Пример #1
0
def SetUp(alternative_exe=None):
    if alternative_exe is not None:
        test_paths.CHROMEDRIVER_EXE = alternative_exe

    global _server, _webserver
    _server = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE).Launch()
    _webserver = ChromeDriverLauncher(
        test_paths.CHROMEDRIVER_EXE,
        test_paths.CHROMEDRIVER_TEST_DATA).Launch()
Пример #2
0
    def GlobalSetUp(other_driver=None, other_chrome=None):
        driver_path = other_driver or test_paths.CHROMEDRIVER_EXE
        chrome_path = other_chrome or test_paths.CHROME_EXE
        if driver_path is None or not os.path.exists(driver_path):
            raise RuntimeError('ChromeDriver could not be found')
        if chrome_path is None or not os.path.exists(chrome_path):
            raise RuntimeError('Chrome could not be found')

        ChromeDriverTest._driver_path = driver_path
        ChromeDriverTest._chrome_path = chrome_path
        ChromeDriverTest._server = ChromeDriverLauncher(driver_path).Launch()
        ChromeDriverTest._webserver = ChromeDriverLauncher(
            driver_path, test_paths.TEST_DATA_PATH).Launch()
Пример #3
0
 def testCanServeFiles(self):
     launcher = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE,
                                     root_path=os.path.dirname(__file__))
     server = launcher.Launch()
     request_url = server.GetUrl() + '/' + os.path.basename(__file__)
     SendRequest(request_url, method='GET')
     server.Kill()
Пример #4
0
 def testShouldNotServeFilesByDefault(self):
     server = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE).Launch()
     try:
         SendRequest(server.GetUrl(), method='GET')
         self.fail('Should have raised a urllib.HTTPError for returned 403')
     except urllib2.HTTPError, expected:
         self.assertEquals(403, expected.code)
Пример #5
0
  def _Run(self):
    """Run the tests."""
    # TODO(kkania): Remove this hack.
    self._FakePytestHack()

    test_names = self._GetTestNames(self._args)

    # The tests expect to run with preset 'driver' and 'webserver' class
    # properties.
    server = ChromeDriverLauncher(
        self._options.driver_exe or test_paths.CHROMEDRIVER_EXE,
        test_paths.WEBDRIVER_TEST_DATA).Launch()
    driver = WebDriver(server.GetUrl(), {})
    # The tests expect a webserver. Since ChromeDriver also operates as one,
    # just pass this dummy class with the right info.
    class DummyWebserver:
      pass
    webserver = DummyWebserver()
    webserver.port = server.GetPort()
    for test in test_names:
      Main._SetTestClassAttributes(test, 'driver', driver)
      Main._SetTestClassAttributes(test, 'webserver', webserver)

    # Load and run the tests.
    logging.debug('Loading tests from %s', test_names)
    loaded_tests = unittest.defaultTestLoader.loadTestsFromNames(test_names)
    test_suite = unittest.TestSuite()
    test_suite.addTests(loaded_tests)
    verbosity = 1
    if self._options.verbose:
      verbosity = 2
    result = GTestTextTestRunner(verbosity=verbosity).run(test_suite)
    server.Kill()
    sys.exit(not result.wasSuccessful())
Пример #6
0
 def setUp(self):
     self._server = ChromeDriverLauncher(
         test_paths.CHROMEDRIVER_EXE).Launch()
     self._factory = ChromeDriverFactory(self._server)
Пример #7
0
 def setUp(self):
     self._server = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE,
                                         url_base='/wd/hub').Launch()
Пример #8
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath(),
                                          url_base='/wd/hub').Launch()
Пример #9
0
 def setUp(self):
     super(ShutdownTest, self).setUp()
     self._custom_server = ChromeDriverLauncher(
         self.GetDriverPath()).Launch()
     self._custom_factory = ChromeDriverFactory(self._custom_server,
                                                self.GetChromePath())
Пример #10
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()
     self._factory2 = ChromeDriverFactory(self._server2)
Пример #11
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()
Пример #12
0
    def _Run(self):
        """Run the tests."""
        # TODO(kkania): Remove this hack.
        self._FakePytestHack()

        # In the webdriver tree, the python 'test' module is moved under the root
        # 'selenium' one for testing. Here we mimic that by setting the 'selenium'
        # module's 'test' attribute and adding 'selenium.test' to the system
        # modules.
        import selenium
        import test
        selenium.test = test
        sys.modules['selenium.test'] = test

        # Load and decide which tests to run.
        test_names = self._GetTestNamesFrom(
            os.path.join(os.path.dirname(__file__), self.TESTS_FILENAME))
        all_tests_suite = unittest.defaultTestLoader.loadTestsFromNames(
            test_names)
        filtered_suite = unittest_util.FilterTestSuite(all_tests_suite,
                                                       self._options.filter)

        if self._options.list is True:
            print '\n'.join(
                unittest_util.GetTestNamesFromSuite(filtered_suite))
            sys.exit(0)

        # The tests expect to run with preset 'driver' and 'webserver' class
        # properties.
        driver_exe = self._options.driver_exe or test_paths.CHROMEDRIVER_EXE
        chrome_exe = self._options.chrome_exe or test_paths.CHROME_EXE
        if driver_exe is None or not os.path.exists(
                os.path.expanduser(driver_exe)):
            raise RuntimeError('ChromeDriver could not be found')
        if chrome_exe is None or not os.path.exists(
                os.path.expanduser(chrome_exe)):
            raise RuntimeError('Chrome could not be found')
        driver_exe = os.path.expanduser(driver_exe)
        chrome_exe = os.path.expanduser(chrome_exe)
        # Increase number of http client threads to 10 to prevent hangs.
        # The hang seems to occur because Chrome keeps too many multiple
        # simultaneous connections open to our webserver.
        server = ChromeDriverLauncher(os.path.expanduser(driver_exe),
                                      test_paths.WEBDRIVER_TEST_DATA,
                                      http_threads=10).Launch()
        driver = WebDriver(server.GetUrl(),
                           {'chrome.binary': os.path.expanduser(chrome_exe)})

        # The tests expect a webserver. Since ChromeDriver also operates as one,
        # just pass this dummy class with the right info.
        class DummyWebserver:
            pass

        webserver = DummyWebserver()
        webserver.port = server.GetPort()
        for test in unittest_util.GetTestsFromSuite(filtered_suite):
            test.__class__.driver = driver
            test.__class__.webserver = webserver

        verbosity = 1
        if self._options.verbose:
            verbosity = 2
        result = unittest_util.TextTestRunner(
            verbosity=verbosity).run(filtered_suite)
        server.Kill()
        sys.exit(not result.wasSuccessful())