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

Side by Side Diff: tests/selenium/selenium_utilities.py

Issue 164130: This CL adds client.toDataURL which gets the contents... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 4 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
« no previous file with comments | « tests/build.scons ('k') | utils/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright 2009, Google Inc. 2 # Copyright 2009, Google Inc.
3 # All rights reserved. 3 # All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 21 matching lines...) Expand all
32 """Utility scripts for selenium. 32 """Utility scripts for selenium.
33 33
34 A collection of utility scripts for selenium test cases to use. 34 A collection of utility scripts for selenium test cases to use.
35 """ 35 """
36 36
37 37
38 import os 38 import os
39 import re 39 import re
40 import time 40 import time
41 import unittest 41 import unittest
42 import base64
42 import gflags 43 import gflags
43 import selenium_constants 44 import selenium_constants
44 45
45 46
46 FLAGS = gflags.FLAGS 47 FLAGS = gflags.FLAGS
47 SUFFIXES = ["small", "medium", "large"] 48 SUFFIXES = ["small", "medium", "large"]
48 49
49 50
50 def IsValidTestType(test_type): 51 def IsValidTestType(test_type):
51 """Returns True if test_type is a "small", "medium" or "large".""" 52 """Returns True if test_type is a "small", "medium" or "large"."""
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 (selenium_constants.RESIZE_WIDTH, 168 (selenium_constants.RESIZE_WIDTH,
168 selenium_constants.RESIZE_HEIGHT)) 169 selenium_constants.RESIZE_HEIGHT))
169 170
170 # Execute screenshot capture code 171 # Execute screenshot capture code
171 172
172 # Replace all backslashes with forward slashes so it is parsed correctly 173 # Replace all backslashes with forward slashes so it is parsed correctly
173 # by Javascript 174 # by Javascript
174 full_path = filename.replace("\\", "/") 175 full_path = filename.replace("\\", "/")
175 176
176 # Attempt to take a screenshot of the display buffer 177 # Attempt to take a screenshot of the display buffer
177 eval_string = ("%s.saveScreen('%s')" % (client, full_path)) 178 eval_string = ("%s.toDataURL()" % client)
179
178 180
179 # Set Post render call back to take screenshot 181 # Set Post render call back to take screenshot
180 script = ["window.g_selenium_post_render = false;", 182 script = ["window.g_selenium_post_render = false;",
181 "window.g_selenium_save_screen_result = false;", 183 "window.g_selenium_save_screen_result = false;",
182 "var frameCount = 0;", 184 "var frameCount = 0;",
183 "%s.setPostRenderCallback(function() {" % client, 185 "%s.setPostRenderCallback(function() {" % client,
184 " ++frameCount;", 186 " ++frameCount;",
185 " if (frameCount >= 3) {", 187 " if (frameCount >= 3) {",
186 " %s.clearPostRenderCallback();" % client, 188 " %s.clearPostRenderCallback();" % client,
187 " window.g_selenium_save_screen_result = %s;" % eval_string, 189 " window.g_selenium_save_screen_result = %s;" % eval_string,
188 " window.g_selenium_post_render = true;", 190 " window.g_selenium_post_render = true;",
189 " } else {", 191 " } else {",
190 " %s.render()" % client, 192 " %s.render()" % client,
191 " }", 193 " }",
192 "})", 194 "})",
193 "%s.render()" % client] 195 "%s.render()" % client]
194 session.run_script("\n".join(script)) 196 session.run_script("\n".join(script))
195 # Wait for screenshot to be taken. 197 # Wait for screenshot to be taken.
196 session.wait_for_condition("window.g_selenium_post_render", 20000) 198 session.wait_for_condition("window.g_selenium_post_render", 20000)
197 199
198 # Get result 200 # Get result
199 success = session.get_eval("window.g_selenium_save_screen_result") 201 data_url = session.get_eval("window.g_selenium_save_screen_result")
200 202 expected_header = "data:image/png;base64,"
201 if success == u"true": 203 if data_url.startswith(expected_header):
204 png = base64.b64decode(data_url[len(expected_header):])
205 file = open(full_path + ".png", 'wb')
206 file.write(png)
207 file.close()
202 print "Saved screenshot %s." % full_path 208 print "Saved screenshot %s." % full_path
203 return True 209 return True
204 210
205 return False 211 return False
206 212
207 213
208 class SeleniumTestCase(unittest.TestCase): 214 class SeleniumTestCase(unittest.TestCase):
209 """Wrapper for TestCase for selenium.""" 215 """Wrapper for TestCase for selenium."""
210 216
211 def __init__(self, name, session, browser, test_type=None, sample_path=None, 217 def __init__(self, name, session, browser, test_type=None, sample_path=None,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 # if they are animated we need to stop the animation and set the clock 301 # if they are animated we need to stop the animation and set the clock
296 # to some time so we get a known state. 302 # to some time so we get a known state.
297 self.session.run_script("g_timeMult = 0") 303 self.session.run_script("g_timeMult = 0")
298 self.session.run_script("g_clock = " + clock) 304 self.session.run_script("g_clock = " + clock)
299 305
300 # take a screenshot. 306 # take a screenshot.
301 screenshot = self.sample_path.replace("/", "_") + str(screenshot_id) 307 screenshot = self.sample_path.replace("/", "_") + str(screenshot_id)
302 self.assertTrue(TakeScreenShot(self.session, self.browser, 308 self.assertTrue(TakeScreenShot(self.session, self.browser,
303 client, screenshot)) 309 client, screenshot))
304 screenshot_id += 1 310 screenshot_id += 1
OLDNEW
« no previous file with comments | « tests/build.scons ('k') | utils/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698