def generate_firefox_profile(
        self: "SeleniumTestability",
        preferences: OptionalDictType = None,
        accept_untrusted_certs: bool = False,
        proxy: OptionalStrType = None,
    ) -> FirefoxProfile:
        """
        Generates a firefox profile that sets up few required preferences for SeleniumTestability to support all necessary features.
        Parameters:
        - ``preferences`` - firefox profile preferences in dictionary format.
        - ``accept_untrusted_certs`` should we accept untrusted/self-signed certificates.
        - ``proxy`` proxy options

        Note: If you opt out using this keyword, you are not able to get logs with ``Get Logs`` and Firefox.
        """
        profile = FirefoxProfile()
        if preferences:
            for key, value in preferences.items():  # type: ignore
                profile.set_preference(key, value)

        profile.set_preference("devtools.console.stdout.content", True)

        profile.accept_untrusted_certs = accept_untrusted_certs

        if proxy:
            profile.set_proxy(proxy)

        profile.update_preferences()
        return profile
Example #2
0
def test_autodetect_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.auto_detect = True

    profile.set_proxy(proxy)
    assert profile.default_preferences["network.proxy.type"] == ProxyType.AUTODETECT['ff_value']
Example #3
0
def test_pac_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.proxy_autoconfig_url = 'http://some.url:12345/path'

    profile.set_proxy(proxy)
    assert profile.default_preferences["network.proxy.type"] == ProxyType.PAC['ff_value']
    assert profile.default_preferences["network.proxy.autoconfig_url"] == 'http://some.url:12345/path'
Example #4
0
def test_autodetect_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.auto_detect = True

    profile.set_proxy(proxy)
    assert profile.default_preferences[
        "network.proxy.type"] == ProxyType.AUTODETECT['ff_value']
Example #5
0
def load_website(url, title):
    config = read_config()
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.proxy_autoconfig_url = config['proxy_url']
    profile.set_proxy(proxy)
    driver = Firefox(firefox_profile=profile)
    driver.get(url)
    assert title in driver.title
    return driver
Example #6
0
def test_pac_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.proxy_autoconfig_url = 'http://some.url:12345/path'

    profile.set_proxy(proxy)
    assert profile.default_preferences["network.proxy.type"] == ProxyType.PAC[
        'ff_value']
    assert profile.default_preferences[
        "network.proxy.autoconfig_url"] == 'http://some.url:12345/path'
Example #7
0
def start_firefox(proxy=None, user_agent=None):
    p = FirefoxProfile("E://profiles")
    p.accept_untrusted_certs = True
    if user_agent:
        p.set_preference("general.useragent.override", user_agent)
    capabilities = DesiredCapabilities().FIREFOX.copy()
    capabilities['acceptInsecureCerts'] = True

    if proxy:
        p.set_proxy(proxy)
    browser = Firefox(firefox_profile=p, capabilities=capabilities)
    return browser
Example #8
0
def test_manual_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.no_proxy = 'localhost, foo.localhost'
    proxy.http_proxy = 'some.url:1234'
    proxy.ftp_proxy = None
    proxy.sslProxy = 'some2.url'

    profile.set_proxy(proxy)
    assert profile.default_preferences["network.proxy.type"] == ProxyType.MANUAL['ff_value']
    assert profile.default_preferences["network.proxy.no_proxies_on"] == 'localhost, foo.localhost'
    assert profile.default_preferences["network.proxy.http"] == 'some.url'
    assert profile.default_preferences["network.proxy.http_port"] == 1234
    assert profile.default_preferences["network.proxy.ssl"] == 'some2.url'
    assert "network.proxy.ssl_port" not in profile.default_preferences
    assert "network.proxy.ftp" not in profile.default_preferences
Example #9
0
def test_manual_proxy_is_set_in_profile():
    profile = FirefoxProfile()
    proxy = Proxy()
    proxy.no_proxy = 'localhost, foo.localhost'
    proxy.http_proxy = 'some.url:1234'
    proxy.ftp_proxy = None
    proxy.sslProxy = 'some2.url'

    profile.set_proxy(proxy)
    assert profile.default_preferences[
        "network.proxy.type"] == ProxyType.MANUAL['ff_value']
    assert profile.default_preferences[
        "network.proxy.no_proxies_on"] == 'localhost, foo.localhost'
    assert profile.default_preferences["network.proxy.http"] == 'some.url'
    assert profile.default_preferences["network.proxy.http_port"] == 1234
    assert profile.default_preferences["network.proxy.ssl"] == 'some2.url'
    assert "network.proxy.ssl_port" not in profile.default_preferences
    assert "network.proxy.ftp" not in profile.default_preferences
