Exemplo n.º 1
0
class UrlBaseTest(unittest.TestCase):
    """Tests that the server can be configured for a different URL base."""
    def setUp(self):
        self._server = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE,
                                            url_base='/wd/hub').Launch()

    def tearDown(self):
        self._server.Kill()

    def testCreatingSessionShouldRedirectToCorrectURL(self):
        request_url = self._server.GetUrl() + '/session'
        response = SendRequest(request_url,
                               method='POST',
                               data='{"desiredCapabilities":{}}')
        self.assertEquals(200, response.code)
        self.session_url = response.geturl()  # TODO(jleyba): verify this URL?

        data = json.loads(response.read())
        self.assertTrue(isinstance(data, dict))
        self.assertEquals(0, data['status'])

        url_parts = urlparse.urlparse(self.session_url)[2].split('/')
        self.assertEquals(5, len(url_parts))
        self.assertEquals('', url_parts[0])
        self.assertEquals('wd', url_parts[1])
        self.assertEquals('hub', url_parts[2])
        self.assertEquals('session', url_parts[3])
        self.assertEquals(data['sessionId'], url_parts[4])
Exemplo n.º 2
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()
Exemplo n.º 3
0
class DetachProcessTest(unittest.TestCase):
    def setUp(self):
        self._server = ChromeDriverLauncher(
            test_paths.CHROMEDRIVER_EXE).Launch()
        self._factory = ChromeDriverFactory(self._server)

    def tearDown(self):
        self._server.Kill()

    # TODO(kkania): Remove this when Chrome 15 is stable.
    def testDetachProcess(self):
        # This is a weak test. Its purpose is to just make sure we can start
        # Chrome successfully in detached mode. There's not an easy way to know
        # if Chrome is shutting down due to the channel error when the client
        # disconnects.
        driver = self._factory.GetNewDriver({'chrome.detach': True})
        driver.get('about:memory')
        pid = int(
            driver.find_elements_by_xpath('//*[@jscontent="pid"]')[0].text)
        self._server.Kill()
        try:
            Kill(pid)
        except OSError:
            self.fail(
                'Chrome quit after detached chromedriver server was killed')
Exemplo n.º 4
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())
Exemplo n.º 5
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)
Exemplo n.º 6
0
class ShutdownTest(ChromeDriverTest):
    def setUp(self):
        super(ShutdownTest, self).setUp()
        self._custom_server = ChromeDriverLauncher(
            self.GetDriverPath()).Launch()
        self._custom_factory = ChromeDriverFactory(self._custom_server,
                                                   self.GetChromePath())

    def tearDown(self):
        self._custom_server.Kill()
        super(ShutdownTest, self).tearDown()

    def testShutdownWithSession(self):
        driver = self._custom_factory.GetNewDriver()
        driver.get(self._custom_server.GetUrl() + '/status')
        driver.find_element_by_tag_name('body')
        self._custom_server.Kill()

    def testShutdownWithBusySession(self):
        def _Hang(driver):
            """Waits for the process to quit and then notifies."""
            try:
                driver.get(self._custom_server.GetUrl() + '/hang')
            except httplib.BadStatusLine:
                pass

        driver = self._custom_factory.GetNewDriver()
        wait_thread = threading.Thread(target=_Hang, args=(driver, ))
        wait_thread.start()
        wait_thread.join(5)
        self.assertTrue(wait_thread.isAlive())

        self._custom_server.Kill()
        wait_thread.join(10)
        self.assertFalse(wait_thread.isAlive())
Exemplo n.º 7
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()
Exemplo n.º 8
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()
Exemplo n.º 9
0
class BasicTest(ChromeDriverTest):
    """Basic ChromeDriver tests."""
    def setUp(self):
        self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()

    def tearDown(self):
        self._server2.Kill()

    def testShouldReturn403WhenSentAnUnknownCommandURL(self):
        request_url = self._server2.GetUrl() + '/foo'
        try:
            SendRequest(request_url, method='GET')
            self.fail('Should have raised a urllib.HTTPError for returned 403')
        except urllib2.HTTPError, expected:
            self.assertEquals(403, expected.code)
Exemplo n.º 10
0
class LoggingTest(unittest.TestCase):
    def setUp(self):
        self._server = ChromeDriverLauncher(
            test_paths.CHROMEDRIVER_EXE).Launch()
        self._factory = ChromeDriverFactory(self._server)

    def tearDown(self):
        self._factory.QuitAll()
        self._server.Kill()

    def testNoVerboseLogging(self):
        driver = self._factory.GetNewDriver()
        url = self._factory.GetServer().GetUrl()
        driver.execute_script('console.log("HI")')
        req = SendRequest(url + '/log', method='GET')
        log = req.read()
        self.assertTrue(':INFO:' not in log, ':INFO: in log: ' + log)

    # crbug.com/94470
    def DISABLED_testVerboseLogging(self):
        driver = self._factory.GetNewDriver({'chrome.verbose': True})
        url = self._factory.GetServer().GetUrl()
        driver.execute_script('console.log("HI")')
        req = SendRequest(url + '/log', method='GET')
        log = req.read()
        self.assertTrue(':INFO:' in log, ':INFO: not in log: ' + log)
Exemplo n.º 11
0
 def setUp(self):
     self._server = ChromeDriverLauncher(test_paths.CHROMEDRIVER_EXE,
                                         url_base='/wd/hub').Launch()
Exemplo n.º 12
0
 def setUp(self):
     super(ShutdownTest, self).setUp()
     self._custom_server = ChromeDriverLauncher(
         self.GetDriverPath()).Launch()
     self._custom_factory = ChromeDriverFactory(self._custom_server,
                                                self.GetChromePath())
Exemplo n.º 13
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()
     self._factory2 = ChromeDriverFactory(self._server2)
Exemplo n.º 14
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()
Exemplo n.º 15
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())
Exemplo n.º 16
0
 def setUp(self):
     self._server = ChromeDriverLauncher(
         test_paths.CHROMEDRIVER_EXE).Launch()
     self._factory = ChromeDriverFactory(self._server)
Exemplo n.º 17
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath(),
                                          url_base='/wd/hub').Launch()