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")') |