| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # 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 |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """End to end tests for ChromeDriver.""" | 6 """End to end tests for ChromeDriver.""" |
| 7 | 7 |
| 8 import ctypes | 8 import ctypes |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 script = 'return arguments[0].innerHTML + arguments[1].innerHTML'; | 45 script = 'return arguments[0].innerHTML + arguments[1].innerHTML'; |
| 46 self.assertEquals('bc', driver.ExecuteScript(script, stuff[0], stuff[1])) | 46 self.assertEquals('bc', driver.ExecuteScript(script, stuff[0], stuff[1])) |
| 47 driver.Quit() | 47 driver.Quit() |
| 48 | 48 |
| 49 def testEvaluateInvalidScript(self): | 49 def testEvaluateInvalidScript(self): |
| 50 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) | 50 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
| 51 self.assertRaises(chromedriver.ChromeDriverException, | 51 self.assertRaises(chromedriver.ChromeDriverException, |
| 52 driver.ExecuteScript, '{{{') | 52 driver.ExecuteScript, '{{{') |
| 53 driver.Quit() | 53 driver.Quit() |
| 54 | 54 |
| 55 def testSwitchToFrame(self): |
| 56 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_LIB, _CHROME_BINARY) |
| 57 driver.ExecuteScript( |
| 58 'var frame = document.createElement("iframe");' |
| 59 'frame.id="id";' |
| 60 'frame.name="name";' |
| 61 'document.body.appendChild(frame);') |
| 62 self.assertTrue(driver.ExecuteScript('return window.top == window')) |
| 63 driver.SwitchToFrame('id') |
| 64 self.assertTrue(driver.ExecuteScript('return window.top != window')) |
| 65 driver.SwitchToMainFrame() |
| 66 self.assertTrue(driver.ExecuteScript('return window.top == window')) |
| 67 driver.SwitchToFrame('name') |
| 68 self.assertTrue(driver.ExecuteScript('return window.top != window')) |
| 69 driver.SwitchToMainFrame() |
| 70 self.assertTrue(driver.ExecuteScript('return window.top == window')) |
| 71 driver.SwitchToFrameByIndex(0) |
| 72 self.assertTrue(driver.ExecuteScript('return window.top != window')) |
| 73 driver.Quit() |
| 74 |
| 55 | 75 |
| 56 if __name__ == '__main__': | 76 if __name__ == '__main__': |
| 57 parser = optparse.OptionParser() | 77 parser = optparse.OptionParser() |
| 58 parser.add_option( | 78 parser.add_option( |
| 59 '', '--chromedriver', type='string', default=None, | 79 '', '--chromedriver', type='string', default=None, |
| 60 help='Path to a build of the chromedriver library(REQUIRED!)') | 80 help='Path to a build of the chromedriver library(REQUIRED!)') |
| 61 parser.add_option( | 81 parser.add_option( |
| 62 '', '--chrome', type='string', default=None, | 82 '', '--chrome', type='string', default=None, |
| 63 help='Path to a build of the chrome binary') | 83 help='Path to a build of the chrome binary') |
| 64 parser.add_option( | 84 parser.add_option( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 if options.chrome is not None: | 97 if options.chrome is not None: |
| 78 _CHROME_BINARY = os.path.abspath(options.chrome) | 98 _CHROME_BINARY = os.path.abspath(options.chrome) |
| 79 else: | 99 else: |
| 80 _CHROME_BINARY = None | 100 _CHROME_BINARY = None |
| 81 | 101 |
| 82 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 102 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
| 83 sys.modules[__name__]) | 103 sys.modules[__name__]) |
| 84 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 104 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
| 85 result = unittest.TextTestRunner().run(tests) | 105 result = unittest.TextTestRunner().run(tests) |
| 86 sys.exit(len(result.failures) + len(result.errors)) | 106 sys.exit(len(result.failures) + len(result.errors)) |
| OLD | NEW |