| |
- __builtin__.object
-
- PageTest
- exceptions.Exception(exceptions.BaseException)
-
- MultiTabTestAppCrashError
- TestNotSupportedOnPlatformError
- telemetry.web_perf.story_test.Failure(exceptions.Exception)
-
- MeasurementFailure
class PageTest(__builtin__.object) |
|
A class styled on unittest.TestCase for creating page-specific tests.
Test should override ValidateAndMeasurePage to perform test
validation and page measurement as necessary.
class BodyChildElementMeasurement(PageTest):
def ValidateAndMeasurePage(self, page, tab, results):
body_child_count = tab.EvaluateJavaScript(
'document.body.children.length')
results.AddValue(scalar.ScalarValue(
page, 'body_children', 'count', body_child_count)) |
|
Methods defined here:
- CustomizeBrowserOptions(self, options)
- Override to add test-specific options to the BrowserOptions object
- DidNavigateToPage(self, page, tab)
- Override to do operations right after the page is navigated and after
all waiting for completion has occurred.
- DidRunPage(self, platform)
- Called after the test run method was run, even if it failed.
- DidStartBrowser(self, browser)
- Override to customize the browser right after it has launched.
- RestartBrowserBeforeEachPage(self)
- Should the browser be restarted for the page?
This returns true if the test needs to unconditionally restart the
browser for each page. It may be called before the browser is started.
- RunNavigateSteps(self, page, tab)
- Navigates the tab to the page URL attribute.
Runs the 'navigate_steps' page attribute as a compound action.
- SetOptions(self, options)
- Sets the BrowserFinderOptions instance to use.
- StopBrowserAfterPage(self, browser, page)
- Should the browser be stopped after the page is run?
This is called after a page is run to decide whether the browser needs to
be stopped to clean up its state. If it is stopped, then it will be
restarted to run the next page.
A test that overrides this can look at both the page and the browser to
decide whether it needs to stop the browser.
- TabForPage(self, page, browser)
- Override to select a different tab for the page. For instance, to
create a new tab for every page, return browser.tabs.New().
- ValidateAndMeasurePage(self, page, tab, results)
- Override to check test assertions and perform measurement.
When adding measurement results, call results.AddValue(...) for
each result. Raise an exception or add a failure.FailureValue on
failure. page_test.py also provides several base exception classes
to use.
Prefer metric value names that are in accordance with python
variable style. e.g., metric_name. The name 'url' must not be used.
Put together:
def ValidateAndMeasurePage(self, page, tab, results):
res = tab.EvaluateJavaScript('2+2')
if res != 4:
raise Exception('Oh, wow.')
results.AddValue(scalar.ScalarValue(
page, 'two_plus_two', 'count', res))
Args:
page: A telemetry.page.Page instance.
tab: A telemetry.core.Tab instance.
results: A telemetry.results.PageTestResults instance.
- WillNavigateToPage(self, page, tab)
- Override to do operations before the page is navigated, notably Telemetry
will already have performed the following operations on the browser before
calling this function:
* Ensure only one tab is open.
* Call WaitForDocumentReadyStateToComplete on the tab.
- WillStartBrowser(self, platform)
- Override to manipulate the browser environment before it launches.
- __init__(self, needs_browser_restart_after_each_page=False, clear_cache_before_each_run=False)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- clear_cache_before_each_run
- When set to True, the browser's disk and memory cache will be cleared
before each run.
- close_tabs_before_run
- When set to True, all tabs are closed before running the test for the
first time.
- is_multi_tab_test
- Returns True if the test opens multiple tabs.
If the test overrides TabForPage, it is deemed a multi-tab test.
Multi-tab tests do not retry after tab or browser crashes, whereas,
single-tab tests too. That is because the state of multi-tab tests
(e.g., how many tabs are open, etc.) is unknown after crashes.
|
|