Package: pwdriver
PWDriver (PyWebDriver)MotivationTo simplify automation settings of each different platform, version, browser.Support:ChromeDriverGeckoDriverEdgeDriver (Chromium)IEDriver...and Android, iOS (SeeWith Appiumsection)Usage1. Install:pipinstallpwdriver2. Make 'config.ini' file and locate in your project directory.config.inilook like this.[automation];if using remote webdriver, then local be false and url required.local=trueurl=http://localhost:4444;target: chrome, gecko, edge, safaritarget=chrome3. Import WebDriverFactory.Now, we can launch webdriver.frompwdriver.coreimportWebDriverFactorydriver=WebDriverFactory.launch()Alternative UsageThis way doesn't make and doesn't use configuration file, but calls setup method of the driver in your test code.with Chrome:fromseleniumimportwebdriverfrompwdriverimportcorecore.setup_chromedriver()driver=webdriver.Chrome()with FireFox:fromseleniumimportwebdriverfrompwdriverimportcorecore.setup_geckodriver()driver=webdriver.Firefox()with Edge:fromseleniumimportwebdriverfrompwdriverimportcorecore.setup_edgedriver()driver=webdriver.Edge()Page object modelsPage object models pattern makes our test cases more concise and readable.The good news is, we can use Page Objects with this.There is an example that searching for keyword onwww.bing.comand verifying url, title.For using this, we are going to create modules that page object classes and test cases.Modules that page elements and locators already implemented, so nevermind.Page Object Classfromselenium.webdriver.common.byimportByfrompwdriver.pageimportBasePageclassBingPage(BasePage):def__init__(self,driver):super().__init__(driver)self._url='https://www.bing.com'self._locator={'input':(By.CSS_SELECTOR,'input#sb_form_q'),'search':(By.CSS_SELECTOR,'label#search_icon')}deftype_keyword(self,text)->None:self._by('input').send_keys(text)defclick_search(self)->BasePage:self._by('search').click()returnBingPage(BasePage)Test casefrompwdriver.coreimportWebDriverFactoryfromtests.pages.bing_pageimportBingPageimportunittestclassBrowserTest(unittest.TestCase):defsetUp(self):self.driver=WebDriverFactory.launch()deftearDown(self):self.driver.quit()deftest_something(self):page=BingPage(self.driver)page.get()keyword='chicken'page.type_keyword(keyword)page.submit_keyword()self.assertIn(f'https://www.bing.com/search?q={keyword}',self.driver.current_url)self.assertEqual(f'{keyword}- Search',self.driver.title)if__name__=='__main__':unittest.main()Logging and Event listenerIf we want to use logging or want to see what events occured in webdriver,we can useget_logger()orEventListener().See below example code.Testfromselenium.webdriver.support.eventsimportEventFiringWebDriverfrompwdriver.coreimportWebDriverFactoryfrompwdriver.listenerimportEventListenerfrompwdriver.utilimportget_loggerlogger=get_logger('test')core=WebDriverFactory.launch()driver=EventFiringWebDriver(core,EventListener())logger.info('WebDriver created.')Log level:debug,info,warning,error,criticalWebDriver event:navigate,execute scriptWebElement event:find,click,change valueWith AppiumThis package also includes wrapped appium's remote webdriver.We could launch an appium driver usingconfig.inifile that contains capabilities.See below configuration and example code.Configuration[automation];if using appium, then local be false and url required.local=falseurl=http://localhost:4723;target: android, iostarget=ios[mobile];add capabilities for mobile testing.platformVersion=15.5deviceName=iPhone 13 minibrowserName=SafariTestfrompwdriver.coreimportWebDriverFactorydriver=WebDriverFactory.launch()License