OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 import os | |
5 import time | |
6 | |
7 from telemetry.page import page_measurement | |
8 | |
9 | |
10 class Screenshot(page_measurement.PageMeasurement): | |
11 @classmethod | |
12 def AddCommandLineArgs(cls, parser): | |
13 parser.add_option('--png-outdir', | |
14 help='Output directory for the PNG files') | |
15 parser.add_option('--screenshot-delay', type='float', | |
16 default=3, | |
17 help='Wait for this many seconds before taking the ' | |
18 'screenshot') | |
19 parser.add_option('--screenshot-timeout', type='float', | |
20 default=5, | |
21 help='Timeout after this many seconds when attempting to ' | |
22 'take the screenshot') | |
23 | |
24 @classmethod | |
25 def ProcessCommandLineArgs(cls, parser, args): | |
26 if not args.png_outdir: | |
27 parser.error('Please specify --png-outdir') | |
28 cls._png_outdir = args.png_outdir | |
29 | |
30 def MeasurePage(self, page, tab, results): | |
31 tab.WaitForDocumentReadyStateToBeComplete() | |
32 time.sleep(self.options.screenshot_delay) | |
tonyg
2014/05/21 09:36:57
This seems like it'll be really flaky.
ernstm
2014/05/22 17:48:01
This measurement will always be flaky on non-stati
| |
33 screenshot = tab.Screenshot(self.options.screenshot_timeout) | |
34 | |
35 outpath = os.path.abspath( | |
36 os.path.join(self._png_outdir, page.file_safe_name)) + '.png' | |
37 | |
38 if os.path.exists(outpath): | |
39 previous_mtime = os.path.getmtime(outpath) | |
40 else: | |
41 previous_mtime = -1 | |
42 | |
43 screenshot.WritePngFile(outpath) | |
44 | |
45 saved_picture_count = 0 | |
46 if os.path.exists(outpath) and os.path.getmtime(outpath) > previous_mtime: | |
47 saved_picture_count = 1 | |
48 results.Add('saved_picture_count', 'count', saved_picture_count) | |
OLD | NEW |