예제 #1
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())
예제 #2
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)
예제 #3
0
class ChromeDriverTest(unittest.TestCase):
    """Fixture for tests that need to instantiate ChromeDriver(s)."""
    @staticmethod
    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._http_server = ChromeDriverLauncher(
            driver_path, test_paths.TEST_DATA_PATH).Launch()
        ChromeDriverTest._https_server = _HttpsServer(
            test_paths.PEM_CERT_AND_KEY, test_paths.TEST_DATA_PATH)

    @staticmethod
    def GlobalTearDown():
        ChromeDriverTest._server.Kill()
        ChromeDriverTest._http_server.Kill()
        ChromeDriverTest._https_server.Shutdown()

    @staticmethod
    def GetTestDataUrl():
        """Returns the base http url for serving files from the test dir."""
        return ChromeDriverTest._http_server.GetUrl()

    @staticmethod
    def GetHttpsTestDataUrl():
        """Returns the base https url for serving files from the test dir."""
        return ChromeDriverTest._https_server.GetUrl()

    @staticmethod
    def GetDriverPath():
        """Returns the path to the default ChromeDriver binary to use."""
        return ChromeDriverTest._driver_path

    @staticmethod
    def GetChromePath():
        """Returns the path to the default Chrome binary to use."""
        return ChromeDriverTest._chrome_path

    def setUp(self):
        self._factory = ChromeDriverFactory(self._server, self.GetChromePath())

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

    def GetServer(self):
        """Returns the ChromeDriver server being used."""
        return self._server

    def GetNewDriver(self, capabilities={}):
        """Returns a new RemoteDriver instance."""
        self.assertTrue(self._factory, 'ChromeDriverTest.setUp must be called')
        return self._factory.GetNewDriver(capabilities)
예제 #4
0
class ChromeDriverTest(unittest.TestCase):
    """Fixture for tests that need to instantiate ChromeDriver(s)."""
    def setUp(self):
        self._factory = ChromeDriverFactory(test_environment.GetServer())

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

    def GetNewDriver(self, capabilities={}):
        """Returns a new RemoteDriver instance."""
        self.assertTrue(self._factory, 'ChromeDriverTest.setUp must be called')
        return self._factory.GetNewDriver(capabilities)
예제 #5
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')
예제 #6
0
 def setUp(self):
     self._server = ChromeDriverLauncher(
         test_paths.CHROMEDRIVER_EXE).Launch()
     self._factory = ChromeDriverFactory(self._server)
예제 #7
0
 def setUp(self):
     super(ShutdownTest, self).setUp()
     self._custom_server = ChromeDriverLauncher(
         self.GetDriverPath()).Launch()
     self._custom_factory = ChromeDriverFactory(self._custom_server,
                                                self.GetChromePath())
예제 #8
0
 def setUp(self):
     self._server2 = ChromeDriverLauncher(self.GetDriverPath()).Launch()
     self._factory2 = ChromeDriverFactory(self._server2)
예제 #9
0
 def setUp(self):
     self._factory = ChromeDriverFactory(self._server, self.GetChromePath())
예제 #10
0
 def setUp(self):
     self._factory = ChromeDriverFactory(test_environment.GetServer())