コード例 #1
0
 def _Run(self):
     """Runs the unit tests."""
     all_tests = unittest.defaultTestLoader.loadTestsFromNames(
         _TEST_MODULES)
     tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
     result = unittest_util.TextTestRunner(verbosity=1).run(tests)
     # Run tests again if installation type is 'both'(i.e., user and system).
     if self._opts.install_type == 'both':
         # Load the tests again so test parameters can be reinitialized.
         all_tests = unittest.defaultTestLoader.loadTestsFromNames(
             _TEST_MODULES)
         tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
         InstallTest.SetInstallType(
             chrome_installer_win.InstallationType.SYSTEM)
         result = unittest_util.TextTestRunner(verbosity=1).run(tests)
     del (tests)
     if not result.wasSuccessful():
         print >> sys.stderr, ('Not all tests were successful.')
         sys.exit(1)
     sys.exit(0)
コード例 #2
0
def main():
    parser = optparse.OptionParser()
    parser.add_option(
        '',
        '--filter',
        type='string',
        default='*',
        help='Filter for specifying what tests to run, google test style.')
    parser.add_option(
        '',
        '--driver-exe',
        type='string',
        default=None,
        help='Path to the default ChromeDriver executable to use.')
    parser.add_option('',
                      '--chrome-exe',
                      type='string',
                      default=None,
                      help='Path to the default Chrome executable to use.')
    parser.add_option('',
                      '--list',
                      action='store_true',
                      default=False,
                      help='List tests instead of running them.')
    options, args = parser.parse_args()

    all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
        chromedriver_tests)
    filtered_suite = unittest_util.FilterTestSuite(all_tests_suite,
                                                   options.filter)

    if options.list is True:
        print '\n'.join(unittest_util.GetTestNamesFromSuite(filtered_suite))
        return 0

    driver_exe = options.driver_exe
    if driver_exe is not None:
        driver_exe = os.path.expanduser(options.driver_exe)
    chrome_exe = options.chrome_exe
    if chrome_exe is not None:
        chrome_exe = os.path.expanduser(options.chrome_exe)
    ChromeDriverTest.GlobalSetUp(driver_exe, chrome_exe)
    result = unittest_util.TextTestRunner(verbosity=1).run(filtered_suite)
    ChromeDriverTest.GlobalTearDown()
    if not result.wasSuccessful():
        print "Rerun failing tests using --f=" + result.getRetestFilter()
    return not result.wasSuccessful()
コード例 #3
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())