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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/webdriver/chromedriver_tests.py
diff --git a/chrome/test/webdriver/chromedriver_tests.py b/chrome/test/webdriver/chromedriver_tests.py
index 02168e2cb958dc4b9943cbb0c02f346721ee6d69..0115382d7745541c0cf57214a068481956576a7c 100755
--- a/chrome/test/webdriver/chromedriver_tests.py
+++ b/chrome/test/webdriver/chromedriver_tests.py
@@ -10,10 +10,12 @@ If your test is testing a specific part of the WebDriver API, consider adding
it to the appropriate place in the WebDriver tree instead.
"""
-import platform
+import hashlib
import os
+import platform
import sys
import unittest
+import urllib
import urllib2
import urlparse
@@ -28,6 +30,26 @@ import simplejson as json
from selenium.webdriver.remote.webdriver import WebDriver
kkania 2011/03/22 21:08:56 one more newline here
Joe 2011/03/22 22:08:19 Done.
+def DataDir():
+ """Returns the path to the data dir chrome/test/data."""
+ return os.path.normpath(
+ os.path.join(os.path.dirname(__file__), os.pardir, "data"))
+
kkania 2011/03/22 21:08:56 one more newline here (to match python style guide
Joe 2011/03/22 22:08:19 Done.
+def GetFileURLForPath(path):
+ """Get file:// url for the given path.
+ Also quotes the url using urllib.quote().
+ """
+ abs_path = os.path.abspath(path)
+ if sys.platform == 'win32':
+ # Don't quote the ':' in drive letter ( say, C: ) on win.
+ # Also, replace '\' with '/' as expected in a file:/// url.
+ drive, rest = os.path.splitdrive(abs_path)
+ quoted_path = drive.upper() + urllib.quote((rest.replace('\\', '/')))
+ return 'file:///' + quoted_path
+ else:
+ quoted_path = urllib.quote(abs_path)
+ return 'file://' + quoted_path
+
class Request(urllib2.Request):
"""Extends urllib2.Request to support all HTTP request types."""
@@ -146,6 +168,30 @@ class CookieTest(unittest.TestCase):
self.assertEqual(cookie_dict, None)
+class ScreenshotTest(unittest.TestCase):
+ """Tests to verify screenshot retrieval"""
+
+ REDBOX = "automation_proxy_snapshot/set_size.html"
+
+ def setUp(self):
+ self._launcher = ChromeDriverLauncher()
+ self._driver = WebDriver(self._launcher.GetURL(), {})
+
+ def tearDown(self):
+ self._driver.quit()
+ self._launcher.Kill()
+
+ def testScreenCaptureAgainstReference(self):
+ # Create a red square of 2000x2000 pixels.
+ 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.
+ self.REDBOX))
+ url = url + "?2000,2000"
kkania 2011/03/22 21:08:56 url += "?2000,2000"
Joe 2011/03/22 22:08:19 Done.
+ self._driver.get(url)
+ s = self._driver.get_screenshot_as_base64();
+ h = hashlib.md5(s).hexdigest()
+ # Compare the PNG created to the reference hash.
+ self.assertTrue(h, '12c0ade27e3875da3d8866f52d2fa84f')
+
class SessionTest(unittest.TestCase):
"""Tests dealing with WebDriver sessions."""

Powered by Google App Engine
This is Rietveld 408576698