diff options
author | chrishenry@google.com <chrishenry@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-08 07:00:57 +0000 |
---|---|---|
committer | chrishenry@google.com <chrishenry@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-08 07:00:57 +0000 |
commit | 64bb94fdffc91abd7ab5c2ba8a1054ff445f1467 (patch) | |
tree | 217cb492058f6448c50089488381a83232341391 | |
parent | cb81d40ce0799449a6001c38d14360d07712d8b3 (diff) | |
download | chromium_src-64bb94fdffc91abd7ab5c2ba8a1054ff445f1467.zip chromium_src-64bb94fdffc91abd7ab5c2ba8a1054ff445f1467.tar.gz chromium_src-64bb94fdffc91abd7ab5c2ba8a1054ff445f1467.tar.bz2 |
Add Wait* API to ActionRunner to wrap over WaitAction.
Add ability to wait for an element specified by a JS function.
The ActionRunner API's WaitForElement will not support lookup
by xpath, unlike WaitAction(). Page sets that uses this
feature now have their own _CreateXpathFunction instead,
that uses element_function variant of WaitForElement.
BUG=361809
Review URL: https://codereview.chromium.org/321563003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275738 0039d316-1c4b-4281-b951-d872f2087c98
48 files changed, 465 insertions, 779 deletions
diff --git a/content/test/gpu/gpu_tests/context_lost.py b/content/test/gpu/gpu_tests/context_lost.py index a491352..092747a 100644 --- a/content/test/gpu/gpu_tests/context_lost.py +++ b/content/test/gpu/gpu_tests/context_lost.py @@ -138,8 +138,8 @@ class WebGLContextLostFromGPUProcessExitPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - {'javascript': 'window.domAutomationController._loaded'})) + action_runner.WaitForJavaScriptCondition( + 'window.domAutomationController._loaded') class WebGLContextLostFromLoseContextExtensionPage(page.Page): @@ -155,8 +155,8 @@ class WebGLContextLostFromLoseContextExtensionPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - {'javascript': 'window.domAutomationController._finished'})) + action_runner.WaitForJavaScriptCondition( + 'window.domAutomationController._finished') class WebGLContextLostFromQuantityPage(page.Page): def __init__(self, page_set, base_dir): @@ -171,8 +171,8 @@ class WebGLContextLostFromQuantityPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - {'javascript': 'window.domAutomationController._loaded'})) + action_runner.WaitForJavaScriptCondition( + 'window.domAutomationController._loaded') class ContextLost(test_module.Test): enabled = True @@ -189,5 +189,3 @@ class ContextLost(test_module.Test): ps.AddPage(WebGLContextLostFromLoseContextExtensionPage(ps, ps.base_dir)) ps.AddPage(WebGLContextLostFromQuantityPage(ps, ps.base_dir)) return ps - - diff --git a/content/test/gpu/gpu_tests/maps.py b/content/test/gpu/gpu_tests/maps.py index 1d5bb6f..e88b2a5 100644 --- a/content/test/gpu/gpu_tests/maps.py +++ b/content/test/gpu/gpu_tests/maps.py @@ -84,8 +84,7 @@ class MapsPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'javascript': 'window.testDone', - 'timeout': 180})) + action_runner.WaitForJavaScriptCondition('window.testDone', timeout=180) class Maps(cloud_storage_test_base.TestBase): diff --git a/content/test/gpu/gpu_tests/screenshot_sync.py b/content/test/gpu/gpu_tests/screenshot_sync.py index 65021b0..d37904b 100644 --- a/content/test/gpu/gpu_tests/screenshot_sync.py +++ b/content/test/gpu/gpu_tests/screenshot_sync.py @@ -38,9 +38,8 @@ class ScreenshotSyncPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({ - 'javascript': 'window.__testComplete', - 'timeout': 120})) + action_runner.WaitForJavaScriptCondition( + 'window.__testComplete', timeout=120) class ScreenshotSyncProcess(test.Test): diff --git a/content/test/gpu/gpu_tests/webgl_conformance.py b/content/test/gpu/gpu_tests/webgl_conformance.py index f17e970..6da2cb1 100644 --- a/content/test/gpu/gpu_tests/webgl_conformance.py +++ b/content/test/gpu/gpu_tests/webgl_conformance.py @@ -89,8 +89,8 @@ class WebglConformancePage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - {'javascript': 'webglTestHarness._finished', 'timeout': 120})) + action_runner.WaitForJavaScriptCondition( + 'webglTestHarness._finished', timeout=120) class WebglConformance(test_module.Test): diff --git a/content/test/gpu/gpu_tests/webgl_robustness.py b/content/test/gpu/gpu_tests/webgl_robustness.py index 1ed3f03..153bd31 100644 --- a/content/test/gpu/gpu_tests/webgl_robustness.py +++ b/content/test/gpu/gpu_tests/webgl_robustness.py @@ -58,8 +58,7 @@ class WebglRobustnessPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction( - WaitAction({'javascript': 'webglTestHarness._finished'})) + action_runner.WaitForJavaScriptCondition('webglTestHarness._finished') class WebglRobustness(test.Test): test = WebglConformanceValidator diff --git a/content/test/gpu/page_sets/gpu_process_tests.py b/content/test/gpu/page_sets/gpu_process_tests.py index c9abeb0..ee3ee47 100644 --- a/content/test/gpu/page_sets/gpu_process_tests.py +++ b/content/test/gpu/page_sets/gpu_process_tests.py @@ -27,11 +27,8 @@ class FunctionalVideoPage(GpuProcessTestsPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'domAutomationController._finished', - 'timeout': 30 - })) + action_runner.WaitForJavaScriptCondition( + 'domAutomationController._finished', timeout=30) class GpuProcessTestsPageSet(page_set_module.PageSet): diff --git a/content/test/gpu/page_sets/gpu_rasterization_tests.py b/content/test/gpu/page_sets/gpu_rasterization_tests.py index e6a338f..4933302 100644 --- a/content/test/gpu/page_sets/gpu_rasterization_tests.py +++ b/content/test/gpu/page_sets/gpu_rasterization_tests.py @@ -69,11 +69,8 @@ class GpuRasterizationTestsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'domAutomationController._finished', - 'timeout': 30 - })) + action_runner.WaitForJavaScriptCondition( + 'domAutomationController._finished', timeout=30) class GpuRasterizationTestsPageSet(page_set_module.PageSet): diff --git a/content/test/gpu/page_sets/memory_tests.py b/content/test/gpu/page_sets/memory_tests.py index dee9c15..ef539c7 100644 --- a/content/test/gpu/page_sets/memory_tests.py +++ b/content/test/gpu/page_sets/memory_tests.py @@ -17,11 +17,8 @@ class MemoryTestsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'domAutomationController._finished', - 'timeout': 60 - })) + action_runner.WaitForJavaScriptCondition( + 'domAutomationController._finished', timeout=60) class MemoryTestsPageSet(page_set_module.PageSet): diff --git a/content/test/gpu/page_sets/pixel_tests.py b/content/test/gpu/page_sets/pixel_tests.py index 7d6e33f..720af30 100644 --- a/content/test/gpu/page_sets/pixel_tests.py +++ b/content/test/gpu/page_sets/pixel_tests.py @@ -17,11 +17,8 @@ class PixelTestsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'domAutomationController._finished', - 'timeout': 30 - })) + action_runner.WaitForJavaScriptCondition( + 'domAutomationController._finished', timeout=30) class PixelTestsPageSet(page_set_module.PageSet): diff --git a/tools/perf/benchmarks/maps.py b/tools/perf/benchmarks/maps.py index 7acda86..ef84b4b 100644 --- a/tools/perf/benchmarks/maps.py +++ b/tools/perf/benchmarks/maps.py @@ -36,7 +36,7 @@ class MapsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'javascript': 'window.testDone'})) + action_runner.WaitForJavaScriptCondition('window.testDone') @test.Disabled diff --git a/tools/perf/measurements/polymer_load.py b/tools/perf/measurements/polymer_load.py index a92576a..b8b52c2 100644 --- a/tools/perf/measurements/polymer_load.py +++ b/tools/perf/measurements/polymer_load.py @@ -2,7 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -from telemetry.page.actions.all_page_actions import WaitAction from telemetry.page import page from telemetry.page import page_measurement @@ -25,10 +24,7 @@ class PageForPolymerLoad(page.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': "window.__polymer_ready" - })) + action_runner.WaitForJavaScriptCondition('window.__polymer_ready') class PolymerLoadMeasurement(page_measurement.PageMeasurement): diff --git a/tools/perf/measurements/smoothness_unittest.py b/tools/perf/measurements/smoothness_unittest.py index 55cd39e..80fa42e 100644 --- a/tools/perf/measurements/smoothness_unittest.py +++ b/tools/perf/measurements/smoothness_unittest.py @@ -34,7 +34,7 @@ class AnimatedPage(page.Page): page_set=page_set, base_dir=page_set.base_dir) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class FakeTab(object): diff --git a/tools/perf/page_sets/browser_control.py b/tools/perf/page_sets/browser_control.py index 434c434..ce9f400 100644 --- a/tools/perf/page_sets/browser_control.py +++ b/tools/perf/page_sets/browser_control.py @@ -18,7 +18,7 @@ class BrowserControlPage(page_module.Page): self.user_agent_type = 'desktop' def RunEndure(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) class BrowserControlPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/browser_control_click.py b/tools/perf/page_sets/browser_control_click.py index acb4e9d..72c55a4 100644 --- a/tools/perf/page_sets/browser_control_click.py +++ b/tools/perf/page_sets/browser_control_click.py @@ -22,29 +22,19 @@ class BrowserControlClickPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'xpath': 'id("attach")', - 'condition': 'element' - })) + action_runner.WaitForElement('#attach') def RunEndure(self, action_runner): action_runner.RunAction(ClickElementAction( { 'xpath': 'id("attach")' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 0.5 - })) + action_runner.Wait(0.5) action_runner.RunAction(ClickElementAction( { 'xpath': 'id("detach")' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 0.5 - })) + action_runner.Wait(0.5) class BrowserControlClickPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/calendar_forward_backward.py b/tools/perf/page_sets/calendar_forward_backward.py index f4ca483..609b59c 100644 --- a/tools/perf/page_sets/calendar_forward_backward.py +++ b/tools/perf/page_sets/calendar_forward_backward.py @@ -23,15 +23,8 @@ class CalendarForwardBackwardPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.ExecuteJavaScript(''' (function() { var elem = document.createElement('meta'); @@ -45,106 +38,50 @@ class CalendarForwardBackwardPage(page_module.Page): { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') class CalendarForwardBackwardPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/gmail_alt_threadlist_conversation.py b/tools/perf/page_sets/gmail_alt_threadlist_conversation.py index 152ffc0..5e1c536 100644 --- a/tools/perf/page_sets/gmail_alt_threadlist_conversation.py +++ b/tools/perf/page_sets/gmail_alt_threadlist_conversation.py @@ -24,11 +24,9 @@ class GmailAltThreadlistConversationPage( def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'window.gmonkey !== undefined && document.getElementById("gb") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined && ' + 'document.getElementById("gb") !== null') def RunEndure(self, action_runner): action_runner.RunAction(ClickElementAction( @@ -36,13 +34,13 @@ class GmailAltThreadlistConversationPage( 'xpath': '//span[@email]', 'wait_until': {'condition': 'href_change'} })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) action_runner.RunAction(ClickElementAction( { 'wait_until': {'condition': 'href_change'}, 'selector': 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class GmailAltThreadlistConversationPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/gmail_alt_two_labels.py b/tools/perf/page_sets/gmail_alt_two_labels.py index 24365ed..c23ce1a 100644 --- a/tools/perf/page_sets/gmail_alt_two_labels.py +++ b/tools/perf/page_sets/gmail_alt_two_labels.py @@ -24,11 +24,9 @@ class GmailAltTwoLabelsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'window.gmonkey !== undefined && document.getElementById("gb") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined && ' + 'document.getElementById("gb") !== null') def RunEndure(self, action_runner): action_runner.RunAction(ClickElementAction( @@ -36,13 +34,13 @@ class GmailAltTwoLabelsPage(page_module.Page): 'wait_until': {'condition': 'href_change'}, 'selector': 'a[href="https://mail.google.com/mail/u/0/?shva=1#sent"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) action_runner.RunAction(ClickElementAction( { 'wait_until': {'condition': 'href_change'}, 'selector': 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class GmailAltTwoLabelsPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/gmail_compose_discard.py b/tools/perf/page_sets/gmail_compose_discard.py index 264878b..018dd9e 100644 --- a/tools/perf/page_sets/gmail_compose_discard.py +++ b/tools/perf/page_sets/gmail_compose_discard.py @@ -1,12 +1,21 @@ # Copyright 2014 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. + +import re + # pylint: disable=W0401,W0614 from telemetry.page.actions.all_page_actions import * from telemetry.page import page as page_module from telemetry.page import page_set as page_set_module +def _CreateXpathFunction(xpath): + return ('document.evaluate(%s, document, null, ' + 'XPathResult.FIRST_ORDERED_NODE_TYPE, null)' + '.singleNodeEvaluate') % re.escape(xpath) + + class GmailComposeDiscardPage(page_module.Page): """ Why: Compose and discard a new email """ @@ -21,12 +30,9 @@ class GmailComposeDiscardPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ( - 'window.gmonkey !== undefined &&' - 'document.getElementById("gb") !== null') - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined &&' + 'document.getElementById("gb") !== null') def ComposeClick(self, action_runner): action_runner.ExecuteJavaScript(''' @@ -41,23 +47,17 @@ class GmailComposeDiscardPage(page_module.Page): button.dispatchEvent(mouseupevent);''') def RunEndure(self, action_runner): - action_runner.RunAction(WaitAction( - { - 'xpath': '//div[text()="COMPOSE"]', - 'condition': 'element' - })) + action_runner.WaitForElement( + element_function=_CreateXpathFunction('//div[text()="COMPOSE"]')) self.ComposeClick(action_runner) - action_runner.RunAction(WaitAction({"seconds": 1})) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="oh"][data-tooltip="Discard draft"]' - })) + action_runner.Wait(1) + action_runner.WaitForElement( + 'div[class~="oh"][data-tooltip="Discard draft"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="oh"][data-tooltip="Discard draft"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class GmailComposeDiscardPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/gmail_expand_collapse_conversation.py b/tools/perf/page_sets/gmail_expand_collapse_conversation.py index 2bfd860..f223e65 100644 --- a/tools/perf/page_sets/gmail_expand_collapse_conversation.py +++ b/tools/perf/page_sets/gmail_expand_collapse_conversation.py @@ -25,48 +25,32 @@ class GmailExpandCollapseConversationPage( def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'img[alt="Expand all"]' - })) + action_runner.WaitForElement('img[alt="Expand all"]') action_runner.RunAction(ClickElementAction( { 'selector': 'img[alt="Expand all"]' })) - action_runner.RunAction(WaitAction({'seconds': 5})) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'img[alt="Collapse all"]' - })) + action_runner.Wait(5) + action_runner.WaitForElement('img[alt="Collapse all"]') action_runner.RunAction(ClickElementAction( { 'selector': 'img[alt="Collapse all"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) def RunEndure(self, action_runner): - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'img[alt="Expand all"]' - })) + action_runner.WaitForElement('img[alt="Expand all"]') action_runner.RunAction(ClickElementAction( { 'selector': 'img[alt="Expand all"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'img[alt="Collapse all"]' - })) + action_runner.Wait(1) + action_runner.WaitForElement('img[alt="Collapse all"]') action_runner.RunAction(ClickElementAction( { 'selector': 'img[alt="Collapse all"]' })) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class GmailExpandCollapseConversationPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/image_decoding_measurement.py b/tools/perf/page_sets/image_decoding_measurement.py index 7b8fe616..a0d1bca 100644 --- a/tools/perf/page_sets/image_decoding_measurement.py +++ b/tools/perf/page_sets/image_decoding_measurement.py @@ -17,10 +17,7 @@ class ImageDecodingMeasurementPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) action_runner.ExecuteJavaScript('runBenchmark();') - action_runner.RunAction(WaitAction( - { - 'javascript': 'isDone' - })) + action_runner.WaitForJavaScriptCondition('isDone') class ImageDecodingMeasurementPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/indexeddb_offline.py b/tools/perf/page_sets/indexeddb_offline.py index 58bfffe..aef9af9 100644 --- a/tools/perf/page_sets/indexeddb_offline.py +++ b/tools/perf/page_sets/indexeddb_offline.py @@ -1,12 +1,21 @@ # Copyright 2014 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. + +import re + # pylint: disable=W0401,W0614 from telemetry.page.actions.all_page_actions import * from telemetry.page import page as page_module from telemetry.page import page_set as page_set_module +def _CreateXpathFunction(xpath): + return ('document.evaluate(%s, document, null, ' + 'XPathResult.FIRST_ORDERED_NODE_TYPE, null)' + '.singleNodeEvaluate') % re.escape(xpath) + + class IndexeddbOfflinePage(page_module.Page): """ Why: Simulates user input while offline and sync while online. """ @@ -20,45 +29,24 @@ class IndexeddbOfflinePage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'initialized', - 'condition': 'element' - })) + action_runner.WaitForElement(text='initialized') def RunEndure(self, action_runner): - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'button[id="online"]:not(disabled)' - })) + action_runner.WaitForElement('button[id="online"]:not(disabled)') action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="online"]:not(disabled)' })) - action_runner.RunAction(WaitAction( - { - 'xpath': 'id("state")[text()="online"]', - 'condition': 'element' - })) - action_runner.RunAction(WaitAction( - { - "seconds": 1 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'button[id="offline"]:not(disabled)' - })) + action_runner.WaitForElement( + element_function=_CreateXpathFunction('id("state")[text()="online"]')) + action_runner.Wait(1) + action_runner.WaitForElement('button[id="offline"]:not(disabled)') action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="offline"]:not(disabled)' })) - action_runner.RunAction(WaitAction( - { - 'xpath': 'id("state")[text()="offline"]', - 'condition': 'element' - })) + action_runner.WaitForElement( + element_function=_CreateXpathFunction('id("state")[text()="offline"]')) class IndexeddbOfflinePageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/key_desktop_sites.py b/tools/perf/page_sets/key_desktop_sites.py index 9d78463..6376aa3 100644 --- a/tools/perf/page_sets/key_desktop_sites.py +++ b/tools/perf/page_sets/key_desktop_sites.py @@ -45,11 +45,9 @@ class GmailPage(KeyDesktopSitesPage): def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'window.gmonkey !== undefined && document.getElementById("gb") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined && ' + 'document.getElementById("gb") !== null') class GoogleCalendarPage(KeyDesktopSitesPage): @@ -81,11 +79,8 @@ class GoogleDrivePage(KeyDesktopSitesPage): def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'document.getElementsByClassName("doclistview-list").length' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("doclistview-list").length') class GoogleDocPage(KeyDesktopSitesPage): @@ -104,11 +99,8 @@ class GoogleDocPage(KeyDesktopSitesPage): def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'document.getElementsByClassName("kix-appview-editor").length' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("kix-appview-editor").length') class KeyDesktopSitesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/key_mobile_sites.py b/tools/perf/page_sets/key_mobile_sites.py index 4c2bee8..b2c9e91 100644 --- a/tools/perf/page_sets/key_mobile_sites.py +++ b/tools/perf/page_sets/key_mobile_sites.py @@ -47,15 +47,9 @@ class Page2(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'Next 35', - 'condition': 'element' - })) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.body.scrollHeight > 2560' - })) + action_runner.WaitForElement(text='Next 35') + action_runner.WaitForJavaScriptCondition( + 'document.body.scrollHeight > 2560') class Page3(KeyMobileSitesPage): @@ -82,14 +76,12 @@ class Page4(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ('window.Chorus !== undefined &&' - 'window.Chorus.Comments !== undefined &&' - 'window.Chorus.Comments.Json !== undefined &&' - '(window.Chorus.Comments.loaded ||' - ' window.Chorus.Comments.Json.load_comments())') - })) + action_runner.WaitForJavaScriptCondition( + 'window.Chorus !== undefined &&' + 'window.Chorus.Comments !== undefined &&' + 'window.Chorus.Comments.Json !== undefined &&' + '(window.Chorus.Comments.loaded ||' + ' window.Chorus.Comments.Json.load_comments())') class Page5(KeyMobileSitesPage): @@ -104,7 +96,7 @@ class Page5(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 8})) + action_runner.Wait(8) class Page6(KeyMobileSitesPage): @@ -132,11 +124,9 @@ class Page7(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ('document.getElementById("u_0_c") !== null &&' - 'document.body.scrollHeight > window.innerHeight') - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("u_0_c") !== null &&' + 'document.body.scrollHeight > window.innerHeight') class Page8(KeyMobileSitesPage): @@ -150,10 +140,8 @@ class Page8(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById("paginatortarget") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("paginatortarget") !== null') class Page9(KeyMobileSitesPage): @@ -194,11 +182,8 @@ class Page11(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'document.getElementById("profile-view-scroller") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("profile-view-scroller") !== null') class Page12(KeyMobileSitesPage): @@ -259,11 +244,7 @@ class Page16(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'Other Answers (1 - 20 of 149)', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Other Answers (1 - 20 of 149)') action_runner.RunAction(ClickElementAction( { 'text': 'Other Answers (1 - 20 of 149)' @@ -283,14 +264,10 @@ class Page17(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById("og_user_warning") !== null' - })) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById("og_user_warning") === null' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("og_user_warning") !== null') + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("og_user_warning") === null') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -359,17 +336,14 @@ class Page21(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 5})) - action_runner.RunAction(WaitAction( - { - 'javascript': ''' - document.getElementById("element-19") !== null && - document.getElementById("element-19").contentDocument - .getElementById("element-22") !== null && - document.getElementById("element-19").contentDocument - .getElementsByClassName( - "container list-item gc-list-item stretched").length !== 0''' - })) + action_runner.Wait(5) + action_runner.WaitForJavaScriptCondition(''' + document.getElementById("element-19") !== null && + document.getElementById("element-19").contentDocument + .getElementById("element-22") !== null && + document.getElementById("element-19").contentDocument + .getElementsByClassName( + "container list-item gc-list-item stretched").length !== 0''') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -396,10 +370,8 @@ class Page22(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById("element-5") !== null' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("element-5") !== null') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -436,11 +408,9 @@ class Page24(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ('typeof NEWS_telemetryReady !== "undefined" && ' - 'NEWS_telemetryReady == true') - })) + action_runner.WaitForJavaScriptCondition( + 'typeof NEWS_telemetryReady !== "undefined" && ' + 'NEWS_telemetryReady == true') class Page25(KeyMobileSitesPage): @@ -456,14 +426,9 @@ class Page25(KeyMobileSitesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById(":h") != null' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById(":h") != null') + action_runner.Wait(1) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( diff --git a/tools/perf/page_sets/key_silk_cases.py b/tools/perf/page_sets/key_silk_cases.py index a55bb4d..4b0920f 100644 --- a/tools/perf/page_sets/key_silk_cases.py +++ b/tools/perf/page_sets/key_silk_cases.py @@ -17,10 +17,7 @@ class KeySilkCasesPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction()) @@ -55,7 +52,7 @@ class Page2(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) class Page3(KeySilkCasesPage): @@ -94,7 +91,7 @@ class Page4(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) class Page5(KeySilkCasesPage): @@ -111,7 +108,7 @@ class Page5(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page6(KeySilkCasesPage): @@ -127,7 +124,7 @@ class Page6(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) class Page7(KeySilkCasesPage): @@ -144,7 +141,7 @@ class Page7(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) class Page8(KeySilkCasesPage): @@ -161,7 +158,7 @@ class Page8(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) class Page9(KeySilkCasesPage): @@ -179,7 +176,7 @@ class Page9(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page10(KeySilkCasesPage): @@ -197,7 +194,7 @@ class Page10(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page11(KeySilkCasesPage): @@ -215,7 +212,7 @@ class Page11(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page12(KeySilkCasesPage): @@ -228,7 +225,7 @@ class Page12(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 5})) + action_runner.Wait(5) class Page13(KeySilkCasesPage): @@ -243,7 +240,7 @@ class Page13(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page14(KeySilkCasesPage): @@ -258,7 +255,7 @@ class Page14(KeySilkCasesPage): self.gpu_raster = True def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 4})) + action_runner.Wait(4) class Page15(KeySilkCasesPage): @@ -271,7 +268,7 @@ class Page15(KeySilkCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 5})) + action_runner.Wait(5) class Page16(KeySilkCasesPage): @@ -283,7 +280,7 @@ class Page16(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) def SwipeToDismiss(self, action_runner): action_runner.RunAction(SwipeAction( @@ -299,9 +296,8 @@ class Page16(KeySilkCasesPage): 'speed': 5000 })) interaction = action_runner.BeginInteraction('Wait', is_smooth=True) - action_runner.RunAction(WaitAction({ - 'javascript': 'document.getElementsByClassName("message").length < 18' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("message").length < 18') interaction.End() def RunSmoothness(self, action_runner): @@ -317,7 +313,7 @@ class Page17(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) def RunSmoothness(self, action_runner): self.StressHideyBars(action_runner) @@ -361,10 +357,7 @@ class Page18(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) def RunSmoothness(self, action_runner): for _ in xrange(6): @@ -391,15 +384,14 @@ class Page19(KeySilkCasesPage): 'selector': '#menu-button' })) interaction = action_runner.BeginInteraction('Wait', is_smooth=True) - action_runner.RunAction(WaitAction({ - 'javascript': 'document.getElementById("nav-drawer").active' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("nav-drawer").active') interaction.End() def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) self.ToggleDrawer(action_runner) def RunSmoothness(self, action_runner): @@ -476,7 +468,7 @@ class Page21(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) self.ScrollKnowledgeCardToTop(action_runner) def RunSmoothness(self, action_runner): @@ -495,14 +487,9 @@ class Page22(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementsByClassName("fHa").length > 0' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("fHa").length > 0') + action_runner.Wait(2) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -535,7 +522,7 @@ class Page23(KeySilkCasesPage): 'function() { return window.innerHeight / 2; }' })) interaction = action_runner.BeginInteraction('Wait', is_smooth=True) - action_runner.RunAction(WaitAction({'seconds' : 1})) + action_runner.Wait(1) interaction.End() @@ -552,14 +539,9 @@ class Page24(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById(":h") != null' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById(":h") != null') + action_runner.Wait(1) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -580,14 +562,9 @@ class Page25(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementById(":h") != null' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById(":h") != null') + action_runner.Wait(1) def RunSmoothness(self, action_runner): action_runner.RunAction(SwipeAction( @@ -600,7 +577,7 @@ class Page25(KeySilkCasesPage): }''' })) interaction = action_runner.BeginInteraction('Wait', is_smooth=True) - action_runner.RunAction(WaitAction({'seconds' : 1})) + action_runner.Wait(1) interaction.End() @@ -615,14 +592,9 @@ class Page26(KeySilkCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.getElementsByClassName("tweet").length > 0' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("tweet").length > 0') + action_runner.Wait(1) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( diff --git a/tools/perf/page_sets/maps.py b/tools/perf/page_sets/maps.py index 654d775..863816c 100644 --- a/tools/perf/page_sets/maps.py +++ b/tools/perf/page_sets/maps.py @@ -18,10 +18,10 @@ class MapsPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds': 3})) + action_runner.Wait(3) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'javascript': 'window.testDone'})) + action_runner.WaitForJavaScriptCondition('window.testDone') class MapsPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/media_cns_cases.py b/tools/perf/page_sets/media_cns_cases.py index 9824f5a..2ba2451 100644 --- a/tools/perf/page_sets/media_cns_cases.py +++ b/tools/perf/page_sets/media_cns_cases.py @@ -30,10 +30,7 @@ class BasicPlayPage(page_module.Page): 'wait_for_ended': False })) # Wait for 1 second so that we know the play-head is at ~1s. - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.Wait(1) # Seek to before the play-head location. action_runner.RunAction(SeekAction( { diff --git a/tools/perf/page_sets/mobile_memory.py b/tools/perf/page_sets/mobile_memory.py index d04c659..24bb724 100644 --- a/tools/perf/page_sets/mobile_memory.py +++ b/tools/perf/page_sets/mobile_memory.py @@ -31,10 +31,7 @@ class GmailPage(MobileMemoryPage): def ReloadAndGc(self, action_runner): action_runner.RunAction(ReloadAction()) - action_runner.RunAction(WaitAction( - { - 'seconds': 15 - })) + action_runner.Wait(15) action_runner.RunAction(JsCollectGarbageAction()) def RunStressMemory(self, action_runner): @@ -53,26 +50,14 @@ class GoogleSearchPage(MobileMemoryPage): def RunStressMemory(self, action_runner): action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'seconds': 3 - })) + action_runner.Wait(3) action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'seconds': 3 - })) + action_runner.Wait(3) action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'seconds': 3 - })) + action_runner.Wait(3) action_runner.RunAction(ScrollAction()) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'document.getElementById("rg_s").childElementCount > 300' - })) + action_runner.WaitForJavaScriptCondition( + 'document.getElementById("rg_s").childElementCount > 300') class ScrollPage(MobileMemoryPage): diff --git a/tools/perf/page_sets/mse_cases.py b/tools/perf/page_sets/mse_cases.py index 6e2994e..a71620c 100644 --- a/tools/perf/page_sets/mse_cases.py +++ b/tools/perf/page_sets/mse_cases.py @@ -14,10 +14,7 @@ class MseCasesPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'window.__testDone == true' - })) + action_runner.WaitForJavaScriptCondition('window.__testDone == true') class MseCasesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/plus_alt_posts_photos.py b/tools/perf/page_sets/plus_alt_posts_photos.py index 2c18960..5aa53bab 100644 --- a/tools/perf/page_sets/plus_alt_posts_photos.py +++ b/tools/perf/page_sets/plus_alt_posts_photos.py @@ -23,44 +23,25 @@ class PlusAltPostsPhotosPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'Barack Obama', - 'condition': 'element' - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'span[guidedhelpid="posts_tab_profile"][class*="s6U8x"]' - })) + action_runner.WaitForElement(text='Barack Obama') + action_runner.WaitForElement( + 'span[guidedhelpid="posts_tab_profile"][class*="s6U8x"]') def RunEndure(self, action_runner): action_runner.RunAction(ClickElementAction( { 'selector': 'span[guidedhelpid="posts_tab_profile"]' })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'span[guidedhelpid="posts_tab_profile"][class*="s6U8x"]' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 5 - })) + action_runner.WaitForElement( + 'span[guidedhelpid="posts_tab_profile"][class*="s6U8x"]') + action_runner.Wait(5) action_runner.RunAction(ClickElementAction( { 'selector': 'span[guidedhelpid="photos_tab_profile"]' })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'span[guidedhelpid="photos_tab_profile"][class*="s6U8x"]' - })) - action_runner.RunAction(WaitAction( - { - 'seconds': 5 - })) + action_runner.WaitForElement( + 'span[guidedhelpid="photos_tab_profile"][class*="s6U8x"]') + action_runner.Wait(5) class PlusAltPostsPhotosPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/polymer.py b/tools/perf/page_sets/polymer.py index 84b57d3..5ec6808 100644 --- a/tools/perf/page_sets/polymer.py +++ b/tools/perf/page_sets/polymer.py @@ -21,8 +21,8 @@ class PolymerPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { 'javascript': "window.__polymer_ready" })) + action_runner.WaitForJavaScriptCondition( + 'window.__polymer_ready') class PolymerCalculatorPage(PolymerPage): @@ -94,10 +94,7 @@ class PolymerShadowPage(PolymerPage): def RunSmoothness(self, action_runner): action_runner.ExecuteJavaScript( "document.getElementById('fab').scrollIntoView()") - action_runner.RunAction(WaitAction( - { - 'seconds': 5 - })) + action_runner.Wait(5) self.AnimateShadow(action_runner, 'card') self.AnimateShadow(action_runner, 'fab') @@ -105,10 +102,7 @@ class PolymerShadowPage(PolymerPage): for i in range(1, 6): action_runner.ExecuteJavaScript( 'document.getElementById("{0}").z = {1}'.format(eid, i)) - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.Wait(1) class PolymerPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/service_worker.py b/tools/perf/page_sets/service_worker.py index 9d48f8d..d2b9b1e 100644 --- a/tools/perf/page_sets/service_worker.py +++ b/tools/perf/page_sets/service_worker.py @@ -13,7 +13,7 @@ archive_data_file_path = 'data/service_worker.json' class ServiceWorkerPage(page.Page): def RunNavigateSteps(self, action_runner): action_runner.RunAction(actions.NavigateAction()) - action_runner.RunAction(actions.WaitAction({'javascript': 'window.done'})) + action_runner.WaitForJavaScriptCondition('window.done') class ServiceWorkerPageSet(page_set.PageSet): diff --git a/tools/perf/page_sets/startup_pages.py b/tools/perf/page_sets/startup_pages.py index 6fe7305..0313c98 100644 --- a/tools/perf/page_sets/startup_pages.py +++ b/tools/perf/page_sets/startup_pages.py @@ -15,7 +15,7 @@ class StartedPage(page_module.Page): self.startup_url = startup_url def RunNavigateSteps(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 10})) + action_runner.Wait(10) class StartupPagesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/top_10.py b/tools/perf/page_sets/top_10.py index ed5f9b9..2ec8247 100644 --- a/tools/perf/page_sets/top_10.py +++ b/tools/perf/page_sets/top_10.py @@ -22,8 +22,7 @@ class Google(SimpleScrollPage): def RunNavigateSteps(self, action_runner): super(Google, self).RunNavigateSteps(action_runner) - action_runner.RunAction(WaitAction( - {'condition': 'element', 'text': 'Next'})) + action_runner.WaitForElement(text='Next') class Gmail(SimpleScrollPage): @@ -35,9 +34,9 @@ class Gmail(SimpleScrollPage): def RunNavigateSteps(self, action_runner): super(Gmail, self).RunNavigateSteps(action_runner) - action_runner.RunAction(WaitAction( - {'javascript' : 'window.gmonkey !== undefined &&' - 'document.getElementById("gb") !== null'})) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined &&' + 'document.getElementById("gb") !== null') class GoogleCalendar(SimpleScrollPage): @@ -55,9 +54,8 @@ class GoogleCalendar(SimpleScrollPage): elem.content="initial-scale=1"; document.body.appendChild(elem); })();''') - action_runner.RunAction(WaitAction({'seconds' : 2})) - action_runner.RunAction(WaitAction({ - 'condition' : 'element', 'selector' : 'div[class~="navForward"]'})) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') class Youtube(SimpleScrollPage): @@ -69,7 +67,7 @@ class Youtube(SimpleScrollPage): def RunNavigateSteps(self, action_runner): super(Youtube, self).RunNavigateSteps(action_runner) - action_runner.RunAction(WaitAction({'seconds' : 2})) + action_runner.Wait(2) class Facebook(SimpleScrollPage): @@ -82,8 +80,7 @@ class Facebook(SimpleScrollPage): def RunNavigateSteps(self, action_runner): super(Facebook, self).RunNavigateSteps(action_runner) - action_runner.RunAction(WaitAction( - {'condition': 'element', 'text': 'About'})) + action_runner.WaitForElement(text='About') class Top10PageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/top_25.py b/tools/perf/page_sets/top_25.py index a437eb0..417ce1d 100644 --- a/tools/perf/page_sets/top_25.py +++ b/tools/perf/page_sets/top_25.py @@ -36,11 +36,7 @@ class GoogleWebSearchPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text' : 'Next', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Next') def RunStressMemory(self, action_runner): action_runner.RunAction(ScrollAction()) @@ -51,11 +47,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Next', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Next') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -64,11 +56,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Next', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Next') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -77,11 +65,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Previous', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Previous') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -90,11 +74,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Previous', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Previous') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -103,11 +83,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Previous', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Previous') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -116,11 +92,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Images', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Images') action_runner.RunAction(ScrollAction()) action_runner.RunAction(ClickElementAction( { @@ -129,11 +101,7 @@ class GoogleWebSearchPage(Top25Page): 'condition': 'href_change' } })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Images', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Images') class GmailPage(Top25Page): @@ -149,11 +117,9 @@ class GmailPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ('window.gmonkey !== undefined &&' - 'document.getElementById("gb") !== null') - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined &&' + 'document.getElementById("gb") !== null') def RunStressMemory(self, action_runner): action_runner.RunAction(ClickElementAction( @@ -196,15 +162,8 @@ class GoogleCalendarPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.ExecuteJavaScript(''' (function() { var elem = document.createElement('meta'); @@ -212,116 +171,57 @@ class GoogleCalendarPage(Top25Page): elem.content='initial-scale=1'; document.body.appendChild(elem); })();''') - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.Wait(1) def RunStressMemory(self, action_runner): action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navForward"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navForward"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navForward"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') action_runner.RunAction(ClickElementAction( { 'selector': 'div[class~="navBack"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': 'div[class~="navBack"]' - })) + action_runner.Wait(2) + action_runner.WaitForElement('div[class~="navBack"]') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -360,15 +260,9 @@ class GoogleDocPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'javascript': - 'document.getElementsByClassName("kix-appview-editor").length' - })) + action_runner.Wait(2) + action_runner.WaitForJavaScriptCondition( + 'document.getElementsByClassName("kix-appview-editor").length') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -393,78 +287,39 @@ class GooglePlusPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text' : 'Home', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Home') def RunStressMemory(self, action_runner): action_runner.RunAction(ClickElementAction( { 'text' : 'Home' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Profile', - 'condition': 'element' - })) + action_runner.Wait(2) + action_runner.WaitForElement(text='Profile') action_runner.RunAction(ClickElementAction( { 'text' : 'Profile' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Explore', - 'condition': 'element' - })) + action_runner.Wait(2) + action_runner.WaitForElement(text='Explore') action_runner.RunAction(ClickElementAction( { 'text' : 'Explore' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Events', - 'condition': 'element' - })) + action_runner.Wait(2) + action_runner.WaitForElement(text='Events') action_runner.RunAction(ClickElementAction( { 'text' : 'Events' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Communities', - 'condition': 'element' - })) + action_runner.Wait(2) + action_runner.WaitForElement(text='Communities') action_runner.RunAction(ClickElementAction( { 'text' : 'Communities' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) - action_runner.RunAction(WaitAction( - { - 'text' : 'Home', - 'condition': 'element' - })) + action_runner.Wait(2) + action_runner.WaitForElement(text='Home') def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -486,10 +341,7 @@ class YoutubePage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) class BlogspotPage(Top25Page): @@ -505,11 +357,7 @@ class BlogspotPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text' : 'accessibility', - 'condition': 'element' - })) + action_runner.WaitForElement(text='accessibility') def RunStressMemory(self, action_runner): action_runner.RunAction(ClickElementAction({'text' : 'accessibility'})) @@ -538,13 +386,9 @@ class WordpressPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'condition': 'element', - 'selector': - # pylint: disable=C0301 - 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]' - })) + action_runner.WaitForElement( + # pylint: disable=C0301 + 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]') def RunStressMemory(self, action_runner): action_runner.RunAction(ScrollAction()) @@ -576,11 +420,7 @@ class FacebookPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text' : 'About', - 'condition': 'element' - })) + action_runner.WaitForElement(text='About') def RunStressMemory(self, action_runner): action_runner.RunAction(ClickElementAction({'text' : 'About'})) @@ -652,10 +492,7 @@ class TwitterPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) def RunSmoothness(self, action_runner): action_runner.RunAction(ScrollAction( @@ -721,10 +558,7 @@ class YahooGamesPage(Top25Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) class Top25PageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/top_desktop_sites_2012Q3.py b/tools/perf/page_sets/top_desktop_sites_2012Q3.py index 8aab0f1..a7e5bf5 100644 --- a/tools/perf/page_sets/top_desktop_sites_2012Q3.py +++ b/tools/perf/page_sets/top_desktop_sites_2012Q3.py @@ -17,7 +17,7 @@ class Top2012Q3Page(Page): def ReloadAndGc(self, action_runner): action_runner.RunAction(ReloadAction()) - action_runner.RunAction(WaitAction({"seconds": 1})) + action_runner.Wait(1) action_runner.RunAction(JsCollectGarbageAction()) def RunSmoothness(self, action_runner): diff --git a/tools/perf/page_sets/tough_animation_cases.py b/tools/perf/page_sets/tough_animation_cases.py index 0e5952a..ee8da89 100644 --- a/tools/perf/page_sets/tough_animation_cases.py +++ b/tools/perf/page_sets/tough_animation_cases.py @@ -17,10 +17,10 @@ class ToughAnimationCasesPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) if self._need_measurement_ready: - action_runner.RunAction(WaitAction({"javascript": "measurementReady"})) + action_runner.WaitForJavaScriptCondition('measurementReady') def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({"seconds": 10})) + action_runner.Wait(10) class ToughAnimationCasesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/tough_canvas_cases.py b/tools/perf/page_sets/tough_canvas_cases.py index b70b51e..0df8d49 100644 --- a/tools/perf/page_sets/tough_canvas_cases.py +++ b/tools/perf/page_sets/tough_canvas_cases.py @@ -15,16 +15,11 @@ class ToughCanvasCasesPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - "javascript": "document.readyState == 'complete'" - })) + action_runner.WaitForJavaScriptCondition( + "document.readyState == 'complete'") def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction( - { - "seconds": 5 - })) + action_runner.Wait(5) class MicrosofFirefliesPage(ToughCanvasCasesPage): diff --git a/tools/perf/page_sets/tough_compositor_cases.py b/tools/perf/page_sets/tough_compositor_cases.py index b86e317..ef26211 100644 --- a/tools/perf/page_sets/tough_compositor_cases.py +++ b/tools/perf/page_sets/tough_compositor_cases.py @@ -18,7 +18,7 @@ class ToughCompositorPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) # TODO(epenner): Remove this wait (http://crbug.com/366933) - action_runner.RunAction(WaitAction({'seconds': 5})) + action_runner.Wait(5) class ToughCompositorScrollPage(ToughCompositorPage): @@ -39,7 +39,7 @@ class ToughCompositorWaitPage(ToughCompositorPage): def RunSmoothness(self, action_runner): # We scroll back and forth a few times to reduce noise in the tests. - action_runner.RunAction(WaitAction({'seconds': 8})) + action_runner.Wait(8) class ToughCompositorCasesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/tough_energy_cases.py b/tools/perf/page_sets/tough_energy_cases.py index 38de3b6..e5b1486 100644 --- a/tools/perf/page_sets/tough_energy_cases.py +++ b/tools/perf/page_sets/tough_energy_cases.py @@ -27,12 +27,9 @@ class GmailPage(ToughEnergyCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': ( - 'window.gmonkey !== undefined &&' - 'document.getElementById("gb") !== null') - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined &&' + 'document.getElementById("gb") !== null') class ToughEnergyCasesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/tough_pinch_zoom_cases.py b/tools/perf/page_sets/tough_pinch_zoom_cases.py index a68dbd6..d658bffb 100644 --- a/tools/perf/page_sets/tough_pinch_zoom_cases.py +++ b/tools/perf/page_sets/tough_pinch_zoom_cases.py @@ -31,11 +31,7 @@ class GoogleSearchPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'Next', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Next') class GmailPage(ToughPinchZoomCasesPage): @@ -51,12 +47,9 @@ class GmailPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript' : ( - 'window.gmonkey !== undefined &&' - 'document.getElementById("gb") !== null') - })) + action_runner.WaitForJavaScriptCondition( + 'window.gmonkey !== undefined &&' + 'document.getElementById("gb") !== null') class GoogleCalendarPage(ToughPinchZoomCasesPage): @@ -72,7 +65,7 @@ class GoogleCalendarPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds':2})) + action_runner.Wait(2) def RunSmoothness(self, action_runner): action_runner.RunAction(PinchAction( @@ -107,11 +100,7 @@ class GooglePlusPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'Home', - 'condition': 'element' - })) + action_runner.WaitForElement(text='Home') def RunSmoothness(self, action_runner): action_runner.RunAction(PinchAction( @@ -136,7 +125,7 @@ class YoutubePage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds':2})) + action_runner.Wait(2) class BlogSpotPage(ToughPinchZoomCasesPage): @@ -152,11 +141,7 @@ class BlogSpotPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'accessibility', - 'condition': 'element' - })) + action_runner.WaitForElement(text='accessibility') class FacebookPage(ToughPinchZoomCasesPage): @@ -171,11 +156,7 @@ class FacebookPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'text': 'About', - 'condition': 'element' - })) + action_runner.WaitForElement(text='About') class LinkedinPage(ToughPinchZoomCasesPage): @@ -209,7 +190,7 @@ class TwitterPage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds':2})) + action_runner.Wait(2) class ESPNPage(ToughPinchZoomCasesPage): @@ -243,7 +224,7 @@ class YahooGamePage(ToughPinchZoomCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction({'seconds':2})) + action_runner.Wait(2) class YahooAnswersPage(ToughPinchZoomCasesPage): diff --git a/tools/perf/page_sets/tough_scheduling_cases.py b/tools/perf/page_sets/tough_scheduling_cases.py index 4cc5cb4..e044fc9 100644 --- a/tools/perf/page_sets/tough_scheduling_cases.py +++ b/tools/perf/page_sets/tough_scheduling_cases.py @@ -291,10 +291,7 @@ class Page19(ToughSchedulingCasesPage): page_set=page_set) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction( - { - "seconds": 3 - })) + action_runner.Wait(3) class Page20(ToughSchedulingCasesPage): @@ -448,4 +445,3 @@ class ToughSchedulingCasesPageSet(page_set_module.PageSet): slow_handler=True, bounce=True, page_set=self)) - diff --git a/tools/perf/page_sets/tough_video_cases.py b/tools/perf/page_sets/tough_video_cases.py index fc23647..1c5c6e6 100644 --- a/tools/perf/page_sets/tough_video_cases.py +++ b/tools/perf/page_sets/tough_video_cases.py @@ -46,10 +46,7 @@ class ToughVideoCasesPage(page_module.Page): 'wait_for_ended': False })) # Wait for 1 second so that we know the play-head is at ~1s. - action_runner.RunAction(WaitAction( - { - 'seconds': 1 - })) + action_runner.Wait(1) # Seek to before the play-head location. action_runner.RunAction(SeekAction( { @@ -495,4 +492,3 @@ class ToughVideoCasesPageSet(page_set_module.PageSet): self.AddPage(Page27(self)) self.AddPage(Page28(self)) self.AddPage(Page29(self)) - diff --git a/tools/perf/page_sets/tough_webgl_cases.py b/tools/perf/page_sets/tough_webgl_cases.py index 3263eb7..69ebb0e 100644 --- a/tools/perf/page_sets/tough_webgl_cases.py +++ b/tools/perf/page_sets/tough_webgl_cases.py @@ -23,14 +23,12 @@ class ToughWebglCasesPage(page_module.Page): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.readyState == "complete"' - })) - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.WaitForJavaScriptCondition( + 'document.readyState == "complete"') + action_runner.Wait(2) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 5})) + action_runner.Wait(5) class Page1(ToughWebglCasesPage): @@ -46,11 +44,9 @@ class Page1(ToughWebglCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.readyState == "complete"' - })) - action_runner.RunAction(WaitAction({'seconds': 15})) + action_runner.WaitForJavaScriptCondition( + 'document.readyState == "complete"') + action_runner.Wait(15) class Page2(ToughWebglCasesPage): @@ -62,11 +58,9 @@ class Page2(ToughWebglCasesPage): def RunNavigateSteps(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'javascript': 'document.readyState == "complete"' - })) - action_runner.RunAction(WaitAction({'seconds': 10})) + action_runner.WaitForJavaScriptCondition( + 'document.readyState == "complete"') + action_runner.Wait(10) class ToughWebglCasesPageSet(page_set_module.PageSet): diff --git a/tools/perf/page_sets/webrtc_cases.py b/tools/perf/page_sets/webrtc_cases.py index 54c8f48..24aaab3 100644 --- a/tools/perf/page_sets/webrtc_cases.py +++ b/tools/perf/page_sets/webrtc_cases.py @@ -24,10 +24,7 @@ class Page1(WebrtcCasesPage): def RunWebrtc(self, action_runner): action_runner.NavigateToPage(self) - action_runner.RunAction(WaitAction( - { - 'seconds': 10 - })) + action_runner.Wait(10) action_runner.ExecuteJavaScript('checkForErrors();') @@ -45,18 +42,12 @@ class Page2(WebrtcCasesPage): { 'selector': 'button[id="btn1"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="btn2"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 10 - })) + action_runner.Wait(10) action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="btn3"]' @@ -67,18 +58,12 @@ class Page2(WebrtcCasesPage): { 'selector': 'button[id="btn1"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 2 - })) + action_runner.Wait(2) action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="btn2"]' })) - action_runner.RunAction(WaitAction( - { - 'seconds': 10 - })) + action_runner.Wait(10) action_runner.RunAction(ClickElementAction( { 'selector': 'button[id="btn3"]' diff --git a/tools/telemetry/telemetry/page/actions/action_runner.py b/tools/telemetry/telemetry/page/actions/action_runner.py index 084b5ef..579e7335 100644 --- a/tools/telemetry/telemetry/page/actions/action_runner.py +++ b/tools/telemetry/telemetry/page/actions/action_runner.py @@ -2,8 +2,10 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +from telemetry.page.actions import page_action from telemetry.page.actions.javascript import JavaScriptAction from telemetry.page.actions.navigate import NavigateAction +from telemetry.page.actions.wait import WaitAction from telemetry.web_perf import timeline_interaction_record as tir_module @@ -76,6 +78,61 @@ class ActionRunner(object): """ self.RunAction(JavaScriptAction({'expression': js_expression})) + def Wait(self, seconds): + """Wait for the number of seconds specified. + + Args: + seconds: The number of seconds to wait. + """ + self.RunAction(WaitAction({'seconds': seconds})) + + def WaitForJavaScriptCondition(self, condition, timeout=60): + """Wait for a JavaScript condition to become true. + + Example: runner.WaitForJavaScriptCondition('window.foo == 10'); + + Args: + condition: The JavaScript condition (as string). + timeout: The timeout in seconds (default to 60). + """ + self.RunAction(WaitAction({'javascript': condition, 'timeout': timeout})) + + def WaitForElement(self, selector=None, text=None, element_function=None, + timeout=60): + """Wait for an element to appear in the document. Only one of selector, + text, or element_function must be specified. + + Args: + selector: A CSS selector describing the element. + text: The element must contains this exact text. + element_function: A JavaScript function (as string) that is used + to retrieve the element. For example: + 'function() { return foo.element; }'. + timeout: The timeout in seconds (default to 60). + """ + attr = {'condition': 'element', 'timeout': timeout} + _FillElementSelector( + attr, selector, text, element_function) + self.RunAction(WaitAction(attr)) + + +def _FillElementSelector(attr, selector=None, text=None, element_function=None): + count = 0 + if selector is not None: + count = count + 1 + attr['selector'] = selector + if text is not None: + count = count + 1 + attr['text'] = text + if element_function is not None: + count = count + 1 + attr['element_function'] = element_function + + if count != 1: + raise page_action.PageActionFailed( + 'Must specify 1 way to retrieve function, but %s was specified: %s' % + (len(attr), attr.keys())) + class Interaction(object): diff --git a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py index 882ba7c..55ada24 100644 --- a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py +++ b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py @@ -2,12 +2,15 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +from telemetry.core import util from telemetry.core.backends.chrome import tracing_backend from telemetry.core.timeline import model from telemetry.page.actions import action_runner as action_runner_module +from telemetry.page.actions import page_action # pylint: disable=W0401,W0614 from telemetry.page.actions.all_page_actions import * from telemetry.unittest import tab_test_case +from telemetry.unittest import tab_test_case from telemetry.web_perf import timeline_interaction_record as tir_module @@ -15,7 +18,7 @@ class ActionRunnerTest(tab_test_case.TabTestCase): def testIssuingInteractionRecord(self): action_runner = action_runner_module.ActionRunner(self._tab) self.Navigate('interaction_enabled_page.html') - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) self._browser.StartTracing(tracing_backend.DEFAULT_TRACE_CATEGORIES) interaction = action_runner.BeginInteraction( 'TestInteraction', is_smooth=True) @@ -53,3 +56,97 @@ class ActionRunnerTest(tab_test_case.TabTestCase): self.assertEquals( self._tab.EvaluateJavaScript('document.location.pathname;'), '/blank.html') + + def testWait(self): + action_runner = action_runner_module.ActionRunner(self._tab) + self.Navigate('blank.html') + + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() { window.testing = 101; }, 1000);') + action_runner.Wait(2) + self.assertEqual(101, self._tab.EvaluateJavaScript('window.testing')) + + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() { window.testing = 102; }, 2000);') + action_runner.Wait(3) + self.assertEqual(102, self._tab.EvaluateJavaScript('window.testing')) + + def testWaitForJavaScriptCondition(self): + action_runner = action_runner_module.ActionRunner(self._tab) + self.Navigate('blank.html') + + action_runner.ExecuteJavaScript('window.testing = 219;') + action_runner.WaitForJavaScriptCondition( + 'window.testing == 219', timeout=1) + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() { window.testing = 220; }, 1000);') + action_runner.WaitForJavaScriptCondition( + 'window.testing == 220', timeout=2) + self.assertEqual(220, self._tab.EvaluateJavaScript('window.testing')) + + def testWaitForElement(self): + action_runner = action_runner_module.ActionRunner(self._tab) + self.Navigate('blank.html') + + action_runner.ExecuteJavaScript( + '(function() {' + ' var el = document.createElement("div");' + ' el.id = "test1";' + ' el.textContent = "foo";' + ' document.body.appendChild(el);' + '})()') + action_runner.WaitForElement('#test1', timeout=1) + action_runner.WaitForElement(text='foo', timeout=1) + action_runner.WaitForElement( + element_function='document.getElementById("test1")') + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() {' + ' var el = document.createElement("div");' + ' el.id = "test2";' + ' document.body.appendChild(el);' + '}, 500)') + action_runner.WaitForElement('#test2', timeout=2) + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() {' + ' document.getElementById("test2").textContent = "bar";' + '}, 500)') + action_runner.WaitForElement(text='bar', timeout=2) + action_runner.ExecuteJavaScript( + 'window.setTimeout(function() {' + ' var el = document.createElement("div");' + ' el.id = "test3";' + ' document.body.appendChild(el);' + '}, 500)') + action_runner.WaitForElement( + element_function='document.getElementById("test3")') + + def testWaitForElementWithWrongText(self): + action_runner = action_runner_module.ActionRunner(self._tab) + self.Navigate('blank.html') + + action_runner.ExecuteJavaScript( + '(function() {' + ' var el = document.createElement("div");' + ' el.id = "test1";' + ' el.textContent = "foo";' + ' document.body.appendChild(el);' + '})()') + action_runner.WaitForElement('#test1', timeout=1) + def WaitForElement(): + action_runner.WaitForElement(text='oo', timeout=1) + self.assertRaises(util.TimeoutException, WaitForElement) + + def testWaitForElementWithConflictingParams(self): + action_runner = action_runner_module.ActionRunner(self._tab) + def WaitForElement1(): + action_runner.WaitForElement(selector='div', text='foo', timeout=1) + self.assertRaises(page_action.PageActionFailed, WaitForElement1) + + def WaitForElement2(): + action_runner.WaitForElement(selector='div', element_function='foo', + timeout=1) + self.assertRaises(page_action.PageActionFailed, WaitForElement2) + + def WaitForElement3(): + action_runner.WaitForElement(text='foo', element_function='', timeout=1) + self.assertRaises(page_action.PageActionFailed, WaitForElement3) diff --git a/tools/telemetry/telemetry/page/actions/wait.py b/tools/telemetry/telemetry/page/actions/wait.py index 6ff37d8..9de6b48 100644 --- a/tools/telemetry/telemetry/page/actions/wait.py +++ b/tools/telemetry/telemetry/page/actions/wait.py @@ -42,6 +42,9 @@ class WaitAction(page_action.PageAction): 'null)' '.singleNodeValue' % re.escape(self.xpath)) tab.WaitForJavaScriptExpression('%s != null' % code, self.timeout) + elif hasattr(self, 'element_function'): + tab.WaitForJavaScriptExpression( + '%s != null' % self.element_function, self.timeout) else: raise page_action.PageActionFailed( 'No element condition given to wait') diff --git a/tools/telemetry/telemetry/web_perf/timeline_based_measurement_unittest.py b/tools/telemetry/telemetry/web_perf/timeline_based_measurement_unittest.py index 99444fb..63385c8 100644 --- a/tools/telemetry/telemetry/web_perf/timeline_based_measurement_unittest.py +++ b/tools/telemetry/telemetry/web_perf/timeline_based_measurement_unittest.py @@ -108,10 +108,10 @@ class TestTimelinebasedMeasurementPage(page_module.Page): 'file://interaction_enabled_page.html', ps, base_dir) def RunSmoothness(self, action_runner): - action_runner.RunAction(WaitAction({'seconds': 2})) + action_runner.Wait(2) action_runner.RunAction(TapAction( {'selector': '#drawer', 'automatically_record_interaction': False})) - action_runner.RunAction(WaitAction({'seconds': 1})) + action_runner.Wait(1) class TimelineBasedMeasurementTest( |