OLD | NEW |
---|---|
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 optparse | |
8 import os | 9 import os |
9 import sys | 10 import sys |
10 import unittest | 11 import unittest |
11 | 12 |
12 import chromedriver | 13 import chromedriver |
13 | 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 unittest_util | |
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 |
18 def testStartStop(self): | 24 def testStartStop(self): |
19 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 25 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
20 driver.Quit() | 26 driver.Quit() |
21 | 27 |
22 def testLoadUrl(self): | 28 def testLoadUrl(self): |
23 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 29 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
(...skipping 16 matching lines...) Expand all Loading... | |
40 driver.Quit() | 46 driver.Quit() |
41 | 47 |
42 def testEvaluateInvalidScript(self): | 48 def testEvaluateInvalidScript(self): |
43 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 49 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
44 self.assertRaises(chromedriver.ChromeDriverException, | 50 self.assertRaises(chromedriver.ChromeDriverException, |
45 driver.ExecuteScript, '{{{') | 51 driver.ExecuteScript, '{{{') |
46 driver.Quit() | 52 driver.Quit() |
47 | 53 |
48 | 54 |
49 if __name__ == '__main__': | 55 if __name__ == '__main__': |
50 if len(sys.argv) != 2 and len(sys.argv) != 3: | 56 parser = optparse.OptionParser() |
kkania
2013/01/06 22:13:09
if you want, go ahead and change this file to exec
| |
51 print ('Usage: %s <path_to_chromedriver_so> [path_to_chrome_binary]' % | 57 parser.add_option( |
52 __file__) | 58 '', '--chromedriver_path', type='string', default=None, |
kkania
2013/01/06 22:13:09
most chromium uses chromedriver-path style args; c
| |
53 sys.exit(1) | 59 help='Path to a build of the chromedriver library(REQUIRED!)') |
60 parser.add_option( | |
61 '', '--chrome_path', type='string', default=None, | |
62 help='Path to a build of the chrome binary') | |
63 parser.add_option( | |
64 '', '--gtest_filter', type='string', default='*', | |
65 help='Filter for specifying what tests to run, "*" will run all. E.g., ' + | |
66 '*testStartStop') | |
67 options, args = parser.parse_args() | |
68 | |
69 if (options.chromedriver_path is None or | |
70 not os.path.exists(options.chromedriver_path)): | |
71 parser.error('chromedriver_path is required or the given path is invalid.' + | |
72 'Please run "%s --help" for help' % __file__) | |
73 | |
54 global _CHROMEDRIVER_LIB | 74 global _CHROMEDRIVER_LIB |
55 _CHROMEDRIVER_LIB = os.path.abspath(sys.argv[1]) | 75 _CHROMEDRIVER_LIB = os.path.abspath(options.chromedriver_path) |
56 global _CHROME_BINARY | 76 global _CHROME_BINARY |
57 if len(sys.argv) == 3: | 77 if options.chrome_path is not None: |
58 _CHROME_BINARY = os.path.abspath(sys.argv[2]) | 78 _CHROME_BINARY = os.path.abspath(options.chrome_path) |
59 else: | 79 else: |
60 _CHROME_BINARY = None | 80 _CHROME_BINARY = None |
81 | |
61 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 82 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
62 sys.modules[__name__]) | 83 sys.modules[__name__]) |
63 result = unittest.TextTestRunner().run(all_tests_suite) | 84 tests = unittest_util.FilterTestSuite(all_tests_suite, options.gtest_filter) |
85 result = unittest.TextTestRunner().run(tests) | |
64 sys.exit(len(result.failures) + len(result.errors)) | 86 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |