Ejemplo n.º 1
0
    def new_firefox_driver(self, javascript_enabled=True):
        assert javascript_enabled, 'Cannot disable javascript anymore, see: https://github.com/seleniumhq/selenium/issues/635'
        from selenium.webdriver import FirefoxProfile, DesiredCapabilities

        # FF does not fire events when its window is not in focus.
        # Native events used to fix this.
        # After FF34 FF does not support native events anymore
        # We're on 48.0 now on local machines, but on 31 on travis

        fp = FirefoxProfile()
        #        fp.set_preference("focusmanager.testmode", False)
        #        fp.set_preference('plugins.testmode', False)
        fp.set_preference('webdriver_enable_native_events', True)
        fp.set_preference('webdriver.enable.native.events', True)
        fp.set_preference('enable.native.events', True)
        fp.native_events_enabled = True

        fp.set_preference('network.http.max-connections-per-server', 1)
        fp.set_preference('network.http.max-persistent-connections-per-server',
                          0)
        fp.set_preference('network.http.spdy.enabled', False)
        fp.set_preference('network.http.pipelining', True)
        fp.set_preference('network.http.pipelining.maxrequests', 8)
        fp.set_preference('network.http.pipelining.ssl', True)
        fp.set_preference('html5.offmainthread', False)

        dc = DesiredCapabilities.FIREFOX.copy()

        if not javascript_enabled:
            fp.set_preference('javascript.enabled', False)
            dc['javascriptEnabled'] = False

        wd = webdriver.Firefox(firefox_profile=fp, capabilities=dc)
        self.reahl_server.install_handler(wd)
        return wd
Ejemplo n.º 2
0
def browser_setup():
    """Set a driver object."""
    cfg = get_config()["browser"]
    profile = FirefoxProfile()
    user_agent = UserAgent()
    profile.native_events_enabled = cfg["native_events_enabled"]
    profile.set_preference("general.useragent.override", user_agent.random)
    opts = FirefoxOptions()
    opts.headless = cfg["headless"]
    driver = Firefox(options=opts, executable_path=cfg["gecko_driver"])
    driver.implicitly_wait(cfg["timeout"])
    return driver
Ejemplo n.º 3
0
def firefox_profile_with_preferences(preferences_dict,
                                     native_events_enabled=False):
    '''
    Create a Firefox Profile with the given preferences.

    Any preferences_dict can be used; :py:func:`firefox_preferences` might
    be a handy way to get one.

    Args:
        preferences_dict (dict): Keys and values used to set preferences
            on the new profile.
        native_events_enabled (bool, optional): Used to set the corresponding value
            on the new profile. Use the default unless you know what you are doing.

    Returns:
        FirefoxProfile: A new profile, as customized.
    '''

    profile = FirefoxProfile()
    profile.native_events_enabled = native_events_enabled
    for k, v in preferences_dict.items():
        profile.set_preference(k, v)
    return profile