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

Unified Diff: tools/telemetry/telemetry/page/actions/action_runner_unittest.py

Issue 321563003: Add Wait* API to ActionRunner to wrap over WaitAction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/actions/action_runner_unittest.py
diff --git a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py
index 827609701ee97297a60b4b78b56e91c7f00bd336..58abaf81dd32daa4534db015aec299cbc9677168 100644
--- a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py
+++ b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py
@@ -8,6 +8,7 @@ from telemetry.page.actions import action_runner as action_runner_module
# 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
@@ -40,3 +41,66 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
self.Navigate('blank.html')
action_runner.ExecuteJavaScript('var testing = 42;')
self.assertEqual(42, self._tab.EvaluateJavaScript('testing'))
+
+ 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(contains_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(contains_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")')

Powered by Google App Engine
This is Rietveld 408576698