我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用selenium.webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX。
def create_selenium_driver(browser='chrome'): # set default browser string based on env (if available) env_browser = os.environ.get('TOASTER_TESTS_BROWSER') if env_browser: browser = env_browser if browser == 'chrome': return webdriver.Chrome( service_args=["--verbose", "--log-path=selenium.log"] ) elif browser == 'firefox': return webdriver.Firefox() elif browser == 'marionette': capabilities = DesiredCapabilities.FIREFOX capabilities['marionette'] = True return webdriver.Firefox(capabilities=capabilities) elif browser == 'ie': return webdriver.Ie() elif browser == 'phantomjs': return webdriver.PhantomJS() else: msg = 'Selenium driver for browser %s is not available' % browser raise RuntimeError(msg)
def driver(): if exists(screenshot_dir): shutil.rmtree(screenshot_dir) os.mkdir(screenshot_dir) firefox_path = '{0}/firefox/firefox'.format(DIR) caps = DesiredCapabilities.FIREFOX caps["marionette"] = True caps['acceptSslCerts'] = True binary = FirefoxBinary(firefox_path) profile = webdriver.FirefoxProfile() profile.add_extension('{0}/JSErrorCollector.xpi'.format(DIR)) profile.set_preference('app.update.auto', False) profile.set_preference('app.update.enabled', False) driver = webdriver.Firefox(profile, capabilities=caps, log_path="{0}/firefox.log".format(LOG_DIR), firefox_binary=binary, executable_path=join(DIR, 'geckodriver/geckodriver')) # driver.set_page_load_timeout(30) # print driver.capabilities['version'] return driver
def _get_desired_capabilities(): """ Return a dictionary of browser settings for a Selenium web driver. """ platform = _TEST_SETTINGS['PLATFORM'] browser = _TEST_SETTINGS['BROWSER'] version = _TEST_SETTINGS['VERSION'] if platform and browser: capabilities = { 'platform': platform, 'browserName': browser, 'version': version, } elif browser.lower() == 'firefox': capabilities = DesiredCapabilities.FIREFOX else: capabilities = DesiredCapabilities.CHROME return _add_travis_info(capabilities)
def __init__(self): try: self.driver = webdriver.Remote(command_executor='http://firefox:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX) except URLError as e: print("Failed to connect!") raise e
def connect(self): """Connects to the extension and retrieves the session id.""" return self.execute(Command.NEW_SESSION, {'desiredCapabilities': DesiredCapabilities.FIREFOX})
def __init__(self): self.driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX) pass
def spawnBrowser(self): """Spawns the browser to use when internetting.""" self.driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX)
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30, capabilities=None, proxy=None): self.binary = firefox_binary self.profile = firefox_profile if self.profile is None: self.profile = FirefoxProfile() self.profile.native_events_enabled = ( self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) if self.binary is None: self.binary = FirefoxBinary() if capabilities is None: capabilities = DesiredCapabilities.FIREFOX if proxy is not None: proxy.add_to_capabilities(capabilities) RemoteWebDriver.__init__(self, command_executor=ExtensionConnection("127.0.0.1", self.profile, self.binary, timeout), desired_capabilities=capabilities, keep_alive=True) self._is_remote = False
def connect_to_selenium(port, t=30, c=1): global Browser if c >= t: return False try: if verbose: print ('Connecting to docker selenium server ' 'http://127.0.0.1:%s/wd/hub [%s/%s]...') % (str(port), str(c), str(t)) if driver == 'chrome': desired_caps = DesiredCapabilities.CHROME elif driver == 'firefox': desired_caps = DesiredCapabilities.FIREFOX Browser = webdriver.Remote( command_executor='http://127.0.0.1:%s/wd/hub' % str(port), desired_capabilities=desired_caps ) except: c += 1 sleep(1) connect_to_selenium(port, t, c) return True
def selenium(selenium_server_ip): remote = webdriver.Remote('http://{}:4444/wd/hub'.format(selenium_server_ip), desired_capabilities=DesiredCapabilities.FIREFOX) remote.implicitly_wait(2) yield remote remote.quit()
def __init_driver(self): firefoxCap = DesiredCapabilities.FIREFOX firefoxCap["marionette"] = True self.__driver = webdriver.Firefox(capabilities = firefoxCap)
def get_firefox_driver(path = None, selenium_grid_hub = None, no_proxy=False): if selenium_grid_hub: desired_capabilities={ "browserName": "firefox", "javascriptEnabled": True, "proxy": { "proxyType": "direct" if no_proxy else "system" } } profile = webdriver.FirefoxProfile() profile.set_preference("network.http.phishy-userpass-length", 255); return webdriver.Remote(command_executor=selenium_grid_hub, desired_capabilities=desired_capabilities, browser_profile=profile) else: binary = None if path: binary = FirefoxBinary(path) #, log_file=open("/tmp/bat_firefox", 'a')) profile = webdriver.FirefoxProfile() profile.set_preference("network.http.phishy-userpass-length", 255); profile.set_preference("network.proxy.type", 0) capabilities = None if USE_MARIONETTE: # tell webdriver to use Marionette instead of plain Firefox capabilities = DesiredCapabilities.FIREFOX capabilities["marionette"] = True return webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, capabilities=capabilities)
def get_driver(self): if self.driver_name == 'PhantomJS': # These capabilities were part of a failed attempt to make the # PhantomJS driver work. cap = webdriver.DesiredCapabilities.PHANTOMJS cap["phantomjs.page.settings.resourceTimeout"] = 20000 cap["phantomjs.page.settings.userAgent"] = \ ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)' ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116' ' Safari/537.36') return webdriver.PhantomJS(desired_capabilities=cap) elif self.driver_name == 'Chrome': driver = webdriver.Chrome() driver.set_window_size(1700, 900) elif self.driver_name == 'Chrome-Hub': capabilities = DesiredCapabilities.CHROME.copy() capabilities["chrome.switches"] = [ "--start-maximized", '--ignore-certificate-errors', '--test-type'] driver = webdriver.Remote( command_executor=os.environ.get('HUB_ADDRESS'), desired_capabilities=capabilities) driver.set_window_size(1200, 900) elif self.driver_name == 'Firefox': fp = webdriver.FirefoxProfile() fp.set_preference("dom.max_chrome_script_run_time", 0) fp.set_preference("dom.max_script_run_time", 0) driver = webdriver.Firefox(firefox_profile=fp) elif self.driver_name == 'Firefox-Hub': driver = webdriver.Remote( command_executor=os.environ.get('HUB_ADDRESS'), desired_capabilities=DesiredCapabilities.FIREFOX) else: driver = getattr(webdriver, self.driver_name)() driver.set_script_timeout(10) self.all_drivers.append(driver) return driver
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path="wires"): self.binary = firefox_binary self.profile = firefox_profile if self.profile is None: self.profile = FirefoxProfile() self.profile.native_events_enabled = ( self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) if capabilities is None: capabilities = DesiredCapabilities.FIREFOX # marionette if capabilities.get("marionette"): self.binary = capabilities.get("binary") self.service = Service(executable_path, firefox_binary=self.binary) self.service.start() executor = FirefoxRemoteConnection( remote_server_addr=self.service.service_url) RemoteWebDriver.__init__( self, command_executor=executor, desired_capabilities=capabilities, keep_alive=True) else: # Oh well... sometimes the old way is the best way. if self.binary is None: self.binary = FirefoxBinary() if proxy is not None: proxy.add_to_capabilities(capabilities) executor = ExtensionConnection("127.0.0.1", self.profile, self.binary, timeout) RemoteWebDriver.__init__(self, command_executor=executor, desired_capabilities=capabilities, keep_alive=True) self._is_remote = False