def _browserFirefoxRun(self, browserName, lCurPath, browserProxy, randomProxy, desiredCapabilities): executable = helper.browserHelper_getBrowserExecutable(browserName) self._downloadDriverCheck(executable, lCurPath, browserName) profile = webDrv.webdriver_setFirefoxProfile(browserProxy, randomProxy) self.downloadFolder = webDrv.getDownloadFolderFromProfile(profile) logger.debug(f"Firefox Profile as follows:{profile.userPrefs}") return webDrv.BROWSER_DRIVERS[browserName]( options=webDrv.webdriver_createBrowserOptions( browserName=browserName, desiredCapabilities=desiredCapabilities), executable_path=helper.browserHelper_findBrowserDriverPaths( executable), firefox_profile=profile, service_log_path=os.path.join(self.managedPaths.getLogfilePath(), 'geckodriver.log'))
def _browserChromeRun(self, browserName, lCurPath, browserProxy, randomProxy, desiredCapabilities): executable = helper.browserHelper_getBrowserExecutable(browserName) self._downloadDriverCheck(executable, lCurPath, browserName) lOptions = webDrv.webdriver_createBrowserOptions( browserName=browserName, desiredCapabilities=desiredCapabilities, browserMobProxy=browserProxy, randomProxy=randomProxy) self.downloadFolder = webDrv.getDownloadFolderFromChromeOptions( options=lOptions) return webDrv.BROWSER_DRIVERS[browserName]( chrome_options=lOptions, executable_path=helper.browserHelper_findBrowserDriverPaths( executable), service_log_path=os.path.join(self.managedPaths.getLogfilePath(), 'chromedriver.log'))
def createNewBrowser(self, mobileType=None, mobileApp=None, desired_app=None, mobile_app_setting=None, browserName=GC.BROWSER_FIREFOX, desiredCapabilities={}, randomProxy=None, **kwargs): """ Will find the specified executables of the desired browser and start it with the given capabilities. @param browserName: one of GC_BROWSER_*-Browsernames, e.g. GC_BROWSER_FIREFOX @param desiredCapabilities: DICT of desiredCapabilities for this browser @param kwargs: Currently (Jan2020) not used """ self.takeTime("Browser Start") self.randomProxy = randomProxy self.browserName = browserName self.browserProcessID = [] lCurPath = Path(self.managedPaths.getOrSetDriverPath()) if browserName in webDrv.BROWSER_DRIVERS: browserProxy = kwargs.get('browserProxy') browserInstance = kwargs.get('browserInstance', 'unknown') if utils.anything2Boolean(mobileType): self.browserData.driver = self._mobileConnectAppium( browserName, desired_app, mobileApp, mobile_app_setting) elif GC.BROWSER_FIREFOX == browserName: self.browserData.driver = self._browserFirefoxRun( browserName, lCurPath, browserProxy, randomProxy, desiredCapabilities) helper.browserHelper_startBrowsermobProxy( browserName=browserName, browserInstance=browserInstance, browserProxy=browserProxy) self.browserProcessID.append( self.browserData.driver.capabilities.get("moz:processID")) elif GC.BROWSER_CHROME == browserName: self.browserData.driver = self._browserChromeRun( browserName, lCurPath, browserProxy, randomProxy, desiredCapabilities) helper.browserHelper_startBrowsermobProxy( browserName=browserName, browserInstance=browserInstance, browserProxy=browserProxy) try: port = self.browserData.driver.capabilities[ 'goog:chromeOptions']["debuggerAddress"].split(":")[1] fp = os.popen(f"lsof -nP -iTCP:{port} | grep LISTEN") self.browserProcessID.append( int(fp.readlines()[-1].split()[1])) except Exception as ex: logger.info(ex) elif GC.BROWSER_EDGE == browserName: self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName]( executable_path=helper. browserHelper_findBrowserDriverPaths(GC.EDGE_DRIVER)) elif GC.BROWSER_SAFARI == browserName: # SAFARI doesn't provide any options, but desired_capabilities. # Executable_path = the standard safaridriver path. if len(desiredCapabilities) == 0: desiredCapabilities = {} self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName]( desired_capabilities=desiredCapabilities) elif GC.BROWSER_REMOTE == browserName: self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName]( options=webDrv.webdriver_createBrowserOptions( browserName=browserName, desiredCapabilities=desiredCapabilities), command_executor=GC.REMOTE_EXECUTE_URL, desired_capabilities=desiredCapabilities) else: logger.critical( f"Browsername not found: {browserName}. Cancelling test run" ) raise SystemError( f"Browsername not found: {browserName}. Cancelling test run" ) elif GC.BROWSER_REMOTE_V4 == browserName: desired_capabilities, seleniumGridIp, seleniumGridPort = helper.browserHelper_setSettingsRemoteV4( desiredCapabilities) if desired_capabilities['browserName'] == 'firefox': browserExecutable = helper.browserHelper_getBrowserExecutable( GC.BROWSER_FIREFOX) self._downloadDriverCheck(browserExecutable, lCurPath, GC.BROWSER_FIREFOX) elif desired_capabilities['browserName'] == 'chrome': browserExecutable = helper.browserHelper_getBrowserExecutable( GC.BROWSER_CHROME) self._downloadDriverCheck(browserExecutable, lCurPath, GC.BROWSER_CHROME) serverUrl = 'http://' + seleniumGridIp + ':' + seleniumGridPort self.browserData.driver = webDrv.BROWSER_DRIVERS[ GC.BROWSER_REMOTE](command_executor=serverUrl, desired_capabilities=desiredCapabilities) else: raise SystemExit("Browsername unknown") if self.downloadFolder: self.downloadFolderMonitoring = DownloadFolderMonitoring( self.downloadFolder) self.takeTime("Browser Start")