| OLD | NEW |
| 1 #!/usr/bin/env python |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 4 | 5 |
| 5 """End to end tests for ChromeDriver.""" | 6 """End to end tests for ChromeDriver.""" |
| 6 | 7 |
| 7 import ctypes | 8 import ctypes |
| 9 import optparse |
| 8 import os | 10 import os |
| 9 import sys | 11 import sys |
| 10 import unittest | 12 import unittest |
| 11 | 13 |
| 12 import chromedriver | 14 import chromedriver |
| 13 | 15 |
| 16 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 17 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) |
| 18 |
| 19 from common import unittest_util |
| 20 |
| 14 | 21 |
| 15 class ChromeDriverTest(unittest.TestCase): | 22 class ChromeDriverTest(unittest.TestCase): |
| 16 """End to end tests for ChromeDriver.""" | 23 """End to end tests for ChromeDriver.""" |
| 17 | 24 |
| 18 def testStartStop(self): | 25 def testStartStop(self): |
| 19 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 26 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
| 20 driver.Quit() | 27 driver.Quit() |
| 21 | 28 |
| 22 def testLoadUrl(self): | 29 def testLoadUrl(self): |
| 23 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 30 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 driver.Quit() | 47 driver.Quit() |
| 41 | 48 |
| 42 def testEvaluateInvalidScript(self): | 49 def testEvaluateInvalidScript(self): |
| 43 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 50 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
| 44 self.assertRaises(chromedriver.ChromeDriverException, | 51 self.assertRaises(chromedriver.ChromeDriverException, |
| 45 driver.ExecuteScript, '{{{') | 52 driver.ExecuteScript, '{{{') |
| 46 driver.Quit() | 53 driver.Quit() |
| 47 | 54 |
| 48 | 55 |
| 49 if __name__ == '__main__': | 56 if __name__ == '__main__': |
| 50 if len(sys.argv) != 2 and len(sys.argv) != 3: | 57 parser = optparse.OptionParser() |
| 51 print ('Usage: %s <path_to_chromedriver_so> [path_to_chrome_binary]' % | 58 parser.add_option( |
| 52 __file__) | 59 '', '--chromedriver', type='string', default=None, |
| 53 sys.exit(1) | 60 help='Path to a build of the chromedriver library(REQUIRED!)') |
| 61 parser.add_option( |
| 62 '', '--chrome', type='string', default=None, |
| 63 help='Path to a build of the chrome binary') |
| 64 parser.add_option( |
| 65 '', '--filter', type='string', default='*', |
| 66 help='Filter for specifying what tests to run, "*" will run all. E.g., ' + |
| 67 '*testStartStop') |
| 68 options, args = parser.parse_args() |
| 69 |
| 70 if (options.chromedriver is None or not os.path.exists(options.chromedriver)): |
| 71 parser.error('chromedriver 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) |
| 56 global _CHROME_BINARY | 76 global _CHROME_BINARY |
| 57 if len(sys.argv) == 3: | 77 if options.chrome is not None: |
| 58 _CHROME_BINARY = os.path.abspath(sys.argv[2]) | 78 _CHROME_BINARY = os.path.abspath(options.chrome) |
| 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.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 |