Пример #1
0
  def testWaitForJavaScriptCondition(self):
    action_runner = action_runner_module.ActionRunner(self._tab,
                                                      skip_waits=True)
    self.Navigate('blank.html')

    action_runner.ExecuteJavaScript('window.testing = 219;')
    action_runner.WaitForJavaScriptCondition(
        'window.testing == 219', timeout_in_seconds=0.1)
    action_runner.ExecuteJavaScript(
        'window.setTimeout(function() { window.testing = 220; }, 50);')
    action_runner.WaitForJavaScriptCondition(
        'window.testing == 220', timeout_in_seconds=0.1)
    self.assertEqual(220, self._tab.EvaluateJavaScript('window.testing'))
Пример #2
0
  def testWaitForNavigate(self):
    self.Navigate('page_with_link.html')
    action_runner = action_runner_module.ActionRunner(self._tab,
                                                      skip_waits=True)
    action_runner.ClickElement('#clickme')
    action_runner.WaitForNavigate()

    self.assertTrue(self._tab.EvaluateJavaScript(
        'document.readyState == "interactive" || '
        'document.readyState == "complete"'))
    self.assertEqual(
        self._tab.EvaluateJavaScript('document.location.pathname;'),
        '/blank.html')
Пример #3
0
  def testWait(self):
    action_runner = action_runner_module.ActionRunner(self._tab)
    self.Navigate('blank.html')

    action_runner.ExecuteJavaScript(
        'window.setTimeout(function() { window.testing = 101; }, 50);')
    action_runner.Wait(0.1)
    self.assertEqual(101, self._tab.EvaluateJavaScript('window.testing'))

    action_runner.ExecuteJavaScript(
        'window.setTimeout(function() { window.testing = 102; }, 100);')
    action_runner.Wait(0.2)
    self.assertEqual(102, self._tab.EvaluateJavaScript('window.testing'))
Пример #4
0
 def Run(self, shared_state):
     current_tab = shared_state.current_tab
     # Collect garbage from previous run several times to make the results more
     # stable if needed.
     if self._collect_garbage_before_run:
         for _ in xrange(0, 5):
             current_tab.CollectGarbage()
     shared_state.page_test.WillNavigateToPage(self, current_tab)
     shared_state.page_test.RunNavigateSteps(self, current_tab)
     shared_state.page_test.DidNavigateToPage(self, current_tab)
     action_runner = action_runner_module.ActionRunner(
         current_tab, skip_waits=self.skip_waits)
     self.RunPageInteractions(action_runner)
Пример #5
0
 def testCreateInteraction(self):
   action_runner = action_runner_module.ActionRunner(self._tab)
   self.Navigate('interaction_enabled_page.html')
   action_runner.Wait(1)
   config = tracing_config.TracingConfig()
   config.chrome_trace_config.SetLowOverheadFilter()
   config.enable_chrome_trace = True
   self._browser.platform.tracing_controller.StartTracing(config)
   with action_runner.CreateInteraction('InteractionName', repeatable=True):
     pass
   trace_data = self._browser.platform.tracing_controller.StopTracing()
   markers = trace_processor.ExtractTimelineMarkers(trace_data)
   self.assertIn('Interaction.InteractionName/repeatable', markers)
    def testWaitForJavaScriptCondition_returnsValue(self):
        action_runner = action_runner_module.ActionRunner(self._tab,
                                                          skip_waits=True)
        self.Navigate('blank.html')

        action_runner.ExecuteJavaScript('window.testing = 0;')
        action_runner.WaitForJavaScriptCondition('window.testing == 0',
                                                 timeout=0.1)
        action_runner.ExecuteJavaScript(
            'window.setTimeout(function() { window.testing = 42; }, 50);')
        self.assertEqual(
            42,
            action_runner.WaitForJavaScriptCondition('window.testing',
                                                     timeout=10))
Пример #7
0
 def Run(self, shared_state):
     current_tab = shared_state.current_tab
     # Collect garbage from previous run several times to make the results more
     # stable if needed.
     for _ in xrange(0, 5):
         current_tab.CollectGarbage()
     action_runner = action_runner_module.ActionRunner(
         current_tab, skip_waits=self.skip_waits)
     with shared_state.interval_profiling_controller.SamplePeriod(
             'story_run', action_runner):
         shared_state.NavigateToPage(action_runner, self)
         with shared_state.interval_profiling_controller.SamplePeriod(
                 'interactions', action_runner):
             self.RunPageInteractions(action_runner)
Пример #8
0
 def Run(self, shared_state):
     current_tab = shared_state.current_tab
     # Collect garbage from previous run several times to make the results more
     # stable if needed.
     for _ in xrange(0, 5):
         current_tab.CollectGarbage()
     shared_state.page_test.WillNavigateToPage(self, current_tab)
     with shared_state.simpleperf_controller.SamplePeriod('navigation'):
         shared_state.page_test.RunNavigateSteps(self, current_tab)
     shared_state.page_test.DidNavigateToPage(self, current_tab)
     action_runner = action_runner_module.ActionRunner(
         current_tab, skip_waits=self.skip_waits)
     with shared_state.simpleperf_controller.SamplePeriod('interactions'):
         self.RunPageInteractions(action_runner)
