Beispiel #1
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())
Beispiel #2
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())