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

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: changed PageSnapshotTaker to use JSON interface 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
kkania 2011/03/22 21:08:56 one more newline here
Joe 2011/03/22 22:08:19 Done.
33 def DataDir():
34 """Returns the path to the data dir chrome/test/data."""
35 return os.path.normpath(
36 os.path.join(os.path.dirname(__file__), os.pardir, "data"))
37
kkania 2011/03/22 21:08:56 one more newline here (to match python style guide
Joe 2011/03/22 22:08:19 Done.
38 def GetFileURLForPath(path):
39 """Get file:// url for the given path.
40 Also quotes the url using urllib.quote().
41 """
42 abs_path = os.path.abspath(path)
43 if sys.platform == 'win32':
44 # Don't quote the ':' in drive letter ( say, C: ) on win.
45 # Also, replace '\' with '/' as expected in a file:/// url.
46 drive, rest = os.path.splitdrive(abs_path)
47 quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/')))
48 return 'file:///' + quoted_path
49 else:
50 quoted_path = urllib.quote(abs_path)
51 return 'file://' + quoted_path
52
31 53
32 class Request(urllib2.Request): 54 class Request(urllib2.Request):
33 """Extends urllib2.Request to support all HTTP request types.""" 55 """Extends urllib2.Request to support all HTTP request types."""
34 56
35 def __init__(self, url, method=None, data=None): 57 def __init__(self, url, method=None, data=None):
36 """Initialise a new HTTP request. 58 """Initialise a new HTTP request.
37 59
38 Arguments: 60 Arguments:
39 url: The full URL to send the request to. 61 url: The full URL to send the request to.
40 method: The HTTP request method to use; defaults to 'GET'. 62 method: The HTTP request method to use; defaults to 'GET'.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 self.assertNotEqual(cookie_dict, None) 161 self.assertNotEqual(cookie_dict, None)
140 self.assertEqual(cookie_dict["value"], "this is a test") 162 self.assertEqual(cookie_dict["value"], "this is a test")
141 163
142 def testDeleteCookie(self): 164 def testDeleteCookie(self):
143 self.testAddCookie(); 165 self.testAddCookie();
144 self._driver.delete_cookie("chromedriver_cookie_test") 166 self._driver.delete_cookie("chromedriver_cookie_test")
145 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") 167 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test")
146 self.assertEqual(cookie_dict, None) 168 self.assertEqual(cookie_dict, None)
147 169
148 170
171 class ScreenshotTest(unittest.TestCase):
172 """Tests to verify screenshot retrieval"""
173
174 REDBOX = "automation_proxy_snapshot/set_size.html"
175
176 def setUp(self):
177 self._launcher = ChromeDriverLauncher()
178 self._driver = WebDriver(self._launcher.GetURL(), {})
179
180 def tearDown(self):
181 self._driver.quit()
182 self._launcher.Kill()
183
184 def testScreenCaptureAgainstReference(self):
185 # Create a red square of 2000x2000 pixels.
186 url = BasicTest.GetFileURLForPath(os.path.join(DataDir(),
kkania 2011/03/22 21:08:56 try running this test from scratch. You at least
Joe 2011/03/22 22:08:19 Done.
187 self.REDBOX))
188 url = url + "?2000,2000"
kkania 2011/03/22 21:08:56 url += "?2000,2000"
Joe 2011/03/22 22:08:19 Done.
189 self._driver.get(url)
190 s = self._driver.get_screenshot_as_base64();
191 h = hashlib.md5(s).hexdigest()
192 # Compare the PNG created to the reference hash.
193 self.assertTrue(h, '12c0ade27e3875da3d8866f52d2fa84f')
194
149 class SessionTest(unittest.TestCase): 195 class SessionTest(unittest.TestCase):
150 """Tests dealing with WebDriver sessions.""" 196 """Tests dealing with WebDriver sessions."""
151 197
152 def setUp(self): 198 def setUp(self):
153 self._launcher = ChromeDriverLauncher() 199 self._launcher = ChromeDriverLauncher()
154 200
155 def tearDown(self): 201 def tearDown(self):
156 self._launcher.Kill() 202 self._launcher.Kill()
157 203
158 def testCreatingSessionShouldRedirectToCorrectURL(self): 204 def testCreatingSessionShouldRedirectToCorrectURL(self):
(...skipping 127 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