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

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: update for ken's comments 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 55a7bd37ec7dcb538199b9e0a80b18170d727122..f4aa44d85a87363bf1434d5a25c09fa4afb493dc 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
@@ -83,6 +85,28 @@ class BasicTest(unittest.TestCase):
def tearDown(self):
self._launcher.Kill()
+ @staticmethod
+ 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"))
+
+ @staticmethod
+ 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
+
def testShouldReturn404WhenSentAnUnknownCommandURL(self):
request_url = self._launcher.GetURL() + '/foo'
try:
@@ -148,6 +172,32 @@ class CookieTest(unittest.TestCase):
self.assertEqual(cookie_dict, None)
+class ScreenshotTest(unittest.TestCase):
+ """Tests to verify screenshot retrieval"""
+
+ SEARCH = "http://www.google.com/webhp?hl=en"
+ NEWS = "http://www.google.com/news"
+ 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(BasicTest.DataDir(),
+ self.REDBOX))
+ url = url + "?2000,2000"
+ 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