Python selenium.webdriver.common.desired_capabilities.DesiredCapabilities 模块,FIREFOX 实例源码

我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用selenium.webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX

项目:isar    作者:ilbers    | 项目源码 | 文件源码
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)
项目:nextcloud    作者:syncloud    | 项目源码 | 文件源码
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
项目:cyphon    作者:dunbarcyber    | 项目源码 | 文件源码
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)
项目:AutoTriageBot    作者:salesforce    | 项目源码 | 文件源码
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
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:Skynet2.0    作者:Skynet2-0    | 项目源码 | 文件源码
def __init__(self):
        self.driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4444/wd/hub',
        desired_capabilities=DesiredCapabilities.FIREFOX)
        pass
项目:Skynet2.0    作者:Skynet2-0    | 项目源码 | 文件源码
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)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
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
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:Phantomime    作者:psyb0t    | 项目源码 | 文件源码
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
项目:ShuoshuoMonitor    作者:aploium    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:amazon_order_history_scraper    作者:drewctate    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def connect(self):
        """Connects to the extension and retrieves the session id."""
        return self.execute(Command.NEW_SESSION,
                            {'desiredCapabilities': DesiredCapabilities.FIREFOX})
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
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
项目:dila    作者:socialwifi    | 项目源码 | 文件源码
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()
项目:facebook-wrapper    作者:matteoalessiocarrara    | 项目源码 | 文件源码
def __init_driver(self):
        firefoxCap = DesiredCapabilities.FIREFOX
        firefoxCap["marionette"] = True
        self.__driver = webdriver.Firefox(capabilities = firefoxCap)
项目:phat    作者:danielfranca    | 项目源码 | 文件源码
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)
项目:archivematica-acceptance-tests    作者:artefactual-labs    | 项目源码 | 文件源码
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
项目:ShuoshuoMonitor    作者:aploium    | 项目源码 | 文件源码
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