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

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 os
13 import platform 14 import platform
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 try:
28 import simplejson as json
29 except ImportError:
30 import json
28 31
29 from selenium.webdriver.remote.webdriver import WebDriver 32 from selenium.webdriver.remote.webdriver import WebDriver
33 from selenium.webdriver.common.keys import Keys
34 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
30 35
31 36
32 class Request(urllib2.Request): 37 class Request(urllib2.Request):
33 """Extends urllib2.Request to support all HTTP request types.""" 38 """Extends urllib2.Request to support all HTTP request types."""
34 39
35 def __init__(self, url, method=None, data=None): 40 def __init__(self, url, method=None, data=None):
36 """Initialise a new HTTP request. 41 """Initialise a new HTTP request.
37 42
38 Arguments: 43 Arguments:
39 url: The full URL to send the request to. 44 url: The full URL to send the request to.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 request_url = self._launcher.GetURL() + '/session/unkown_session_id' 109 request_url = self._launcher.GetURL() + '/session/unkown_session_id'
105 try: 110 try:
106 SendRequest(request_url, method='DELETE') 111 SendRequest(request_url, method='DELETE')
107 self.fail('Should have raised a urllib.HTTPError for returned 404') 112 self.fail('Should have raised a urllib.HTTPError for returned 404')
108 except urllib2.HTTPError, expected: 113 except urllib2.HTTPError, expected:
109 self.assertEquals(404, expected.code) 114 self.assertEquals(404, expected.code)
110 115
111 def testCanStartChromeDriverOnSpecificPort(self): 116 def testCanStartChromeDriverOnSpecificPort(self):
112 launcher = ChromeDriverLauncher(port=9520) 117 launcher = ChromeDriverLauncher(port=9520)
113 self.assertEquals(9520, launcher.GetPort()) 118 self.assertEquals(9520, launcher.GetPort())
114 driver = WebDriver(launcher.GetURL(), {}) 119 driver = WebDriver(launcher.GetURL(), DesiredCapabilities.CHROME)
115 driver.quit() 120 driver.quit()
116 launcher.Kill() 121 launcher.Kill()
117 122
118 123
124 class NativeInputTest(unittest.TestCase):
125 """Native input ChromeDriver tests."""
126
127 def setUp(self):
128 self._launcher = ChromeDriverLauncher()
129 self._capabilities = DesiredCapabilities.CHROME
130 self._capabilities["chrome"] = { "nativeEvents" : True }
131
132 def tearDown(self):
133 self._launcher.Kill()
134
135 def testCanStartsWithNativeEvents(self):
136 driver = WebDriver(self._launcher.GetURL(), self._capabilities)
137 self.assertTrue(driver.capabilities["chrome"].has_key("nativeEvents"))
138 self.assertTrue(driver.capabilities["chrome"]["nativeEvents"])
139
140 def testSendKeysNative(self):
141 driver = WebDriver(self._launcher.GetURL(), self._capabilities)
142 driver.get(self._launcher.GetURL() + '/test_page.html')
143 # Find the text input.
144 q = driver.find_element_by_name("key_input_test")
145 # Send some keys.
146 q.send_keys("tokyo")
147 self.assertEqual(q.value, "tokyo")
148
149 #@unittest.skip("Need to run this on a machine with an IME installed.")
150 #def testSendKeysNativeProcessedByIME(self):
151 #driver = WebDriver(self._launcher.GetURL(), self.capabilities)
152 #driver.get(self._launcher.GetURL() + '/test_page.html')
153 #q = driver.find_element_by_name("key_input_test")
154 ## Send key combination to turn IME on.
155 #q.send_keys(Keys.F7)
156 #q.send_keys("toukyou")
157 ## Now turning it off.
158 #q.send_keys(Keys.F7)
159 #self.assertEqual(q.value, "\xe6\x9d\xb1\xe4\xba\xac")
160
161
119 class CookieTest(unittest.TestCase): 162 class CookieTest(unittest.TestCase):
120 """Cookie test for the json webdriver protocol""" 163 """Cookie test for the json webdriver protocol"""
121 164
122 def setUp(self): 165 def setUp(self):
123 self._launcher = ChromeDriverLauncher() 166 self._launcher = ChromeDriverLauncher()
124 self._driver = WebDriver(self._launcher.GetURL(), {}) 167 self._driver = WebDriver(self._launcher.GetURL(),
168 DesiredCapabilities.CHROME)
125 169
126 def tearDown(self): 170 def tearDown(self):
127 self._driver.quit() 171 self._driver.quit()
128 self._launcher.Kill() 172 self._launcher.Kill()
129 173
130 def testAddCookie(self): 174 def testAddCookie(self):
131 self._driver.get(self._launcher.GetURL() + '/test_page.html') 175 self._driver.get(self._launcher.GetURL() + '/test_page.html')
132 cookie_dict = None 176 cookie_dict = None
133 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") 177 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test")
134 cookie_dict = {} 178 cookie_dict = {}
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 self.assertEquals('windows', capabilities['platform'].lower()) 236 self.assertEquals('windows', capabilities['platform'].lower())
193 elif system == 'Darwin': 237 elif system == 'Darwin':
194 self.assertEquals('mac', capabilities['platform'].lower()) 238 self.assertEquals('mac', capabilities['platform'].lower())
195 else: 239 else:
196 # No python on ChromeOS, so we won't have a platform value, but 240 # No python on ChromeOS, so we won't have a platform value, but
197 # the server will know and return the value accordingly. 241 # the server will know and return the value accordingly.
198 self.assertEquals('chromeos', capabilities['platform'].lower()) 242 self.assertEquals('chromeos', capabilities['platform'].lower())
199 driver.quit() 243 driver.quit()
200 244
201 def testSessionCreationDeletion(self): 245 def testSessionCreationDeletion(self):
202 driver = WebDriver(self._launcher.GetURL(), {}) 246 driver = WebDriver(self._launcher.GetURL(), DesiredCapabilities.CHROME)
203 driver.quit() 247 driver.quit()
204 248
205 def testMultipleSessionCreationDeletion(self): 249 def testMultipleSessionCreationDeletion(self):
206 for i in range(10): 250 for i in range(10):
207 driver = WebDriver(self._launcher.GetURL(), {}) 251 driver = WebDriver(self._launcher.GetURL(), DesiredCapabilities.CHROME)
208 driver.quit() 252 driver.quit()
209 253
210 def testSessionCommandsAfterSessionDeletionReturn404(self): 254 def testSessionCommandsAfterSessionDeletionReturn404(self):
211 driver = WebDriver(self._launcher.GetURL(), {}) 255 driver = WebDriver(self._launcher.GetURL(), DesiredCapabilities.CHROME)
212 session_id = driver.session_id 256 session_id = driver.session_id
213 driver.quit() 257 driver.quit()
214 try: 258 try:
215 response = SendRequest(self._launcher.GetURL() + '/session/' + session_id, 259 response = SendRequest(self._launcher.GetURL() + '/session/' + session_id,
216 method='GET') 260 method='GET')
217 self.fail('Should have thrown 404 exception') 261 self.fail('Should have thrown 404 exception')
218 except urllib2.HTTPError, expected: 262 except urllib2.HTTPError, expected:
219 self.assertEquals(404, expected.code) 263 self.assertEquals(404, expected.code)
220 264
221 def testMultipleConcurrentSessions(self): 265 def testMultipleConcurrentSessions(self):
222 drivers = [] 266 drivers = []
223 for i in range(10): 267 for i in range(10):
224 drivers += [WebDriver(self._launcher.GetURL(), {})] 268 drivers += [WebDriver(self._launcher.GetURL(),
269 DesiredCapabilities.CHROME)]
225 for driver in drivers: 270 for driver in drivers:
226 driver.quit() 271 driver.quit()
227 272
228 273
229 class MouseTest(unittest.TestCase): 274 class MouseTest(unittest.TestCase):
230 """Mouse command tests for the json webdriver protocol""" 275 """Mouse command tests for the json webdriver protocol"""
231 276
232 def setUp(self): 277 def setUp(self):
233 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) 278 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
234 self._driver = WebDriver(self._launcher.GetURL(), {}) 279 self._driver = WebDriver(self._launcher.GetURL(),
280 DesiredCapabilities.CHROME)
235 281
236 def tearDown(self): 282 def tearDown(self):
237 self._driver.quit() 283 self._driver.quit()
238 self._launcher.Kill() 284 self._launcher.Kill()
239 285
240 def testClickElementThatNeedsContainerScrolling(self): 286 def testClickElementThatNeedsContainerScrolling(self):
241 self._driver.get(self._launcher.GetURL() + '/test_page.html') 287 self._driver.get(self._launcher.GetURL() + '/test_page.html')
242 self._driver.find_element_by_name('hidden_scroll').click() 288 self._driver.find_element_by_name('hidden_scroll').click()
243 self.assertTrue(self._driver.execute_script('return window.success')) 289 self.assertTrue(self._driver.execute_script('return window.success'))
244 290
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 self.assertEquals('', url_parts[0]) 332 self.assertEquals('', url_parts[0])
287 self.assertEquals('wd', url_parts[1]) 333 self.assertEquals('wd', url_parts[1])
288 self.assertEquals('hub', url_parts[2]) 334 self.assertEquals('hub', url_parts[2])
289 self.assertEquals('session', url_parts[3]) 335 self.assertEquals('session', url_parts[3])
290 self.assertEquals(data['sessionId'], url_parts[4]) 336 self.assertEquals(data['sessionId'], url_parts[4])
291 337
292 338
293 if __name__ == '__main__': 339 if __name__ == '__main__':
294 unittest.main(module='chromedriver_tests', 340 unittest.main(module='chromedriver_tests',
295 testRunner=GTestTextTestRunner(verbosity=1)) 341 testRunner=GTestTextTestRunner(verbosity=1))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698