Chromium Code Reviews| 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 """Tests for ChromeDriver. | 5 """Tests for ChromeDriver. |
| 6 | 6 |
| 7 If your test is testing a specific part of the WebDriver API, consider adding | 7 If your test is testing a specific part of the WebDriver API, consider adding |
| 8 it to the appropriate place in the WebDriver tree instead. | 8 it to the appropriate place in the WebDriver tree instead. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 | 972 |
| 973 def testCanHandleAlertInSubframe(self): | 973 def testCanHandleAlertInSubframe(self): |
| 974 driver = self.GetNewDriver() | 974 driver = self.GetNewDriver() |
| 975 driver.get(self.GetTestDataUrl() + '/alerts.html') | 975 driver.get(self.GetTestDataUrl() + '/alerts.html') |
| 976 driver.switch_to_frame('subframe') | 976 driver.switch_to_frame('subframe') |
| 977 driver.execute_async_script('arguments[0](); window.alert("ok")') | 977 driver.execute_async_script('arguments[0](); window.alert("ok")') |
| 978 driver.switch_to_alert().accept() | 978 driver.switch_to_alert().accept() |
| 979 | 979 |
| 980 | 980 |
| 981 class WindowTest(ChromeDriverTest): | 981 class WindowTest(ChromeDriverTest): |
| 982 def testSizeAndPosition(self): | 982 """Tests for WebDriver window commands.""" |
| 983 driver = self.GetNewDriver() | |
| 984 | 983 |
| 984 def setUp(self): | |
| 985 super(WindowTest, self).setUp() | |
| 986 self._driver = self.GetNewDriver() | |
| 985 # TODO(kkania): Update the python bindings and get rid of these. | 987 # TODO(kkania): Update the python bindings and get rid of these. |
| 986 driver.command_executor._commands.update({ | 988 self._driver.command_executor._commands.update({ |
| 987 'getSize': ('GET', '/session/$sessionId/window/$windowHandle/size'), | 989 'getSize': ('GET', '/session/$sessionId/window/$windowHandle/size'), |
| 988 'setSize': ('POST', '/session/$sessionId/window/$windowHandle/size'), | 990 'setSize': ('POST', '/session/$sessionId/window/$windowHandle/size'), |
| 989 'getPos': ('GET', '/session/$sessionId/window/$windowHandle/position'), | 991 'getPos': ('GET', '/session/$sessionId/window/$windowHandle/position'), |
| 990 'setPos': ('POST', '/session/$sessionId/window/$windowHandle/position') | 992 'setPos': ('POST', '/session/$sessionId/window/$windowHandle/position'), |
| 993 'max': ('POST', '/session/$sessionId/window/$windowHandle/maximize') | |
| 991 }) | 994 }) |
| 992 def getSize(window='current'): | |
| 993 return driver.execute('getSize', {'windowHandle': window})['value'] | |
| 994 def setSize(width, height, window='current'): | |
| 995 params = { 'windowHandle': window, | |
| 996 'width': width, | |
| 997 'height': height | |
| 998 } | |
| 999 return driver.execute('setSize', params) | |
| 1000 def getPosition(window='current'): | |
| 1001 return driver.execute('getPos', {'windowHandle': window})['value'] | |
| 1002 def setPosition(x, y, window='current'): | |
| 1003 params = { 'windowHandle': window, | |
| 1004 'x': x, | |
| 1005 'y': y | |
| 1006 } | |
| 1007 return driver.execute('setPos', params) | |
| 1008 | 995 |
| 1009 # Test size. | 996 def _getSize(self, window='current'): |
| 1010 size = getSize() | 997 return self._driver.execute('getSize', {'windowHandle': window})['value'] |
| 1011 setSize(size['width'], size['height']) | 998 |
| 1012 self.assertEquals(size, getSize()) | 999 def _setSize(self, width, height, window='current'): |
| 1013 setSize(800, 600) | 1000 params = { 'windowHandle': window, |
| 1014 self.assertEquals(800, getSize()['width']) | 1001 'width': width, |
| 1015 self.assertEquals(600, getSize()['height']) | 1002 'height': height |
| 1016 # Test position. | 1003 } |
| 1017 pos = getPosition() | 1004 return self._driver.execute('setSize', params) |
| 1018 setPosition(pos['x'], pos['y']) | 1005 |
| 1019 self.assertEquals(pos, getPosition()) | 1006 def _getPosition(self, window='current'): |
| 1020 setPosition(100, 200) | 1007 return self._driver.execute('getPos', {'windowHandle': window})['value'] |
| 1021 self.assertEquals(100, getPosition()['x']) | 1008 |
| 1022 self.assertEquals(200, getPosition()['y']) | 1009 def _setPosition(self, x, y, window='current'): |
| 1023 # Test specifying window handle. | 1010 params = { 'windowHandle': window, |
| 1024 driver.execute_script( | 1011 'x': x, |
| 1012 'y': y | |
| 1013 } | |
| 1014 return self._driver.execute('setPos', params) | |
| 1015 | |
| 1016 def _maximize(self, window='current'): | |
| 1017 return self._driver.execute('max', {'windowHandle': window}) | |
| 1018 | |
| 1019 def testSize(self): | |
| 1020 size = self._getSize() | |
| 1021 self._setSize(size['width'], size['height']) | |
| 1022 self.assertEquals(size, self._getSize()) | |
| 1023 self._setSize(800, 600) | |
| 1024 self.assertEquals(800, self._getSize()['width']) | |
| 1025 self.assertEquals(600, self._getSize()['height']) | |
| 1026 | |
| 1027 def testPosition(self): | |
| 1028 pos = self._getPosition() | |
| 1029 self._setPosition(pos['x'], pos['y']) | |
| 1030 self.assertEquals(pos, self._getPosition()) | |
| 1031 self._setPosition(100, 200) | |
| 1032 self.assertEquals(100, self._getPosition()['x']) | |
| 1033 self.assertEquals(200, self._getPosition()['y']) | |
| 1034 | |
| 1035 # Systems without window manager (Xvfb, Xvnc) do not implement maximization. | |
| 1036 @SkipIf(util.IsLinux()) | |
| 1037 def testMaximize(self): | |
| 1038 old_size = self._getSize() | |
| 1039 self._maximize() | |
| 1040 new_size = self._getSize() | |
| 1041 self.assertTrue(old_size['width'] <= new_size['width']) | |
| 1042 self.assertTrue(old_size['height'] <= new_size['height']) | |
| 1043 | |
| 1044 def testWindowHandle(self): | |
| 1045 """Test specifying window handle.""" | |
| 1046 self._driver.execute_script( | |
| 1025 'window.open("about:blank", "name", "height=200, width=200")') | 1047 'window.open("about:blank", "name", "height=200, width=200")') |
| 1026 windows = driver.window_handles | 1048 windows = self._driver.window_handles |
| 1027 self.assertEquals(2, len(windows)) | 1049 self.assertEquals(2, len(windows)) |
| 1028 setSize(400, 300, windows[1]) | 1050 self._setSize(400, 300, windows[1]) |
| 1029 self.assertEquals(400, getSize(windows[1])['width']) | 1051 self.assertEquals(400, self._getSize(windows[1])['width']) |
| 1030 self.assertEquals(300, getSize(windows[1])['height']) | 1052 self.assertEquals(300, self._getSize(windows[1])['height']) |
| 1031 self.assertNotEquals(getSize(windows[1]), getSize(windows[0])) | 1053 self.assertNotEquals(self._getSize(windows[1]), self._getSize(windows[0])) |
| 1032 # Test specifying invalid handle. | 1054 |
| 1055 def testInvalidWindowHandle(self): | |
| 1056 """Tests specifying invalid handle.""" | |
| 1033 invalid_handle = 'f1-120' | 1057 invalid_handle = 'f1-120' |
| 1034 self.assertRaises(WebDriverException, setSize, 400, 300, invalid_handle) | 1058 self.assertRaises(WebDriverException, self._setSize, 400, 300, |
| 1035 self.assertRaises(NoSuchWindowException, getSize, invalid_handle) | 1059 invalid_handle) |
| 1036 self.assertRaises(NoSuchWindowException, setPosition, 1, 1, invalid_handle) | 1060 self.assertRaises(NoSuchWindowException, self._getSize, invalid_handle) |
| 1037 self.assertRaises(NoSuchWindowException, getPosition, invalid_handle) | 1061 self.assertRaises(NoSuchWindowException, self._setPosition, 1, 1, |
| 1062 invalid_handle) | |
| 1063 self.assertRaises(NoSuchWindowException, self._getPosition, invalid_handle) | |
| 1064 # self.assertRaises(NoSuchWindowException, self._maximize, invalid_handle) | |
|
kkania
2012/06/01 04:14:03
?
zori
2012/06/02 01:20:54
Sorry about that. Fixed.
On 2012/06/01 04:14:03, k
| |
| 1065 | |
| 1038 | 1066 |
| 1039 | 1067 |
| 1040 class GeolocationTest(ChromeDriverTest): | 1068 class GeolocationTest(ChromeDriverTest): |
| 1041 """Tests for WebDriver geolocation commands.""" | 1069 """Tests for WebDriver geolocation commands.""" |
| 1042 | 1070 |
| 1043 def testGeolocation(self): | 1071 def testGeolocation(self): |
| 1044 """Tests the get and set geolocation commands.""" | 1072 """Tests the get and set geolocation commands.""" |
| 1045 driver = self.GetNewDriver() | 1073 driver = self.GetNewDriver() |
| 1046 | 1074 |
| 1047 # TODO(kkania): Update the python bindings and get rid of these. | 1075 # TODO(kkania): Update the python bindings and get rid of these. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1137 self._testExtensionView(driver, ext.get_popup_handle(), ext) | 1165 self._testExtensionView(driver, ext.get_popup_handle(), ext) |
| 1138 | 1166 |
| 1139 def testPageActionPopupView(self): | 1167 def testPageActionPopupView(self): |
| 1140 driver = self.GetNewDriver() | 1168 driver = self.GetNewDriver() |
| 1141 ext = driver.install_extension(self.PAGE_ACTION_EXTENSION) | 1169 ext = driver.install_extension(self.PAGE_ACTION_EXTENSION) |
| 1142 def is_page_action_visible(driver): | 1170 def is_page_action_visible(driver): |
| 1143 return ext.is_page_action_visible() | 1171 return ext.is_page_action_visible() |
| 1144 WebDriverWait(driver, 10).until(is_page_action_visible) | 1172 WebDriverWait(driver, 10).until(is_page_action_visible) |
| 1145 ext.click_page_action() | 1173 ext.click_page_action() |
| 1146 self._testExtensionView(driver, ext.get_popup_handle(), ext) | 1174 self._testExtensionView(driver, ext.get_popup_handle(), ext) |
| OLD | NEW |