Esempio n. 1
0
    def runFirefox(self, turn=False):
        print("Running firefox with Turn: ", turn)
        self.options = webdriver.FirefoxOptions()
        self.options.set_preference('media.navigator.permission.disabled',
                                    False)
        self.options.set_preference('media.navigator.streams.fake', True)
        self.options.set_preference('media.peerconnection.enabled', True)
        self.options.set_preference(
            'media.peerconnection.ice.obfuscate_host_addresses', False)
        self.options.set_preference('media.peerconnection.identity.enabled',
                                    True)
        self.options.set_preference('media.peerconnection.mtransport_process',
                                    True)
        self.options.set_preference('media.peerconnection.ice.no_host', False)
        self.options.set_preference('network.process.enabled', True)
        self.options.set_preference('media.peerconnection.ice.relay_only',
                                    turn)
        self.options.set_preference('media.peerconnection.turn.disable',
                                    not turn)

        self.driver = webdriver.Firefox(service=FirefoxService(
            GeckoDriverManager().install()),
                                        options=self.options)
        self.driver.implicitly_wait(15)
        self.driver.maximize_window()
    def login(self, request):
        _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
        if os.path.isfile(_geckodriver):
            _service = FirefoxService(executable_path=_geckodriver)
            driver_ = webdriver.Firefox(service=_service)
        else:
            driver_ = webdriver.Firefox()

        def quit():
            driver_.quit()
        request.addfinalizer(quit)
        return login_page.LoginPage(driver_)
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.host = request.config.getoption("--host").lower()
    config.browser = request.config.getoption("--browser").lower()
    config.browserversion = request.config.getoption(
        "--browserversion").lower()
    config.platform = request.config.getoption("--platform").lower()

    if config.host == "saucelabs":
        _desired_caps = {}
        _desired_caps["browserName"] = config.browser
        _desired_caps["browserVersion"] = config.browserversion
        _desired_caps["platformName"] = config.platform
        _desired_caps["name"] = request.cls.__name__ + \
            "." + request.function.__name__
        _credentials = os.environ["SAUCE_USERNAME"] + \
            ":" + os.environ["SAUCE_ACCESS_KEY"]
        _url = "http://" + _credentials + "@ondemand.saucelabs.com:80/wd/hub"
        driver_ = webdriver.Remote(_url, _desired_caps)
    elif config.host == "localhost":
        if config.browser == "firefox":
            _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
            if os.path.isfile(_geckodriver):
                _service = FirefoxService(executable_path=_geckodriver)
                driver_ = webdriver.Firefox(executable_path=_geckodriver)
            else:
                driver_ = webdriver.Firefox()
        elif config.browser == "chrome":
            _chromedriver = os.path.join(
                os.getcwd() + 'vendor', 'chromedriver')
            if os.path.isfile(_chromedriver):
                _service = ChromeService(executable_path=_geckodriver)
                driver_ = webdriver.Chrome(service=_service)
            else:
                driver_ = webdriver.Chrome()

    def quit():
        try:
            if config.host == "saucelabs":
                if request.node.result_call.failed:
                    driver_.execute_script("sauce:job-result=failed")
                    print "http://saucelabs.com/tests/" + driver_.session_id
                elif request.node.result_call.passed:
                    driver_.execute_script("sauce:job-result=passed")
        finally:
            driver_.quit()

    request.addfinalizer(quit)
    return driver_
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")

    _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
    if os.path.isfile(_geckodriver):
        _service = FirefoxService(executable_path=_geckodriver)
        driver_ = webdriver.Firefox(service=_service)
    else:
        driver_ = webdriver.Firefox()

    def quit():
        driver_.quit()

    request.addfinalizer(quit)
    return driver_
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.host = request.config.getoption("--host").lower()
    config.browser = request.config.getoption("--browser").lower()
    config.browserversion = request.config.getoption(
        "--browserversion").lower()
    config.platform = request.config.getoption("--platform").lower()

    if config.host == "saucelabs":
        _desired_caps = {}
        _desired_caps["browserName"] = config.browser
        _desired_caps["browserVersion"] = config.browserversion
        _desired_caps["platformName"] = config.platform
        _credentials = os.environ["SAUCE_USERNAME"] + \
            ":" + os.environ["SAUCE_ACCESS_KEY"]
        _url = "http://" + _credentials + "@ondemand.saucelabs.com:80/wd/hub"
        driver_ = webdriver.Remote(_url, _desired_caps)
    elif config.host == "localhost":
        if config.browser == "firefox":
            _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
            if os.path.isfile(_geckodriver):
                _service = FirefoxService(executable_path=_geckodriver)
                driver_ = webdriver.Firefox(executable_path=_geckodriver)
            else:
                driver_ = webdriver.Firefox()
        elif config.browser == "chrome":
            _chromedriver = os.path.join(os.getcwd() + 'vendor',
                                         'chromedriver')
            if os.path.isfile(_chromedriver):
                _service = ChromeService(executable_path=_geckodriver)
                driver_ = webdriver.Chrome(service=_service)
            else:
                driver_ = webdriver.Chrome()

    def quit():
        driver_.quit()

    request.addfinalizer(quit)
    return driver_
