telemetry.page.page_measurement
index
telemetry/page/page_measurement.py

# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

 
Modules
       
telemetry.page.page_test

 
Classes
       
telemetry.page.page_test.Failure(exceptions.Exception)
MeasurementFailure
telemetry.page.page_test.PageTest(telemetry.core.command_line.ArgumentHandlerMixIn)
PageMeasurement

 
class MeasurementFailure(telemetry.page.page_test.Failure)
    Exception that can be thrown from MeasurePage to indicate an undesired but
designed-for problem.
 
 
Method resolution order:
MeasurementFailure
telemetry.page.page_test.Failure
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors inherited from telemetry.page.page_test.Failure:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class PageMeasurement(telemetry.page.page_test.PageTest)
    Glue code for running a measurement across a set of pages.
 
To use this, subclass from the measurement and override MeasurePage. For
example:
 
   class BodyChildElementMeasurement(PageMeasurement):
      def MeasurePage(self, page, tab, results):
         body_child_count = tab.EvaluateJavaScript(
             'document.body.children.length')
         results.Add('body_children', 'count', body_child_count)
 
   if __name__ == '__main__':
       page_measurement.Main(BodyChildElementMeasurement())
 
To add test-specific options:
 
   class BodyChildElementMeasurement(PageMeasurement):
      def AddCommandLineArgs(parser):
         parser.add_option('--element', action='store', default='body')
 
      def MeasurePage(self, page, tab, results):
         body_child_count = tab.EvaluateJavaScript(
            'document.querySelector('%s').children.length')
         results.Add('children', 'count', child_count)
 
 
Method resolution order:
PageMeasurement
telemetry.page.page_test.PageTest
telemetry.core.command_line.ArgumentHandlerMixIn
__builtin__.object

Methods defined here:
MeasurePage(self, page, tab, results)
Override to actually measure the page's performance.
 
page is a page_set.Page
tab is an instance of telemetry.core.Tab
 
Should call results.Add(name, units, value) for each result, or raise an
exception on failure. The name and units of each Add() call must be
the same across all iterations. The name 'url' must not be used.
 
Prefer field names that are in accordance with python variable style. E.g.
field_name.
 
Put together:
 
   def MeasurePage(self, page, tab, results):
     res = tab.EvaluateJavaScript('2+2')
     if res != 4:
       raise Exception('Oh, wow.')
     results.Add('two_plus_two', 'count', res)
__init__(self, action_name_to_run='', needs_browser_restart_after_each_page=False, discard_first_result=False, clear_cache_before_each_run=False)

Data descriptors defined here:
results_are_the_same_on_every_page
By default, measurements are assumed to output the same values for every
page. This allows incremental output, for example in CSV. If, however, the
measurement discovers what values it can report as it goes, and those values
may vary from page to page, you need to override this function and return
False. Output will not appear in this mode until the entire pageset has
run.

Methods inherited from telemetry.page.page_test.PageTest:
CanRunForPage(self, page)
Override to customize if the test can be ran for the given page.
CleanUpAfterPage(self, page, tab)
Called after the test run method was run, even if it failed.
CreateExpectations(self, page_set)
Override to make this test generate its own expectations instead of
any that may have been defined in the page set.
CreatePageSet(self, args, options)
Override to make this test generate its own page set instead of
allowing arbitrary page sets entered from the command-line.
CustomizeBrowserOptions(self, options)
Override to add test-specific options to the BrowserOptions object
CustomizeBrowserOptionsForPageSet(self, page_set, options)
Set options required for this page set.
 
These options will be used every time the browser is started while running
this page set. They may, however, be further modified by
CustomizeBrowserOptionsForSinglePage or by the profiler.
CustomizeBrowserOptionsForSinglePage(self, page, options)
Set options specific to the test and the given page.
 
This will be called with the current page when the browser is (re)started.
Changing options at this point only makes sense if the browser is being
restarted for each page. Note that if page has a startup_url, the browser
will always be restarted for each run.
DidNavigateToPage(self, page, tab)
Override to do operations right after the page is navigated and after
all waiting for completion has occurred.
DidRunAction(self, page, tab, action)
Override to do operations after running the action on the page.
DidRunActions(self, page, tab)
Override to do operations after running the actions on the page.
DidRunPageRepeats(self, page)
Override to do operations after each page is iterated over.
DidRunTest(self, browser, results)
Override to do operations after all page set(s) are completed.
 
This will occur before the browser is torn down.
DidStartBrowser(self, browser)
Override to customize the browser right after it has launched.
DidStartHTTPServer(self, tab)
Override to do operations after the HTTP server is started.
IsExiting(self)
RequestExit(self)
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.
Run(self, page, tab, results)
RunNavigateSteps(self, page, tab)
Navigates the tab to the page URL attribute.
 
Runs the 'navigate_steps' page attribute as a compound action.
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().
ValidatePageSet(self, page_set)
Override to examine the page set before the test run.  Useful for
example to validate that the pageset can be used with the test.
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.
WillRunAction(self, page, tab, action)
Override to do operations before running the action on the page.
WillRunActions(self, page, tab)
Override to do operations before running the actions on the page.
WillRunPageRepeats(self, page)
Override to do operations before each page is iterated over.
WillRunTest(self, options)
Override to do operations before the page set(s) are navigated.
WillStartBrowser(self, browser)
Override to manipulate the browser environment before it launches.

Data descriptors inherited from telemetry.page.page_test.PageTest:
action_name_to_run
attempts
Maximum number of times test will be attempted.
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.
discard_first_result
When set to True, the first run of the test is discarded.  This is
useful for cases where it's desirable to have some test resource cached so
the first run of the test can warm things up.
max_errors
Maximum number of errors allowed for the page set.
max_failures
Maximum number of failures allowed for the page set.

Class methods inherited from telemetry.core.command_line.ArgumentHandlerMixIn:
AddCommandLineArgs(cls, parser) from __builtin__.type
Override to accept custom command-line arguments.
ProcessCommandLineArgs(cls, parser, args) from __builtin__.type
Override to process command-line arguments.
 
We pass in parser so we can call parser.error().

Data descriptors inherited from telemetry.core.command_line.ArgumentHandlerMixIn:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)