Example #10
0
    def _create_firefox(cls, config, driver_path, browser_bin_path):
        from selenium.webdriver import Firefox
        from selenium.webdriver import FirefoxOptions
        from selenium.webdriver import FirefoxProfile

        profile = FirefoxProfile()
        if config["arjunaOptions"]["BROWSER_PROXY_ON"]:
            proxy = Proxy()
            proxy_string = "{}.{}".format(
                config["arjunaOptions"]["BROWSER_PROXY_HOST"],
                config["arjunaOptions"]["BROWSER_PROXY_PORT"])
            proxy.http_proxy = proxy_string
            proxy.ssl_proxy = proxy_string
            profile.set_proxy(proxy)

        caps = DesiredCapabilities.FIREFOX
        caps.update(config["driverCapabilities"])

        options = FirefoxOptions()

        if browser_bin_path.lower() != "not_set":
            options.binary_location = browser_bin_path

        if cls.are_browser_prefs_set(config):
            for pref, value in config["browserPreferences"].items():
                options.set_preference(pref, value)

        if cls.are_browser_args_set(config):
            for arg in config["browserArgs"]:
                options.add_argument(arg)

        # print(options.to_capabilities())
        # caps[FirefoxOptions.KEY] = options.to_capabilities()[FirefoxOptions.KEY]
        driver = Firefox(executable_path=driver_path,
                         firefox_profile=profile,
                         capabilities=caps)

        if cls.are_extensions_set(config):
            for ext in config["browserExtensions"]:
                driver.install_addon(ext)

        return driver
    def generate_firefox_profile(
        self: "SeleniumTestability",
        options: OptionalDictType = None,
        accept_untrusted_certs: bool = False,
        proxy: OptionalStrType = None,
    ) -> FirefoxProfile:
        profile = FirefoxProfile()
        if options:
            for key, value in options.items():  # type: ignore
                profile.set_preference(key, value)

        profile.set_preference("devtools.console.stdout.content", True)

        if accept_untrusted_certs:
            profile.accept_untrusted_certs

        if proxy:
            profile.set_proxy(proxy)

        profile.update_preferences()
        return profile
Example #12
0
def test_unspecified_proxy_is_set():
    profile = FirefoxProfile()
    proxy = Proxy()
    profile.set_proxy(proxy)
    assert "network.proxy.type" not in profile.default_preferences
Example #13
0
def test_none_proxy_is_set():
    profile = FirefoxProfile()
    proxy = None
    with pytest.raises(ValueError):
        profile.set_proxy(proxy)
    assert "network.proxy.type" not in profile.default_preferences
Example #14
0
# x.headless = True
# x.proxy = p
# x.accept_insecure_certs = True
# x.set_preference("browser.download.defaultFolder", str(Path(os.getcwd()).parent) + os.path.sep +  "AutomationDownloads")

# myProxy = "86.111.144.194:3128"
# proxy = Proxy({
#     'proxyType': ProxyType.MANUAL,
#     'httpProxy': myProxy,
#     'ftpProxy': myProxy,
#     'sslProxy': myProxy,
#     'noProxy':''})


fp = FirefoxProfile()
fp.assume_untrusted_cert_issuer = False
fp.accept_untrusted_certs = True
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/octet-stream,application/msexcel,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv,text/txt,application/pkcs10,application/x-msdownload,application/csv,text/html,application/force-download,application/pkix-cert")
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.useDownloadDir", True)
fp.set_preference("browser.download.defaultFolder", str(Path(os.getcwd()).parent) + os.path.sep +  "AutomationDownloads")
fp.set_preference("browser.startup.homepage", "http://www.google.com")
fp.set_proxy(p)

# driver = webdriver.Firefox(firefox_profile=fp)
driver = webdriver.Firefox(options=x)
driver.maximize_window()
time.sleep(60)
driver.quit()
Example #15
0
def test_unspecified_proxy_is_set():
    profile = FirefoxProfile()
    proxy = Proxy()
    profile.set_proxy(proxy)
    assert "network.proxy.type" not in profile.default_preferences
Example #16
0
def test_none_proxy_is_set():
    profile = FirefoxProfile()
    proxy = None
    with pytest.raises(ValueError):
        profile.set_proxy(proxy)
    assert "network.proxy.type" not in profile.default_preferences