Пример #9
0
  def testWaitForElementWithWrongText(self):
    action_runner = action_runner_module.ActionRunner(self._tab,
                                                      skip_waits=True)
    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_in_seconds=0.2)
    def WaitForElement():
      action_runner.WaitForElement(text='oo', timeout_in_seconds=0.2)
    self.assertRaises(exceptions.TimeoutException, WaitForElement)
Пример #10
0
 def Run(self, shared_state):
     current_tab = shared_state.current_tab
     # Collect garbage from previous run several times to make the results more
     # stable if needed.
     for _ in xrange(0, 5):
         current_tab.CollectGarbage()
     action_runner = action_runner_module.ActionRunner(
         current_tab, skip_waits=self.skip_waits)
     with shared_state.interval_profiling_controller.SamplePeriod(
             'story_run', action_runner):
         shared_state.NavigateToPage(action_runner, self)
         shared_state.RunPageInteractions(action_runner, self)
     # Navigate to about:blank in order to force previous page's metrics to
     # flush. Needed for many UMA metrics reported from PageLoadMetricsObserver.
     if self._perform_final_navigation:
         action_runner.Navigate('about:blank')
Пример #11
0
  def testOverviewMode(self):
    action_runner = action_runner_module.ActionRunner(
        self._tab, skip_waits=True)
    # TODO(chiniforooshan): Currently, there is no easy way to verify that the
    # browser has actually entered to/exited from the overview mode. For now, we
    # just make sure that the actions do not raise exception.
    #
    # One could at least try to capture screenshots before and after entering
    # overview mode and check if they are different, showing that something has
    # happened. But, for some reason taking CrOS screenshots is not properly
    # working.
    #
    # https://github.com/catapult-project/catapult/issues/4043

    action_runner.EnterOverviewMode()
    action_runner.ExitOverviewMode()
Пример #12
0
    def testScrollToElement(self):
        self.Navigate('page_with_swipeables.html')
        action_runner = action_runner_module.ActionRunner(self._tab,
                                                          skip_waits=True)

        off_screen_element = 'document.querySelectorAll("#off-screen")[0]'
        top_bottom_element = 'document.querySelector("#top-bottom")'
        viewport_comparator_js_template = '''
      (function(elem) {
        var rect = elem.getBoundingClientRect();

        if (rect.bottom < 0) {
          // The bottom of the element is above the viewport.
          return -1;
        }
        if (rect.top - window.innerHeight > 0) {
          // rect.top provides the pixel offset of the element from the
          // top of the page. Because that exceeds the viewport's height,
          // we know that the element is below the viewport.
          return 1;
        }
        return 0;
      })(
    '''
        viewport_comparator_off_screen_js = (viewport_comparator_js_template +
                                             '%s);' % off_screen_element)
        viewport_comparator_top_bottom_js = (viewport_comparator_js_template +
                                             '%s);' % top_bottom_element)

        self.assertEqual(
            action_runner.EvaluateJavaScript(
                viewport_comparator_off_screen_js), 1)
        action_runner.ScrollPageToElement(selector='#off-screen',
                                          speed_in_pixels_per_second=5000)
        self.assertEqual(
            action_runner.EvaluateJavaScript(
                viewport_comparator_off_screen_js), 0)

        self.assertEqual(
            action_runner.EvaluateJavaScript(
                viewport_comparator_top_bottom_js), -1)
        action_runner.ScrollPageToElement(selector='#top-bottom',
                                          speed_in_pixels_per_second=5000)
        self.assertEqual(
            action_runner.EvaluateJavaScript(
                viewport_comparator_top_bottom_js), 0)
  def testSmoothScrollBy(self):
    self.Navigate('page_with_swipeables.html')
    action_runner = action_runner_module.ActionRunner(
        self._tab, skip_waits=True)
    self.assertEquals(action_runner.EvaluateJavaScript('window.scrollY'), 0)
    self.assertEquals(action_runner.EvaluateJavaScript('window.scrollX'), 0)

    platform = action_runner.tab.browser.platform
    app_ui = action_runner.tab.browser.GetAppUi()
    view = app_ui.WaitForUiNode(resource_id='compositor_view_holder')
    scroll_start1 = 0.5 * (view.bounds.center + view.bounds.bottom_right)
    platform.android_action_runner.SmoothScrollBy(scroll_start1.x,
                                                  scroll_start1.y, 'down', 300)
    self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') > 0)

    scroll_start2 = 0.5 * (view.bounds.center + view.bounds.top_left)
    platform.android_action_runner.SmoothScrollBy(scroll_start2.x,
                                                  scroll_start2.y, 'up', 500)
    self.assertTrue(action_runner.EvaluateJavaScript('window.scrollY') == 0)
