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 |
11 import sys | 11 import sys |
12 import time | |
12 import unittest | 13 import unittest |
13 | 14 |
14 import chromedriver | 15 import chromedriver |
15 import webserver | 16 import webserver |
16 from webelement import WebElement | 17 from webelement import WebElement |
17 | 18 |
18 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 19 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
19 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) | 20 sys.path.insert(0, os.path.join(_THIS_DIR, os.pardir, 'pylib')) |
20 | 21 |
21 from common import chrome_paths | 22 from common import chrome_paths |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) | 78 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) |
78 self._driver.SwitchToMainFrame() | 79 self._driver.SwitchToMainFrame() |
79 self.assertTrue(self._driver.ExecuteScript('return window.top == window')) | 80 self.assertTrue(self._driver.ExecuteScript('return window.top == window')) |
80 self._driver.SwitchToFrame('name') | 81 self._driver.SwitchToFrame('name') |
81 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) | 82 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) |
82 self._driver.SwitchToMainFrame() | 83 self._driver.SwitchToMainFrame() |
83 self.assertTrue(self._driver.ExecuteScript('return window.top == window')) | 84 self.assertTrue(self._driver.ExecuteScript('return window.top == window')) |
84 self._driver.SwitchToFrameByIndex(0) | 85 self._driver.SwitchToFrameByIndex(0) |
85 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) | 86 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) |
86 | 87 |
88 def testExecuteInRemovedFrame(self): | |
89 self._driver.ExecuteScript( | |
90 'var frame = document.createElement("iframe");' | |
91 'frame.id="id";' | |
92 'frame.name="name";' | |
93 'document.body.appendChild(frame);') | |
94 self.assertTrue(self._driver.ExecuteScript('return window.top == window')) | |
95 self._driver.SwitchToFrame('id') | |
96 self.assertTrue(self._driver.ExecuteScript('return window.top != window')) | |
97 self._driver.SwitchToMainFrame() | |
98 self._driver.ExecuteScript( | |
99 'var frame = document.getElementById("id");' | |
100 'window.setTimeout(function() {' | |
101 ' document.body.removeChild(frame);' | |
102 '}, 1000);') | |
kkania
2013/02/06 01:41:25
is there a non racy way to do this?
craigdh
2013/02/06 18:52:49
Yeah, just realized I can probably do it with a po
| |
103 self._driver.SwitchToFrame('id') | |
104 | |
105 def _BecomesTrue(func, sec): | |
106 timeout = time.time() + sec | |
107 while time.time() < timeout: | |
108 if func(): | |
109 return True | |
110 time.sleep(0.01) | |
111 return False | |
112 | |
113 self.assertTrue(_BecomesTrue( | |
114 lambda: self._driver.ExecuteScript('return window.top == window'), 5)) | |
chrisgao (Use stgao instead)
2013/02/06 01:32:14
Are 5 seconds long enough if the bot is in heavy l
craigdh
2013/02/06 18:52:49
Done.
| |
115 | |
87 def testGetTitle(self): | 116 def testGetTitle(self): |
88 script = 'document.title = "title"; return 1;' | 117 script = 'document.title = "title"; return 1;' |
89 self.assertEquals(1, self._driver.ExecuteScript(script)) | 118 self.assertEquals(1, self._driver.ExecuteScript(script)) |
90 self.assertEquals('title', self._driver.GetTitle()) | 119 self.assertEquals('title', self._driver.GetTitle()) |
91 | 120 |
92 def testFindElement(self): | 121 def testFindElement(self): |
93 self._driver.ExecuteScript( | 122 self._driver.ExecuteScript( |
94 'document.body.innerHTML = "<div>a</div><div>b</div>";') | 123 'document.body.innerHTML = "<div>a</div><div>b</div>";') |
95 self.assertTrue( | 124 self.assertTrue( |
96 isinstance(self._driver.FindElement('tag name', 'div'), WebElement)) | 125 isinstance(self._driver.FindElement('tag name', 'div'), WebElement)) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 else: | 299 else: |
271 _CHROME_BINARY = None | 300 _CHROME_BINARY = None |
272 | 301 |
273 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 302 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
274 sys.modules[__name__]) | 303 sys.modules[__name__]) |
275 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 304 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
276 ChromeDriverTest.GlobalSetUp(); | 305 ChromeDriverTest.GlobalSetUp(); |
277 result = unittest.TextTestRunner().run(tests) | 306 result = unittest.TextTestRunner().run(tests) |
278 ChromeDriverTest.GlobalTearDown(); | 307 ChromeDriverTest.GlobalTearDown(); |
279 sys.exit(len(result.failures) + len(result.errors)) | 308 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |