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

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

Issue 5572001: Send screenshots back to the client for debugging (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fixed newlines 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 hashlib
14 import os
13 import platform 15 import platform
14 import os
15 import sys 16 import sys
16 import unittest 17 import unittest
18 import urllib
17 import urllib2 19 import urllib2
18 import urlparse 20 import urlparse
19 21
20 from chromedriver_launcher import ChromeDriverLauncher 22 from chromedriver_launcher import ChromeDriverLauncher
21 import chromedriver_paths 23 import chromedriver_paths
22 from gtest_text_test_runner import GTestTextTestRunner 24 from gtest_text_test_runner import GTestTextTestRunner
23 25
24 sys.path += [chromedriver_paths.SRC_THIRD_PARTY] 26 sys.path += [chromedriver_paths.SRC_THIRD_PARTY]
25 sys.path += [chromedriver_paths.PYTHON_BINDINGS] 27 sys.path += [chromedriver_paths.PYTHON_BINDINGS]
26 28
27 import simplejson as json 29 import simplejson as json
28 30
29 from selenium.webdriver.remote.webdriver import WebDriver 31 from selenium.webdriver.remote.webdriver import WebDriver
30 32
31 33
34 def DataDir():
35 """Returns the path to the data dir chrome/test/data."""
36 return os.path.normpath(
37 os.path.join(os.path.dirname(__file__), os.pardir, "data"))
38
39
40 def GetFileURLForPath(path):
41 """Get file:// url for the given path.
42 Also quotes the url using urllib.quote().
43 """
44 abs_path = os.path.abspath(path)
45 if sys.platform == 'win32':
46 # Don't quote the ':' in drive letter ( say, C: ) on win.
47 # Also, replace '\' with '/' as expected in a file:/// url.
48 drive, rest = os.path.splitdrive(abs_path)
49 quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/')))
50 return 'file:///' + quoted_path
51 else:
52 quoted_path = urllib.quote(abs_path)
53 return 'file://' + quoted_path
54
55
32 class Request(urllib2.Request): 56 class Request(urllib2.Request):
33 """Extends urllib2.Request to support all HTTP request types.""" 57 """Extends urllib2.Request to support all HTTP request types."""
34 58
35 def __init__(self, url, method=None, data=None): 59 def __init__(self, url, method=None, data=None):
36 """Initialise a new HTTP request. 60 """Initialise a new HTTP request.
37 61
38 Arguments: 62 Arguments:
39 url: The full URL to send the request to. 63 url: The full URL to send the request to.
40 method: The HTTP request method to use; defaults to 'GET'. 64 method: The HTTP request method to use; defaults to 'GET'.
41 data: The data to send with the request as a string. Defaults to 65 data: The data to send with the request as a string. Defaults to
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 self.assertNotEqual(cookie_dict, None) 163 self.assertNotEqual(cookie_dict, None)
140 self.assertEqual(cookie_dict["value"], "this is a test") 164 self.assertEqual(cookie_dict["value"], "this is a test")
141 165
142 def testDeleteCookie(self): 166 def testDeleteCookie(self):
143 self.testAddCookie(); 167 self.testAddCookie();
144 self._driver.delete_cookie("chromedriver_cookie_test") 168 self._driver.delete_cookie("chromedriver_cookie_test")
145 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") 169 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test")
146 self.assertEqual(cookie_dict, None) 170 self.assertEqual(cookie_dict, None)
147 171
148 172
173 class ScreenshotTest(unittest.TestCase):
174 """Tests to verify screenshot retrieval"""
175
176 REDBOX = "automation_proxy_snapshot/set_size.html"
177
178 def setUp(self):
179 self._launcher = ChromeDriverLauncher()
180 self._driver = WebDriver(self._launcher.GetURL(), {})
181
182 def tearDown(self):
183 self._driver.quit()
184 self._launcher.Kill()
185
186 def testScreenCaptureAgainstReference(self):
187 # Create a red square of 2000x2000 pixels.
188 url = GetFileURLForPath(os.path.join(DataDir(),
189 self.REDBOX))
190 url += "?2000,2000"
191 self._driver.get(url)
192 s = self._driver.get_screenshot_as_base64();
193 self._driver.get_screenshot_as_file("/tmp/foo.png")
194 h = hashlib.md5(s).hexdigest()
195 # Compare the PNG created to the reference hash.
196 self.assertEquals(h, '12c0ade27e3875da3d8866f52d2fa84f')
197
198
149 class SessionTest(unittest.TestCase): 199 class SessionTest(unittest.TestCase):
150 """Tests dealing with WebDriver sessions.""" 200 """Tests dealing with WebDriver sessions."""
151 201
152 def setUp(self): 202 def setUp(self):
153 self._launcher = ChromeDriverLauncher() 203 self._launcher = ChromeDriverLauncher()
154 204
155 def tearDown(self): 205 def tearDown(self):
156 self._launcher.Kill() 206 self._launcher.Kill()
157 207
158 def testCreatingSessionShouldRedirectToCorrectURL(self): 208 def testCreatingSessionShouldRedirectToCorrectURL(self):
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 self.assertEquals('', url_parts[0]) 336 self.assertEquals('', url_parts[0])
287 self.assertEquals('wd', url_parts[1]) 337 self.assertEquals('wd', url_parts[1])
288 self.assertEquals('hub', url_parts[2]) 338 self.assertEquals('hub', url_parts[2])
289 self.assertEquals('session', url_parts[3]) 339 self.assertEquals('session', url_parts[3])
290 self.assertEquals(data['sessionId'], url_parts[4]) 340 self.assertEquals(data['sessionId'], url_parts[4])
291 341
292 342
293 if __name__ == '__main__': 343 if __name__ == '__main__':
294 unittest.main(module='chromedriver_tests', 344 unittest.main(module='chromedriver_tests',
295 testRunner=GTestTextTestRunner(verbosity=1)) 345 testRunner=GTestTextTestRunner(verbosity=1))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698