Пример #14
0
  def testTapElement(self):
    self.Navigate('page_with_clickables.html')
    action_runner = action_runner_module.ActionRunner(
        self._tab, skip_waits=True)

    action_runner.ExecuteJavaScript('valueSettableByTest = 1;')
    action_runner.TapElement('#test')
    self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest'))

    action_runner.ExecuteJavaScript('valueSettableByTest = 2;')
    action_runner.TapElement(text='Click/tap me')
    self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest'))

    action_runner.ExecuteJavaScript('valueSettableByTest = 3;')
    action_runner.TapElement(element_function='document.body.firstElementChild')
    self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest'))

    def WillFail():
      action_runner.TapElement('#notfound')

    self.assertRaises(exceptions.EvaluateException, WillFail)
  def testInputText(self):
    self.Navigate('blank.html')
    self._tab.ExecuteJavaScript(
        '(function() {'
        '  var elem = document.createElement("textarea");'
        '  document.body.appendChild(elem);'
        '  elem.focus();'
        '})();')

    action_runner = action_runner_module.ActionRunner(
        self._tab, skip_waits=True)
    platform = action_runner.tab.browser.platform
    platform.android_action_runner.InputText('Input spaces')
    platform.android_action_runner.InputText(', even multiple   spaces')

    # Check that the contents of the textarea is correct. It might take some
    # time until keystrokes are handled on Android.
    self._tab.WaitForJavaScriptCondition(
        ('document.querySelector("textarea").value === '
         '"Input spaces, even multiple   spaces"'),
        timeout=5)
Пример #16
0
  def testSwipe(self):
    if not page_action.IsGestureSourceTypeSupported(
        self._tab, 'touch'):
      return

    self.Navigate('page_with_swipeables.html')
    action_runner = action_runner_module.ActionRunner(self._tab,
                                                      skip_waits=True)

    action_runner.SwipeElement(
        selector='#left-right', direction='left', left_start_ratio=0.9)
    self.assertTrue(action_runner.EvaluateJavaScript(
        'document.querySelector("#left-right").scrollLeft') > 75)
    action_runner.SwipeElement(
        selector='#top-bottom', direction='up', top_start_ratio=0.9)
    self.assertTrue(action_runner.EvaluateJavaScript(
        'document.querySelector("#top-bottom").scrollTop') > 75)

    action_runner.SwipePage(direction='left', left_start_ratio=0.9)
    self.assertTrue(action_runner.EvaluateJavaScript(
        '(document.scrollingElement || document.body).scrollLeft') > 75)
Пример #17
0
    def VerifyIssuingInteractionRecords(self, **interaction_kwargs):
        action_runner = action_runner_module.ActionRunner(self._tab,
                                                          skip_waits=True)
        self.Navigate('interaction_enabled_page.html')
        action_runner.Wait(1)
        config = tracing_config.TracingConfig()
        config.chrome_trace_config.SetNoOverheadFilter()
        config.enable_chrome_trace = True
        self._browser.platform.tracing_controller.StartTracing(config)
        with action_runner.CreateInteraction('InteractionName',
                                             **interaction_kwargs):
            pass
        trace_data = self._browser.platform.tracing_controller.StopTracing()

        records = self.GetInteractionRecords(trace_data)
        self.assertEqual(
            1, len(records),
            'Failed to issue the interaction record on the tracing timeline.'
            ' Trace data:\n%s' % repr(trace_data._raw_data))
        self.assertEqual('InteractionName', records[0].label)
        for attribute_name in interaction_kwargs:
            self.assertTrue(getattr(records[0], attribute_name))
Пример #18
0
  def testWaitForElement(self):
    action_runner = action_runner_module.ActionRunner(
        self._tab, skip_waits=True)
    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')
    action_runner.WaitForElement(text='foo')
    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);'
        '}, 50)')
    action_runner.WaitForElement('#test2')
    action_runner.ExecuteJavaScript(
        'window.setTimeout(function() {'
        '  document.getElementById("test2").textContent = "bar";'
        '}, 50)')
    action_runner.WaitForElement(text='bar')
    action_runner.ExecuteJavaScript(
        'window.setTimeout(function() {'
        '  var el = document.createElement("div");'
        '  el.id = "test3";'
        '  document.body.appendChild(el);'
        '}, 50)')
    action_runner.WaitForElement(
        element_function='document.getElementById("test3")')
Пример #19
0
 def __init__(self, inspector_backend, tab_list_backend, browser):
   super(Tab, self).__init__(inspector_backend)
   self._tab_list_backend = tab_list_backend
   self._browser = browser
   self._action_runner = action_runner.ActionRunner(self)
Пример #20
0
 def testExecuteJavaScript(self):
   action_runner = action_runner_module.ActionRunner(
       self._tab, skip_waits=True)
   self.Navigate('blank.html')
   action_runner.ExecuteJavaScript('var testing = 42;')
   self.assertEqual(42, self._tab.EvaluateJavaScript('testing'))
Пример #21
0
 def setUp(self):
   super(ActionRunnerMeasureMemoryTest, self).setUp()
   self.action_runner = action_runner_module.ActionRunner(
       self._tab, skip_waits=True)
   self.Navigate('blank.html')
   self._REQUESTED_DUMP_COUNT = 3