Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/test/webdriver/chromedriver_tests.py

Issue 6630001: Allow webdriver users to choose between sending the key events when... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Tests for ChromeDriver. 7 """Tests for ChromeDriver.
8 8
9 If your test is testing a specific part of the WebDriver API, consider adding 9 If your test is testing a specific part of the WebDriver API, consider adding
10 it to the appropriate place in the WebDriver tree instead. 10 it to the appropriate place in the WebDriver tree instead.
11 """ 11 """
12 12
13 import platform 13 import platform
14 import os 14 import os
15 import sys 15 import sys
16 import unittest 16 import unittest
17 import urllib2 17 import urllib2
18 import urlparse 18 import urlparse
19 19
20 from chromedriver_launcher import ChromeDriverLauncher 20 from chromedriver_launcher import ChromeDriverLauncher
21 import chromedriver_paths 21 import chromedriver_paths
22 from gtest_text_test_runner import GTestTextTestRunner 22 from gtest_text_test_runner import GTestTextTestRunner
23 23
24 sys.path += [chromedriver_paths.SRC_THIRD_PARTY] 24 sys.path += [chromedriver_paths.SRC_THIRD_PARTY]
25 sys.path += [chromedriver_paths.PYTHON_BINDINGS] 25 sys.path += [chromedriver_paths.PYTHON_BINDINGS]
26 26
27 import simplejson as json 27 import simplejson as json
28 28
29 from selenium.webdriver.remote.webdriver import WebDriver 29 from selenium.webdriver.remote.webdriver import WebDriver
30 from selenium.webdriver.common.keys import Keys
31 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
30 32
31 33
32 class Request(urllib2.Request): 34 class Request(urllib2.Request):
33 """Extends urllib2.Request to support all HTTP request types.""" 35 """Extends urllib2.Request to support all HTTP request types."""
34 36
35 def __init__(self, url, method=None, data=None): 37 def __init__(self, url, method=None, data=None):
36 """Initialise a new HTTP request. 38 """Initialise a new HTTP request.
37 39
38 Arguments: 40 Arguments:
39 url: The full URL to send the request to. 41 url: The full URL to send the request to.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 104
103 def testShouldGetA404WhenAttemptingToDeleteAnUnknownSession(self): 105 def testShouldGetA404WhenAttemptingToDeleteAnUnknownSession(self):
104 request_url = self._launcher.GetURL() + '/session/unkown_session_id' 106 request_url = self._launcher.GetURL() + '/session/unkown_session_id'
105 try: 107 try:
106 SendRequest(request_url, method='DELETE') 108 SendRequest(request_url, method='DELETE')
107 self.fail('Should have raised a urllib.HTTPError for returned 404') 109 self.fail('Should have raised a urllib.HTTPError for returned 404')
108 except urllib2.HTTPError, expected: 110 except urllib2.HTTPError, expected:
109 self.assertEquals(404, expected.code) 111 self.assertEquals(404, expected.code)
110 112
111 def testCanStartChromeDriverOnSpecificPort(self): 113 def testCanStartChromeDriverOnSpecificPort(self):
112 launcher = ChromeDriverLauncher(port=9520) 114 self.launcher = ChromeDriverLauncher(port=9520)
113 self.assertEquals(9520, launcher.GetPort()) 115 self.assertEquals(9520, launcher.GetPort())
114 driver = WebDriver(launcher.GetURL(), 'chrome', 'any') 116 driver = WebDriver(launcher.GetURL(), {})
115 driver.quit() 117 driver.quit()
116 launcher.Kill() 118 launcher.Kill()
117 119
118 120
121 class NativeInputTest(unittest.TestCase):
122 """Native input ChromeDriver tests."""
123
124 SEARCH = "http://www.google.com/webhp?hl=en"
125
126 def setUp(self):
127 self._launcher = ChromeDriverLauncher()
128 self.capabilities = DesiredCapabilities.CHROME
129 self.capabilities["chrome"] = { "nativeEvents" : True }
130
131 def tearDown(self):
132 self._launcher.Kill()
133
134 def testCanStartsWithNativeEvents(self):
135 driver = WebDriver(self._launcher.GetURL(), self.capabilities)
136 self.assertTrue(driver.capabilities["chrome"].has_key("nativeEvents"))
137 self.assertTrue(driver.capabilities["chrome"]["nativeEvents"])
138
139 def testSendKeysNative(self):
140 driver = WebDriver(self._launcher.GetURL(), self.capabilities)
141 driver.get(self.SEARCH)
142 # Find the Google search Button.
143 q = driver.find_element_by_name("q")
144 # Send some keys.
145 q.send_keys("tokyo")
146 self.assertEqual(q.value, "tokyo")
147
148 #TODO(timothe): run this test on a machine with an IME enabled.
kkania 2011/03/11 16:32:13 how are you planning on doing this? you can just d
timothe 2011/03/21 18:02:05 @unittest.skip only works for python 2.7+, is it o
149 #def testSendKeysNativeProcessedByIME(self):
150 #driver = WebDriver(self._launcher.GetURL(), self.capabilities)
151 #driver.get(self.SEARCH)
152 #q = driver.find_element_by_name("q")
153 # Send key combination to turn IME on.
154 #q.send_keys(Keys.F7)
155 #q.send_keys("toukyou")
156 #self.assertEqual(q.value, "\xe6\x9d\xb1\xe4\xba\xac")
157
158
119 class CookieTest(unittest.TestCase): 159 class CookieTest(unittest.TestCase):
120 """Cookie test for the json webdriver protocol""" 160 """Cookie test for the json webdriver protocol"""
121 161
122 SEARCH = "http://www.google.com/webhp?hl=en" 162 SEARCH = "http://www.google.com/webhp?hl=en"
123 163
124 def setUp(self): 164 def setUp(self):
125 self._launcher = ChromeDriverLauncher() 165 self._launcher = ChromeDriverLauncher()
126 self._driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 166 self._driver = WebDriver(self._launcher.GetURL(), {})
127 167
128 def tearDown(self): 168 def tearDown(self):
129 self._driver.quit() 169 self._driver.quit()
130 self._launcher.Kill() 170 self._launcher.Kill()
131 171
132 def testAddCookie(self): 172 def testAddCookie(self):
133 self._driver.get(self.SEARCH) 173 self._driver.get(self.SEARCH)
134 cookie_dict = None 174 cookie_dict = None
135 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") 175 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test")
136 cookie_dict = {} 176 cookie_dict = {}
(...skipping 30 matching lines...) Expand all
167 self.assertTrue(isinstance(data, dict)) 207 self.assertTrue(isinstance(data, dict))
168 self.assertEquals(0, data['status']) 208 self.assertEquals(0, data['status'])
169 209
170 url_parts = urlparse.urlparse(self.session_url)[2].split('/') 210 url_parts = urlparse.urlparse(self.session_url)[2].split('/')
171 self.assertEquals(3, len(url_parts)) 211 self.assertEquals(3, len(url_parts))
172 self.assertEquals('', url_parts[0]) 212 self.assertEquals('', url_parts[0])
173 self.assertEquals('session', url_parts[1]) 213 self.assertEquals('session', url_parts[1])
174 self.assertEquals(data['sessionId'], url_parts[2]) 214 self.assertEquals(data['sessionId'], url_parts[2])
175 215
176 def testShouldBeGivenCapabilitiesWhenStartingASession(self): 216 def testShouldBeGivenCapabilitiesWhenStartingASession(self):
177 driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 217 driver = WebDriver(self._launcher.GetURL(), {})
178 capabilities = driver.capabilities 218 capabilities = driver.capabilities
179 219
180 self.assertEquals('chrome', capabilities['browserName']) 220 self.assertEquals('chrome', capabilities['browserName'])
181 self.assertTrue(capabilities['javascriptEnabled']) 221 self.assertTrue(capabilities['javascriptEnabled'])
182 222
183 # Value depends on what version the server is starting. 223 # Value depends on what version the server is starting.
184 self.assertTrue('version' in capabilities) 224 self.assertTrue('version' in capabilities)
185 self.assertTrue( 225 self.assertTrue(
186 isinstance(capabilities['version'], unicode), 226 isinstance(capabilities['version'], unicode),
187 'Expected a %s, but was %s' % (unicode, 227 'Expected a %s, but was %s' % (unicode,
188 type(capabilities['version']))) 228 type(capabilities['version'])))
189 229
190 system = platform.system() 230 system = platform.system()
191 if system == 'Linux': 231 if system == 'Linux':
192 self.assertEquals('linux', capabilities['platform'].lower()) 232 self.assertEquals('linux', capabilities['platform'].lower())
193 elif system == 'Windows': 233 elif system == 'Windows':
194 self.assertEquals('windows', capabilities['platform'].lower()) 234 self.assertEquals('windows', capabilities['platform'].lower())
195 elif system == 'Darwin': 235 elif system == 'Darwin':
196 self.assertEquals('mac', capabilities['platform'].lower()) 236 self.assertEquals('mac', capabilities['platform'].lower())
197 else: 237 else:
198 # No python on ChromeOS, so we won't have a platform value, but 238 # No python on ChromeOS, so we won't have a platform value, but
199 # the server will know and return the value accordingly. 239 # the server will know and return the value accordingly.
200 self.assertEquals('chromeos', capabilities['platform'].lower()) 240 self.assertEquals('chromeos', capabilities['platform'].lower())
201 driver.quit() 241 driver.quit()
202 242
203 def testSessionCreationDeletion(self): 243 def testSessionCreationDeletion(self):
204 driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 244 driver = WebDriver(self._launcher.GetURL(), {})
205 driver.quit() 245 driver.quit()
206 246
207 def testMultipleSessionCreationDeletion(self): 247 def testMultipleSessionCreationDeletion(self):
208 for i in range(10): 248 for i in range(10):
209 driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 249 driver = WebDriver(self._launcher.GetURL(), {})
210 driver.quit() 250 driver.quit()
211 251
212 def testSessionCommandsAfterSessionDeletionReturn404(self): 252 def testSessionCommandsAfterSessionDeletionReturn404(self):
213 driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 253 driver = WebDriver(self._launcher.GetURL(), {})
214 session_id = driver.session_id 254 session_id = driver.session_id
215 driver.quit() 255 driver.quit()
216 try: 256 try:
217 response = SendRequest(self._launcher.GetURL() + '/session/' + session_id, 257 response = SendRequest(self._launcher.GetURL() + '/session/' + session_id,
218 method='GET') 258 method='GET')
219 self.fail('Should have thrown 404 exception') 259 self.fail('Should have thrown 404 exception')
220 except urllib2.HTTPError, expected: 260 except urllib2.HTTPError, expected:
221 self.assertEquals(404, expected.code) 261 self.assertEquals(404, expected.code)
222 262
223 def testMultipleConcurrentSessions(self): 263 def testMultipleConcurrentSessions(self):
224 drivers = [] 264 drivers = []
225 for i in range(10): 265 for i in range(10):
226 drivers += [WebDriver(self._launcher.GetURL(), 'chrome', 'any')] 266 drivers += [WebDriver(self._launcher.GetURL(), {})]
227 for driver in drivers: 267 for driver in drivers:
228 driver.quit() 268 driver.quit()
229 269
230 270
231 class MouseTest(unittest.TestCase): 271 class MouseTest(unittest.TestCase):
232 """Mouse command tests for the json webdriver protocol""" 272 """Mouse command tests for the json webdriver protocol"""
233 273
234 def setUp(self): 274 def setUp(self):
235 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) 275 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
236 self._driver = WebDriver(self._launcher.GetURL(), 'chrome', 'any') 276 self._driver = WebDriver(self._launcher.GetURL(), {})
237 277
238 def tearDown(self): 278 def tearDown(self):
239 self._driver.quit() 279 self._driver.quit()
240 self._launcher.Kill() 280 self._launcher.Kill()
241 281
242 def testClickElementThatNeedsScrolling(self): 282 def testClickElementThatNeedsScrolling(self):
243 self._driver.get(self._launcher.GetURL() + '/test_page.html') 283 self._driver.get(self._launcher.GetURL() + '/test_page.html')
244 self._driver.find_element_by_name('hidden_scroll').click() 284 self._driver.find_element_by_name('hidden_scroll').click()
245 self.assertTrue(self._driver.execute_script('return window.success')) 285 self.assertTrue(self._driver.execute_script('return window.success'))
246 286
(...skipping 28 matching lines...) Expand all
275 self.assertEquals('', url_parts[0]) 315 self.assertEquals('', url_parts[0])
276 self.assertEquals('wd', url_parts[1]) 316 self.assertEquals('wd', url_parts[1])
277 self.assertEquals('hub', url_parts[2]) 317 self.assertEquals('hub', url_parts[2])
278 self.assertEquals('session', url_parts[3]) 318 self.assertEquals('session', url_parts[3])
279 self.assertEquals(data['sessionId'], url_parts[4]) 319 self.assertEquals(data['sessionId'], url_parts[4])
280 320
281 321
282 if __name__ == '__main__': 322 if __name__ == '__main__':
283 unittest.main(module='chromedriver_tests', 323 unittest.main(module='chromedriver_tests',
284 testRunner=GTestTextTestRunner(verbosity=1)) 324 testRunner=GTestTextTestRunner(verbosity=1))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698