| 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 882ba7c0fb30d23562ccd44249244cab39c75aea..55ada24a86a2fdc9084b956f7318beccb72fd784 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)
|
|
|