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

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

Issue 6992015: Fix minor issues in ChromeDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 7 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
« no previous file with comments | « chrome/test/webdriver/automation.cc ('k') | chrome/test/webdriver/commands/create_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 # Don't quote the ':' in drive letter ( say, C: ) on win. 52 # Don't quote the ':' in drive letter ( say, C: ) on win.
53 # Also, replace '\' with '/' as expected in a file:/// url. 53 # Also, replace '\' with '/' as expected in a file:/// url.
54 drive, rest = os.path.splitdrive(abs_path) 54 drive, rest = os.path.splitdrive(abs_path)
55 quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/'))) 55 quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/')))
56 return 'file:///' + quoted_path 56 return 'file:///' + quoted_path
57 else: 57 else:
58 quoted_path = urllib.quote(abs_path) 58 quoted_path = urllib.quote(abs_path)
59 return 'file://' + quoted_path 59 return 'file://' + quoted_path
60 60
61 61
62 def IsWindows():
63 return sys.platform == 'cygwin' or sys.platform.startswith('win')
64
65
66 def IsLinux():
67 return sys.platform.startswith('linux')
68
69
70 def IsMac():
71 return sys.platform.startswith('darwin')
72
73
62 class Request(urllib2.Request): 74 class Request(urllib2.Request):
63 """Extends urllib2.Request to support all HTTP request types.""" 75 """Extends urllib2.Request to support all HTTP request types."""
64 76
65 def __init__(self, url, method=None, data=None): 77 def __init__(self, url, method=None, data=None):
66 """Initialise a new HTTP request. 78 """Initialise a new HTTP request.
67 79
68 Arguments: 80 Arguments:
69 url: The full URL to send the request to. 81 url: The full URL to send the request to.
70 method: The HTTP request method to use; defaults to 'GET'. 82 method: The HTTP request method to use; defaults to 'GET'.
71 data: The data to send with the request as a string. Defaults to 83 data: The data to send with the request as a string. Defaults to
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 SendRequest(request_url, method='GET') 193 SendRequest(request_url, method='GET')
182 launcher.Kill() 194 launcher.Kill()
183 195
184 196
185 class NativeInputTest(unittest.TestCase): 197 class NativeInputTest(unittest.TestCase):
186 """Native input ChromeDriver tests.""" 198 """Native input ChromeDriver tests."""
187 199
188 def setUp(self): 200 def setUp(self):
189 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) 201 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
190 self._capabilities = DesiredCapabilities.CHROME 202 self._capabilities = DesiredCapabilities.CHROME
191 self._capabilities["chrome"] = { "nativeEvents" : True } 203 self._capabilities['chrome.nativeEvents'] = True
192 204
193 def tearDown(self): 205 def tearDown(self):
194 self._launcher.Kill() 206 self._launcher.Kill()
195 207
196 def testCanStartsWithNativeEvents(self): 208 def testCanStartWithNativeEvents(self):
197 driver = WebDriver(self._launcher.GetURL(), self._capabilities) 209 driver = WebDriver(self._launcher.GetURL(), self._capabilities)
198 self.assertTrue(driver.capabilities["chrome"].has_key("nativeEvents")) 210 self.assertTrue(driver.capabilities.has_key('chrome.nativeEvents'))
199 self.assertTrue(driver.capabilities["chrome"]["nativeEvents"]) 211 self.assertTrue(driver.capabilities['chrome.nativeEvents'])
200 212
201 # Flaky on windows. See crbug.com/80295. 213 # Flaky on windows. See crbug.com/80295.
202 def DISABLED_testSendKeysNative(self): 214 def DISABLED_testSendKeysNative(self):
203 driver = WebDriver(self._launcher.GetURL(), self._capabilities) 215 driver = WebDriver(self._launcher.GetURL(), self._capabilities)
204 driver.get(self._launcher.GetURL() + '/test_page.html') 216 driver.get(self._launcher.GetURL() + '/test_page.html')
205 # Find the text input. 217 # Find the text input.
206 q = driver.find_element_by_name("key_input_test") 218 q = driver.find_element_by_name('key_input_test')
207 # Send some keys. 219 # Send some keys.
208 q.send_keys("tokyo") 220 q.send_keys('tokyo')
209 #TODO(timothe): change to .text when beta 4 wrappers are out. 221 self.assertEqual(q.text, 'tokyo')
210 self.assertEqual(q.value, "tokyo")
211 222
212 # Needs to run on a machine with an IME installed. 223 # Needs to run on a machine with an IME installed.
213 def DISABLED_testSendKeysNativeProcessedByIME(self): 224 def DISABLED_testSendKeysNativeProcessedByIME(self):
214 driver = WebDriver(self._launcher.GetURL(), self.capabilities) 225 driver = WebDriver(self._launcher.GetURL(), self.capabilities)
215 driver.get(self._launcher.GetURL() + '/test_page.html') 226 driver.get(self._launcher.GetURL() + '/test_page.html')
216 q = driver.find_element_by_name("key_input_test") 227 q = driver.find_element_by_name('key_input_test')
217 # Send key combination to turn IME on. 228 # Send key combination to turn IME on.
218 q.send_keys(Keys.F7) 229 q.send_keys(Keys.F7)
219 q.send_keys("toukyou") 230 q.send_keys('toukyou')
220 # Now turning it off. 231 # Now turning it off.
221 q.send_keys(Keys.F7) 232 q.send_keys(Keys.F7)
222 self.assertEqual(q.value, "\xe6\x9d\xb1\xe4\xba\xac") 233 self.assertEqual(q.value, "\xe6\x9d\xb1\xe4\xba\xac")
223 234
224 235
225 class CommandLineOptionsTest(unittest.TestCase): 236 class DesiredCapabilitiesTest(unittest.TestCase):
226 """ Tests ability to add command line flags when startinfg chrome."""
227 237
228 def setUp(self): 238 def setUp(self):
229 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) 239 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
230 self._driver = None
231 240
232 def tearDown(self): 241 def tearDown(self):
233 self._driver.quit()
234 self._launcher.Kill() 242 self._launcher.Kill()
235 243
236 def sendFlag(self): 244 def testCustomSwitches(self):
237 flags = {"enable-file-cookie" : ""} 245 switches = ['enable-file-cookie', 'homepage=about:memory']
238 args = {} 246 capabilities = {'chrome.switches': switches}
239 args.update(DesiredCapabilities.CHROME) 247
240 args.update({"chrome" : {"customSwitches":flags}}) 248 driver = WebDriver(self._launcher.GetURL(), capabilities)
241 # make sure enable cookie is not already enabled 249 url = driver.current_url
242 self.__driver = WebDriver(self._launcher.GetURL(), 250 self.assertTrue('memory' in url,
243 DesiredCapabilities.CHROME) 251 'URL does not contain with "memory":' + url)
244 self.__driver.get("about:version") 252 driver.get('about:version')
245 s = self.__driver.get_page_source() 253 self.assertNotEqual(-1, driver.page_source.find('enable-file-cookie'))
246 self.assertEqual(-1, s.find("enable-file-cookie")) 254
247 self.__driver.close() 255 def testBinary(self):
248 # relaunch with added flags 256 binary_path = ChromeDriverLauncher.LocateExe()
249 self.__driver = WebDriver(self._launcher.GetURL(), args) 257 self.assertNotEquals(None, binary_path)
250 self.__driver.get("about:version") 258 if IsWindows():
251 s = self.__driver.get_page_source() 259 chrome_name = 'chrome.exe'
252 self.assertNotEqual(-1, s.find("enable-file-cookie")) 260 elif IsMac():
261 chrome_name = 'Google Chrome.app/Contents/MacOS/Google Chrome'
262 if not os.path.exists(os.path.join(binary_path, chrome_name)):
263 chrome_name = 'Chromium.app/Contents/MacOS/Chromium'
264 elif IsLinux():
265 chrome_name = 'chrome'
266 else:
267 self.fail('Unrecognized platform: ' + sys.platform)
268 binary_path = os.path.join(os.path.dirname(binary_path), chrome_name)
269 self.assertTrue(os.path.exists(binary_path),
270 'Binary not found: ' + binary_path)
271 capabilities = {'chrome.binary': binary_path}
272
273 driver = WebDriver(self._launcher.GetURL(), capabilities)
253 274
254 275
255 class CookieTest(unittest.TestCase): 276 class CookieTest(unittest.TestCase):
256 """Cookie test for the json webdriver protocol""" 277 """Cookie test for the json webdriver protocol"""
257 278
258 def setUp(self): 279 def setUp(self):
259 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) 280 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
260 self._driver = WebDriver(self._launcher.GetURL(), 281 self._driver = WebDriver(self._launcher.GetURL(),
261 DesiredCapabilities.CHROME) 282 DesiredCapabilities.CHROME)
262 283
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 """Tests dealing with WebDriver sessions.""" 334 """Tests dealing with WebDriver sessions."""
314 335
315 def setUp(self): 336 def setUp(self):
316 self._launcher = ChromeDriverLauncher() 337 self._launcher = ChromeDriverLauncher()
317 338
318 def tearDown(self): 339 def tearDown(self):
319 self._launcher.Kill() 340 self._launcher.Kill()
320 341
321 def testCreatingSessionShouldRedirectToCorrectURL(self): 342 def testCreatingSessionShouldRedirectToCorrectURL(self):
322 request_url = self._launcher.GetURL() + '/session' 343 request_url = self._launcher.GetURL() + '/session'
323 response = SendRequest(request_url, method='POST', data='{}') 344 response = SendRequest(request_url, method='POST',
345 data='{"desiredCapabilities": {}}')
324 self.assertEquals(200, response.code) 346 self.assertEquals(200, response.code)
325 self.session_url = response.geturl() # TODO(jleyba): verify this URL? 347 self.session_url = response.geturl() # TODO(jleyba): verify this URL?
326 348
327 data = json.loads(response.read()) 349 data = json.loads(response.read())
328 self.assertTrue(isinstance(data, dict)) 350 self.assertTrue(isinstance(data, dict))
329 self.assertEquals(0, data['status']) 351 self.assertEquals(0, data['status'])
330 352
331 url_parts = urlparse.urlparse(self.session_url)[2].split('/') 353 url_parts = urlparse.urlparse(self.session_url)[2].split('/')
332 self.assertEquals(3, len(url_parts)) 354 self.assertEquals(3, len(url_parts))
333 self.assertEquals('', url_parts[0]) 355 self.assertEquals('', url_parts[0])
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 """Tests that the server can be configured for a different URL base.""" 453 """Tests that the server can be configured for a different URL base."""
432 454
433 def setUp(self): 455 def setUp(self):
434 self._launcher = ChromeDriverLauncher(url_base='/wd/hub') 456 self._launcher = ChromeDriverLauncher(url_base='/wd/hub')
435 457
436 def tearDown(self): 458 def tearDown(self):
437 self._launcher.Kill() 459 self._launcher.Kill()
438 460
439 def testCreatingSessionShouldRedirectToCorrectURL(self): 461 def testCreatingSessionShouldRedirectToCorrectURL(self):
440 request_url = self._launcher.GetURL() + '/session' 462 request_url = self._launcher.GetURL() + '/session'
441 response = SendRequest(request_url, method='POST', data='{}') 463 response = SendRequest(request_url, method='POST',
464 data='{"desiredCapabilities":{}}')
442 self.assertEquals(200, response.code) 465 self.assertEquals(200, response.code)
443 self.session_url = response.geturl() # TODO(jleyba): verify this URL? 466 self.session_url = response.geturl() # TODO(jleyba): verify this URL?
444 467
445 data = json.loads(response.read()) 468 data = json.loads(response.read())
446 self.assertTrue(isinstance(data, dict)) 469 self.assertTrue(isinstance(data, dict))
447 self.assertEquals(0, data['status']) 470 self.assertEquals(0, data['status'])
448 471
449 url_parts = urlparse.urlparse(self.session_url)[2].split('/') 472 url_parts = urlparse.urlparse(self.session_url)[2].split('/')
450 self.assertEquals(5, len(url_parts)) 473 self.assertEquals(5, len(url_parts))
451 self.assertEquals('', url_parts[0]) 474 self.assertEquals('', url_parts[0])
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 list_entry = driver.find_element_by_class_name('autofill-list-item') 592 list_entry = driver.find_element_by_class_name('autofill-list-item')
570 self.assertTrue(list_entry.is_displayed) 593 self.assertTrue(list_entry.is_displayed)
571 self.assertEqual(list_entry.text, 594 self.assertEqual(list_entry.text,
572 creditcard_data['CREDIT_CARD_NAME'], 595 creditcard_data['CREDIT_CARD_NAME'],
573 'Saved CC line item not same as what was entered.') 596 'Saved CC line item not same as what was entered.')
574 597
575 598
576 if __name__ == '__main__': 599 if __name__ == '__main__':
577 unittest.main(module='chromedriver_tests', 600 unittest.main(module='chromedriver_tests',
578 testRunner=GTestTextTestRunner(verbosity=1)) 601 testRunner=GTestTextTestRunner(verbosity=1))
OLDNEW
« no previous file with comments | « chrome/test/webdriver/automation.cc ('k') | chrome/test/webdriver/commands/create_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698