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

Side by Side Diff: telemetry/telemetry/page/legacy_page_test.py

Issue 1921633003: [Telemetry] Rename page_test to legacy_page_test (Closed) Base URL: https://github.com/catapult-project/catapult@master
Patch Set: Add TODO Created 4 years, 8 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
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
6 6
7 from telemetry.core import exceptions 7 from telemetry.core import exceptions
8 from telemetry.internal.actions import action_runner as action_runner_module 8 from telemetry.internal.actions import action_runner as action_runner_module
9 9
10 # Export story_test.Failure to this page_test module 10 # Export story_test.Failure to this page_test module
11 from telemetry.web_perf.story_test import Failure 11 from telemetry.web_perf.story_test import Failure
12 12
13 13
14 class TestNotSupportedOnPlatformError(Exception): 14 class TestNotSupportedOnPlatformError(Exception):
15 """PageTest Exception raised when a required feature is unavailable. 15 """LegacyPageTest Exception raised when a required feature is unavailable.
16 16
17 The feature required to run the test could be part of the platform, 17 The feature required to run the test could be part of the platform,
18 hardware configuration, or browser. 18 hardware configuration, or browser.
19 """ 19 """
20 20
21 21
22 class MultiTabTestAppCrashError(Exception): 22 class MultiTabTestAppCrashError(Exception):
23 """PageTest Exception raised after browser or tab crash for multi-tab tests. 23 """Exception raised after browser or tab crash for multi-tab tests.
24 24
25 Used to abort the test rather than try to recover from an unknown state. 25 Used to abort the test rather than try to recover from an unknown state.
26 """ 26 """
27 27
28 28
29 class MeasurementFailure(Failure): 29 class MeasurementFailure(Failure):
30 """PageTest Exception raised when an undesired but designed-for problem.""" 30 """Exception raised when an undesired but designed-for problem."""
31 31
32 32
33 class PageTest(object): 33 class LegacyPageTest(object):
34 """A class styled on unittest.TestCase for creating page-specific tests. 34 """A class styled on unittest.TestCase for creating page-specific tests.
35 35
36 Note that this method of measuring browser's performance is obsolete and only
37 here for "historical" reason. For your performance measurement need, please
38 use TimelineBasedMeasurement instead: https://goo.gl/eMvikK
39
40 For correctness testing, please use
41 telemetry.testing.serially_executed_browser_test_case.SeriallyBrowserTestCase
42 instead. See examples in:
43 https://github.com/catapult-project/catapult/tree/master/telemetry/examples/br owser_tests
44
36 Test should override ValidateAndMeasurePage to perform test 45 Test should override ValidateAndMeasurePage to perform test
37 validation and page measurement as necessary. 46 validation and page measurement as necessary.
38 47
39 class BodyChildElementMeasurement(PageTest): 48 class BodyChildElementMeasurement(LegacyPageTest):
40 def ValidateAndMeasurePage(self, page, tab, results): 49 def ValidateAndMeasurePage(self, page, tab, results):
41 body_child_count = tab.EvaluateJavaScript( 50 body_child_count = tab.EvaluateJavaScript(
42 'document.body.children.length') 51 'document.body.children.length')
43 results.AddValue(scalar.ScalarValue( 52 results.AddValue(scalar.ScalarValue(
44 page, 'body_children', 'count', body_child_count)) 53 page, 'body_children', 'count', body_child_count))
45 """ 54 """
46 55
47 def __init__(self, 56 def __init__(self,
48 needs_browser_restart_after_each_page=False, 57 needs_browser_restart_after_each_page=False,
49 clear_cache_before_each_run=False): 58 clear_cache_before_each_run=False):
50 super(PageTest, self).__init__() 59 super(LegacyPageTest, self).__init__()
51 60
52 self.options = None 61 self.options = None
53 self._needs_browser_restart_after_each_page = ( 62 self._needs_browser_restart_after_each_page = (
54 needs_browser_restart_after_each_page) 63 needs_browser_restart_after_each_page)
55 self._clear_cache_before_each_run = clear_cache_before_each_run 64 self._clear_cache_before_each_run = clear_cache_before_each_run
56 self._close_tabs_before_run = True 65 self._close_tabs_before_run = True
57 66
58 @property 67 @property
59 def is_multi_tab_test(self): 68 def is_multi_tab_test(self):
60 """Returns True if the test opens multiple tabs. 69 """Returns True if the test opens multiple tabs.
61 70
62 If the test overrides TabForPage, it is deemed a multi-tab test. 71 If the test overrides TabForPage, it is deemed a multi-tab test.
63 Multi-tab tests do not retry after tab or browser crashes, whereas, 72 Multi-tab tests do not retry after tab or browser crashes, whereas,
64 single-tab tests too. That is because the state of multi-tab tests 73 single-tab tests too. That is because the state of multi-tab tests
65 (e.g., how many tabs are open, etc.) is unknown after crashes. 74 (e.g., how many tabs are open, etc.) is unknown after crashes.
66 """ 75 """
67 return self.TabForPage.__func__ is not PageTest.TabForPage.__func__ 76 return self.TabForPage.__func__ is not LegacyPageTest.TabForPage.__func__
68 77
69 @property 78 @property
70 def clear_cache_before_each_run(self): 79 def clear_cache_before_each_run(self):
71 """When set to True, the browser's disk and memory cache will be cleared 80 """When set to True, the browser's disk and memory cache will be cleared
72 before each run.""" 81 before each run."""
73 return self._clear_cache_before_each_run 82 return self._clear_cache_before_each_run
74 83
75 @property 84 @property
76 def close_tabs_before_run(self): 85 def close_tabs_before_run(self):
77 """When set to True, all tabs are closed before running the test for the 86 """When set to True, all tabs are closed before running the test for the
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 # See comment in shared_page_state.WillRunStory for why this waiting 152 # See comment in shared_page_state.WillRunStory for why this waiting
144 # is needed. 153 # is needed.
145 browser.tabs[0].WaitForDocumentReadyStateToBeComplete() 154 browser.tabs[0].WaitForDocumentReadyStateToBeComplete()
146 return browser.tabs[0] 155 return browser.tabs[0]
147 156
148 def ValidateAndMeasurePage(self, page, tab, results): 157 def ValidateAndMeasurePage(self, page, tab, results):
149 """Override to check test assertions and perform measurement. 158 """Override to check test assertions and perform measurement.
150 159
151 When adding measurement results, call results.AddValue(...) for 160 When adding measurement results, call results.AddValue(...) for
152 each result. Raise an exception or add a failure.FailureValue on 161 each result. Raise an exception or add a failure.FailureValue on
153 failure. page_test.py also provides several base exception classes 162 failure. legacy_page_test.py also provides several base exception classes
154 to use. 163 to use.
155 164
156 Prefer metric value names that are in accordance with python 165 Prefer metric value names that are in accordance with python
157 variable style. e.g., metric_name. The name 'url' must not be used. 166 variable style. e.g., metric_name. The name 'url' must not be used.
158 167
159 Put together: 168 Put together:
160 def ValidateAndMeasurePage(self, page, tab, results): 169 def ValidateAndMeasurePage(self, page, tab, results):
161 res = tab.EvaluateJavaScript('2+2') 170 res = tab.EvaluateJavaScript('2+2')
162 if res != 4: 171 if res != 4:
163 raise Exception('Oh, wow.') 172 raise Exception('Oh, wow.')
164 results.AddValue(scalar.ScalarValue( 173 results.AddValue(scalar.ScalarValue(
165 page, 'two_plus_two', 'count', res)) 174 page, 'two_plus_two', 'count', res))
166 175
167 Args: 176 Args:
168 page: A telemetry.page.Page instance. 177 page: A telemetry.page.Page instance.
169 tab: A telemetry.core.Tab instance. 178 tab: A telemetry.core.Tab instance.
170 results: A telemetry.results.PageTestResults instance. 179 results: A telemetry.results.PageTestResults instance.
171 """ 180 """
172 raise NotImplementedError 181 raise NotImplementedError
173 182
174 # Deprecated: do not use this hook. (crbug.com/470147) 183 # Deprecated: do not use this hook. (crbug.com/470147)
175 def RunNavigateSteps(self, page, tab): 184 def RunNavigateSteps(self, page, tab):
176 """Navigates the tab to the page URL attribute. 185 """Navigates the tab to the page URL attribute.
177 186
178 Runs the 'navigate_steps' page attribute as a compound action. 187 Runs the 'navigate_steps' page attribute as a compound action.
179 """ 188 """
180 action_runner = action_runner_module.ActionRunner( 189 action_runner = action_runner_module.ActionRunner(
181 tab, skip_waits=page.skip_waits) 190 tab, skip_waits=page.skip_waits)
182 page.RunNavigateSteps(action_runner) 191 page.RunNavigateSteps(action_runner)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/story_runner_unittest.py ('k') | telemetry/telemetry/page/page_run_end_to_end_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698