Esempio n. 6
0
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.browser = request.config.getoption("--browser").lower()

    if config.browser == "firefox":
        _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
        if os.path.isfile(_geckodriver):
            _service = FirefoxService(executable_path=_geckodriver)
            driver_ = webdriver.Firefox(service=_service)
        else:
            driver_ = webdriver.Firefox()
    elif config.browser == "chrome":
        _chromedriver = os.path.join(os.getcwd() + 'vendor', 'chromedriver')
        if os.path.isfile(_chromedriver):
            _service = ChromeService(executable_path=_geckodriver)
            driver_ = webdriver.Chrome(service=_service)
        else:
            driver_ = webdriver.Chrome()

    def quit():
        driver_.quit()

    request.addfinalizer(quit)
    return driver_
Esempio n. 7
0
 def get_firefox():
     return Firefox(
         service=FirefoxService(GeckoDriverManager().install()))
Esempio n. 8
0
    def start_driver(self):
        """Start a new Selenium web driver and install the bundled
        extension."""
        if self.browser in (CHROME, EDGE):
            # make extension ID constant across runs

            # create temp directory
            # TODO does tmp_dir actually get cleaned up?
            self.tmp_dir = tempfile.TemporaryDirectory()  # pylint:disable=consider-using-with
            new_extension_path = os.path.join(self.tmp_dir.name, "src")

            # copy extension sources there
            copytree(os.path.join(self.pb_dir, 'src'), new_extension_path)

            # update manifest.json
            manifest_path = os.path.join(new_extension_path, "manifest.json")
            with open(manifest_path, "r", encoding="utf-8") as f:
                manifest = json.load(f)

            # this key and the extension ID
            # must both be derived from the same private key
            manifest[
                'key'] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArMdgFkGsm7nOBr/9qkx8XEcmYSu1VkIXXK94oXLz1VKGB0o2MN+mXL/Dsllgkh61LZgK/gVuFFk89e/d6Vlsp9IpKLANuHgyS98FKx1+3sUoMujue+hyxulEGxXXJKXhk0kGxWdE0IDOamFYpF7Yk0K8Myd/JW1U2XOoOqJRZ7HR6is1W6iO/4IIL2/j3MUioVqu5ClT78+fE/Fn9b/DfzdX7RxMNza9UTiY+JCtkRTmm4ci4wtU1lxHuVmWiaS45xLbHphQr3fpemDlyTmaVoE59qG5SZZzvl6rwDah06dH01YGSzUF1ezM2IvY9ee1nMSHEadQRQ2sNduNZWC9gwIDAQAB"  # noqa:E501 pylint:disable=line-too-long

            # remove the 5MB limit on Chrome extension local storage
            if 'unlimitedStorage' not in manifest['permissions']:
                manifest['permissions'].append('unlimitedStorage')

            with open(manifest_path, "w", encoding="utf-8") as f:
                json.dump(manifest, f)

            opts = ChromeOptions() if self.browser == CHROME else EdgeOptions()

            if self.browser_binary:
                opts.binary_location = self.browser_binary

            opts.add_argument("--load-extension=" + new_extension_path)

            # loads parallel extension to run alongside pb
            if self.load_extension:
                opts.add_extension(self.load_extension)

            opts.add_argument("--disable-blink-features=AutomationControlled")
            opts.add_argument("--disable-crash-reporter")

            opts.set_capability("acceptInsecureCerts", False)
            opts.set_capability("unhandledPromptBehavior", "ignore")

            for _ in range(5):
                try:
                    if self.browser == CHROME:
                        self.driver = webdriver.Chrome(self.chromedriver_path,
                                                       options=opts)
                    else:
                        self.driver = webdriver.Edge(options=opts)
                except ConnectionResetError as e:
                    self.logger.warning(
                        ("%s WebDriver initialization failed:\n"
                         "%s\n"
                         "Retrying ..."), self.browser.capitalize(), str(e))
                    time.sleep(2)
                else:
                    break

        elif self.browser == FIREFOX:
            opts = self.get_firefox_options()
            service = FirefoxService(log_path=os.path.devnull)
            self.driver = webdriver.Firefox(options=opts, service=service)

            # load Privacy Badger
            # Firefox requires absolute paths
            unpacked_addon_path = os.path.abspath(
                os.path.join(self.pb_dir, 'src'))
            self.driver.install_addon(unpacked_addon_path, temporary=True)

            # loads parallel extension to run alongside pb
            if self.load_extension:
                parallel_extension_url = os.path.abspath(self.load_extension)
                self.driver.install_addon(parallel_extension_url)

        # apply timeout settings
        self.driver.set_page_load_timeout(self.timeout)
        self.driver.set_script_timeout(self.timeout)

        self.driver.maximize_window()

        # wait for Badger to finish initializing
        self.load_extension_page()
        wait_for_script(self.driver,
                        ("let done = arguments[arguments.length - 1];"
                         "chrome.runtime.sendMessage({"
                         "  type: 'isBadgerInitialized'"
                         "}, r => done(r));"),
                        execute_async=True)
        # also disable the welcome page
        self.driver.execute_async_script(
            "let done = arguments[arguments.length - 1];"
            "chrome.runtime.sendMessage({"
            "  type: 'updateSettings',"
            "  data: { showIntroPage: false }"
            "}, done);")
Esempio n. 9
0
def test_firefox_session():
    service = FirefoxService(executable_path=GeckoDriverManager().install())

    driver = webdriver.Firefox(service=service)

    driver.quit()