Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: chrome/test/chromedriver/test.py

Issue 11746025: [chromedriver]Implement command: title. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """End to end tests for ChromeDriver.""" 5 """End to end tests for ChromeDriver."""
6 6
7 import ctypes 7 import ctypes
8 import os 8 import os
9 import sys 9 import sys
10 import unittest 10 import unittest
11 11
12 import chromedriver 12 import chromedriver
13 import webserver
14
15 _THIS_DIR = os.path.abspath(os.path.dirname(__file__))
16 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib'))
17
18 from common import chrome_paths
13 19
14 20
15 class ChromeDriverTest(unittest.TestCase): 21 class ChromeDriverTest(unittest.TestCase):
16 """End to end tests for ChromeDriver.""" 22 """End to end tests for ChromeDriver."""
17 23
24 @classmethod
25 def setUpClass(cls):
26 cls._http_server = webserver.WebServer(chrome_paths.GetTestData())
chrisgao (Use stgao instead) 2013/01/05 01:19:10 HTTP server is shared by all testcases.
27
28 @classmethod
29 def tearDownClass(cls):
30 cls._http_server.Shutdown()
31
32 @staticmethod
33 def GetHttpUrlForFile(file_path):
34 return ChromeDriverTest._http_server.GetUrl() + file_path
35
36 def setUp(self):
chrisgao (Use stgao instead) 2013/01/05 01:19:10 Add setUp and tearDown to ensure that chrome windo
37 self._driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY)
38
39 def tearDown(self):
40 self._driver.Quit()
41
18 def testStartStop(self): 42 def testStartStop(self):
19 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) 43 pass
20 driver.Quit()
21 44
22 def testLoadUrl(self): 45 def testLoadUrl(self):
23 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) 46 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
24 driver.Load('http://www.google.com')
25 driver.Quit()
26 47
27 def testEvaluateScript(self): 48 def testEvaluateScript(self):
28 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) 49 self.assertEquals(1, self._driver.ExecuteScript('return 1'))
29 self.assertEquals(1, driver.ExecuteScript('return 1')) 50 self.assertEquals(None, self._driver.ExecuteScript(''))
30 self.assertEquals(None, driver.ExecuteScript(''))
31 driver.Quit()
32 51
33 def testEvaluateScriptWithArgs(self): 52 def testEvaluateScriptWithArgs(self):
34 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY)
35 script = ('document.body.innerHTML = "<div>b</div><div>c</div>";' + 53 script = ('document.body.innerHTML = "<div>b</div><div>c</div>";' +
36 'return {stuff: document.querySelectorAll("div")};') 54 'return {stuff: document.querySelectorAll("div")};')
37 stuff = driver.ExecuteScript(script)['stuff'] 55 stuff = self._driver.ExecuteScript(script)['stuff']
38 script = 'return arguments[0].innerHTML + arguments[1].innerHTML'; 56 script = 'return arguments[0].innerHTML + arguments[1].innerHTML';
39 self.assertEquals('bc', driver.ExecuteScript(script, stuff[0], stuff[1])) 57 self.assertEquals(
40 driver.Quit() 58 'bc', self._driver.ExecuteScript(script, stuff[0], stuff[1]))
41 59
42 def testEvaluateInvalidScript(self): 60 def testEvaluateInvalidScript(self):
43 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY)
44 self.assertRaises(chromedriver.ChromeDriverException, 61 self.assertRaises(chromedriver.ChromeDriverException,
45 driver.ExecuteScript, '{{{') 62 self._driver.ExecuteScript, '{{{')
46 driver.Quit() 63
64 def testGetTitle(self):
65 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
66 self.assertEqual('page test', self._driver.GetTitle())
chrisgao (Use stgao instead) 2013/01/05 01:19:10 As Load returns before the page is fully loaded, t
kkania 2013/01/08 21:26:29 We can't use load then until it waits for the navi
chrisgao (Use stgao instead) 2013/01/08 22:23:34 Done.
47 67
48 68
49 if __name__ == '__main__': 69 if __name__ == '__main__':
50 if len(sys.argv) != 2 and len(sys.argv) != 3: 70 if len(sys.argv) != 2 and len(sys.argv) != 3:
51 print ('Usage: %s <path_to_chromedriver_so> [path_to_chrome_binary]' % 71 print ('Usage: %s <path_to_chromedriver_so> [path_to_chrome_binary]' %
52 __file__) 72 __file__)
53 sys.exit(1) 73 sys.exit(1)
54 global _CHROMEDRIVER_LIB 74 global _CHROMEDRIVER_LIB
55 _CHROMEDRIVER_LIB = os.path.abspath(sys.argv[1]) 75 _CHROMEDRIVER_LIB = os.path.abspath(sys.argv[1])
56 global _CHROME_BINARY 76 global _CHROME_BINARY
57 if len(sys.argv) == 3: 77 if len(sys.argv) == 3:
58 _CHROME_BINARY = os.path.abspath(sys.argv[2]) 78 _CHROME_BINARY = os.path.abspath(sys.argv[2])
59 else: 79 else:
60 _CHROME_BINARY = None 80 _CHROME_BINARY = None
61 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( 81 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
62 sys.modules[__name__]) 82 sys.modules[__name__])
63 result = unittest.TextTestRunner().run(all_tests_suite) 83 result = unittest.TextTestRunner().run(all_tests_suite)
64 sys.exit(len(result.failures) + len(result.errors)) 84 sys.exit(len(result.failures) + len(result.errors))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698