Example #1
0
    def _setup_driver(self, proxy=None, use_proxy=False):
        """Initializes a Selenium webdriver instance to programmatically
        interact with a browser.
        """
        driver = None
        if self.browser == 'chrome':
            chrome_options = webdriver.ChromeOptions()
            # Disable several subsystems which run network requests in the
            # background. This helps reduce noise when measuring network
            # performance. Also, disable prerendering by chrome which renders
            # a page in the background leading to wrong test results.
            chrome_options.add_argument('--disable-background-networking')
            chrome_options.add_argument('--prerender=disabled')
            chrome_options.add_argument('--prerender-from-omnibox=disabled')

            if use_proxy:
                proxy_url = python_utils.url_parse(proxy.proxy).path
                proxy_argument = '--proxy-server={0}'.format(proxy_url)
                chrome_options.add_argument(proxy_argument)

            driver = webdriver.Chrome(
                CHROMEDRIVER_PATH,
                chrome_options=chrome_options)

        elif self.browser == 'firefox':
            firefox_profile = webdriver.FirefoxProfile()

            if use_proxy:
                firefox_profile.set_proxy(proxy.selenium_proxy())

            driver = webdriver.Firefox(firefox_profile=firefox_profile)

        self._add_cookie(driver)

        return driver
Example #2
0
 def test_url_parse(self):
     response = python_utils.url_parse('http://www.google.com')
     self.assertEqual(response.geturl(), 'http://www.google.com')