コード例 #1
0
    def RunAction(self, tab):
        if (self._selector is None and self._text is None
                and self._element_function is None):
            self._element_function = 'document.body'

        gesture_source_type = page_action.GetGestureSourceTypeFromOptions(tab)
        if self._use_touch:
            gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'

        code = '''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__scrollAction.start({
            element: element,
            left_start_ratio: %s,
            top_start_ratio: %s,
            direction: '%s',
            speed: %s,
            gesture_source_type: %s
          });
        }''' % (self._left_start_ratio, self._top_start_ratio, self._direction,
                self._speed, gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60)
コード例 #2
0
ファイル: scroll.py プロジェクト: kiara07/catapult
    def RunAction(self, tab):
        if (self._selector is None and self._text is None
                and self._element_function is None):
            self._element_function = '(document.scrollingElement || document.body)'

        gesture_source_type = self._synthetic_gesture_source
        if self._use_touch:
            gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'

        # TODO(catapult:#3028): Fix interpolation of JavaScript values.
        code = '''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__scrollAction.start({
            element: element,
            left_start_ratio: %s,
            top_start_ratio: %s,
            direction: '%s',
            speed: %s,
            gesture_source_type: %s
          });
        }''' % (self._left_start_ratio, self._top_start_ratio, self._direction,
                self._speed, gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60)
コード例 #3
0
    def RunAction(self, tab):
        if not self.HasElementSelector():
            self.element_function = 'document.body'
        gesture_source_type = page_action.GetGestureSourceTypeFromOptions(tab)

        tap_cmd = ('''
        window.__tapAction.start({
          element: element,
          left_position_percentage: %s,
          top_position_percentage: %s,
          duration_ms: %s,
          gesture_source_type: %s
        });''' % (self.left_position_percentage, self.top_position_percentage,
                  self.duration_ms, gesture_source_type))
        code = '''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          %s;
        }''' % tap_cmd

        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self.selector,
            text=self.text,
            element_function=self.element_function)
        tab.WaitForJavaScriptExpression('window.__tapActionDone', 60)
コード例 #4
0
ファイル: swipe.py プロジェクト: subhanshuja/ofa
 def RunAction(self, tab):
   if (self._selector is None and self._text is None and
       self._element_function is None):
     self._element_function = '(document.scrollingElement || document.body)'
   code = '''
       function(element, info) {
         if (!element) {
           throw Error('Cannot find element: ' + info);
         }
         window.__swipeAction.start({
           element: element,
           left_start_ratio: %s,
           top_start_ratio: %s,
           direction: '%s',
           distance: %s,
           speed: %s
         });
       }''' % (self._left_start_ratio,
               self._top_start_ratio,
               self._direction,
               self._distance,
               self._speed)
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self._selector, text=self._text,
       element_function=self._element_function)
   tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60)
コード例 #5
0
ファイル: scroll.py プロジェクト: wanghui0720/catapult
    def RunAction(self, tab):
        if (self._selector is None and self._text is None
                and self._element_function is None):
            self._element_function = '(document.scrollingElement || document.body)'

        gesture_source_type = self._synthetic_gesture_source
        if self._use_touch:
            gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'

        code = js_template.Render('''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__scrollAction.start({
            element: element,
            left_start_ratio: {{ left_start_ratio }},
            top_start_ratio: {{ top_start_ratio }},
            direction: {{ direction }},
            speed: {{ speed }},
            gesture_source_type: {{ @gesture_source_type }}
          });
        }''',
                                  left_start_ratio=self._left_start_ratio,
                                  top_start_ratio=self._top_start_ratio,
                                  direction=self._direction,
                                  speed=self._speed,
                                  gesture_source_type=gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptCondition('window.__scrollActionDone', timeout=60)
コード例 #6
0
 def RunAction(self, tab):
     # TODO(catapult:#3028): Fix interpolation of JavaScript values.
     code = '''
     function(element, info) {
       if (!element) {
         throw Error('Cannot find element: ' + info);
       }
       window.__scrollBounceAction.start({
         element: element,
         left_start_ratio: %s,
         top_start_ratio: %s,
         direction: '%s',
         distance: %s,
         overscroll: %s,
         repeat_count: %s,
         speed: %s
       });
     }''' % (self._left_start_ratio, self._top_start_ratio, self._direction,
             self._distance, self._overscroll, self._repeat_count,
             self._speed)
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self._selector,
         text=self._text,
         element_function=self._element_function)
     tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60)
コード例 #7
0
ファイル: tap.py プロジェクト: subhanshuja/ofa
  def RunAction(self, tab):
    if not self.HasElementSelector():
      self.element_function = 'document.body'

    tap_cmd = ('''
        window.__tapAction.start({
          element: element,
          left_position_percentage: %s,
          top_position_percentage: %s,
          duration_ms: %s,
          gesture_source_type: %s
        });'''
          % (self.left_position_percentage,
             self.top_position_percentage,
             self.duration_ms,
             self._synthetic_gesture_source))
    code = '''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          %s;
        }''' % tap_cmd

    page_action.EvaluateCallbackWithElement(
        tab, code, selector=self.selector, text=self.text,
        element_function=self.element_function)
    # The second disjunct handles the case where the tap action leads to an
    # immediate navigation (in which case the expression below might already be
    # evaluated on the new page).
    tab.WaitForJavaScriptExpression(
        'window.__tapActionDone || window.__tapAction === undefined', 60)
コード例 #8
0
    def RunAction(self, tab):
        if (self._selector is None and self._text is None
                and self._element_function is None):
            self._element_function = 'document.body'

        gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
        if (page_action.IsGestureSourceTypeSupported(tab, 'mouse')
                and not self._use_touch):
            gesture_source_type = 'chrome.gpuBenchmarking.MOUSE_INPUT'

        code = '''
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__dragAction.start({
            element: element,
            left_start_ratio: %s,
            top_start_ratio: %s,
            left_end_ratio: %s,
            top_end_ratio: %s,
            speed: %s,
            gesture_source_type: %s
          });
        }''' % (self._left_start_ratio, self._top_start_ratio,
                self._left_end_ratio, self._top_end_ratio, self._speed,
                gesture_source_type)
        page_action.EvaluateCallbackWithElement(
            tab,
            code,
            selector=self._selector,
            text=self._text,
            element_function=self._element_function)
        tab.WaitForJavaScriptExpression('window.__dragActionDone', 60)
コード例 #9
0
ファイル: swipe.py プロジェクト: isabella232/catapult-csm
 def RunAction(self, tab):
     if (self._selector is None and self._text is None
             and self._element_function is None):
         self._element_function = '(document.scrollingElement || document.body)'
     code = js_template.Render("""
     function(element, info) {
       if (!element) {
         throw Error('Cannot find element: ' + info);
       }
       window.__swipeAction.start({
         element: element,
         left_start_ratio: {{ left_start_ratio }},
         top_start_ratio: {{ top_start_ratio }},
         direction: {{ direction }},
         distance: {{ distance }},
         speed: {{ speed }}
       });
     }""",
                               left_start_ratio=self._left_start_ratio,
                               top_start_ratio=self._top_start_ratio,
                               direction=self._direction,
                               distance=self._distance,
                               speed=self._speed)
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self._selector,
         text=self._text,
         element_function=self._element_function)
     tab.WaitForJavaScriptCondition('window.__swipeActionDone', timeout=60)
コード例 #10
0
ファイル: tap.py プロジェクト: xNUTs/catapult
  def RunAction(self, tab):
    if not self.HasElementSelector():
      self.element_function = 'document.body'

    code = js_template.Render('''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          window.__tapAction.start({
            element: element,
            left_position_percentage: {{ left_position_percentage }},
            top_position_percentage: {{ top_position_percentage }},
            duration_ms: {{ duration_ms }},
            gesture_source_type: {{ @gesture_source_type }}
          });
        }''',
        left_position_percentage=self.left_position_percentage,
        top_position_percentage=self.top_position_percentage,
        duration_ms=self.duration_ms,
        gesture_source_type=self._synthetic_gesture_source)

    page_action.EvaluateCallbackWithElement(
        tab, code, selector=self.selector, text=self.text,
        element_function=self.element_function)
    # The second disjunct handles the case where the tap action leads to an
    # immediate navigation (in which case the expression below might already be
    # evaluated on the new page).
    tab.WaitForJavaScriptCondition2(
        'window.__tapActionDone || window.__tapAction === undefined',
        timeout=60)
コード例 #11
0
ファイル: pinch.py プロジェクト: ycy2012/wechatgame
 def RunAction(self, tab):
     scale_factor = (self._scale_factor if self._scale_factor else
                     PinchAction._GetDefaultScaleFactorForPage(tab))
     code = js_template.Render('''
     function(element, info) {
       if (!element) {
         throw Error('Cannot find element: ' + info);
       }
       window.__pinchAction.start({
         element: element,
         left_anchor_ratio: {{ left_anchor_ratio }},
         top_anchor_ratio: {{ top_anchor_ratio }},
         scale_factor: {{ scale_factor }},
         speed: {{ speed }}
       });
     }''',
                               left_anchor_ratio=self._left_anchor_ratio,
                               top_anchor_ratio=self._top_anchor_ratio,
                               scale_factor=scale_factor,
                               speed=self._speed)
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self._selector,
         text=self._text,
         element_function=self._element_function)
     tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
コード例 #12
0
 def RunAction(self, tab):
   code = js_template.Render(
       """
       function(element, info) {
         if (!element) {
           throw Error('Cannot find element: ' + info);
         }
         window.__scrollBounceAction.start({
           element: element,
           left_start_ratio: {{ left_start_ratio }},
           top_start_ratio: {{ top_start_ratio }},
           direction: {{ direction }},
           distance: {{ distance }},
           overscroll: {{ overscroll }},
           repeat_count: {{ repeat_count }},
           speed: {{ speed }}
         });
       }""",
       left_start_ratio=self._left_start_ratio,
       top_start_ratio=self._top_start_ratio,
       direction=self._direction,
       distance=self._distance,
       overscroll=self._overscroll,
       repeat_count=self._repeat_count,
       speed=self._speed)
   page_action.EvaluateCallbackWithElement(
       tab,
       code,
       selector=self._selector,
       text=self._text,
       element_function=self._element_function)
   tab.WaitForJavaScriptCondition(
       'window.__scrollBounceActionDone', timeout=60)
コード例 #13
0
ファイル: javascript_click.py プロジェクト: gam0za/AlbaAlza
 def RunAction(self, tab):
   code = '''
       function(element, errorMsg) {
         if (!element) {
           throw Error('Cannot find element: ' + errorMsg);
         }
         element.click();
       }'''
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self.selector, text=self.text,
       element_function=self.element_function)
コード例 #14
0
    def testEvaluateCallbackWithElement(self):
        self.Navigate('blank.html')
        runner = action_runner.ActionRunner(self._tab)
        runner.ExecuteJavaScript('''
        (function() {
           function createElement(id, textContent) {
             var el = document.createElement("div");
             el.id = id;
             el.textContent = textContent;
             document.body.appendChild(el);
           }

           createElement('test-1', 'foo');
           createElement('test-2', 'bar');
           createElement('test-3', 'baz');
        })();''')
        self.assertEqual(
            'foo',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                selector='#test-1'))
        self.assertEqual(
            'bar',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                text='bar'))
        self.assertEqual(
            'baz',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                element_function='document.getElementById("test-3")'))
        self.assertEqual(
            'baz',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el.textContent; }',
                element_function='''
                (function() {
                  return document.getElementById("test-3");
                })()'''))

        # Test for when the element is not found.
        self.assertEqual(
            None,
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el) { return el; }',
                element_function='document.getElementById("test-4")'))

        # Test the info message.
        self.assertEqual(
            'using selector "#test-1"',
            page_action.EvaluateCallbackWithElement(
                self._tab,
                'function(el, info) { return info; }',
                selector='#test-1'))
コード例 #15
0
ファイル: mouse_click.py プロジェクト: xNUTs/catapult
 def RunAction(self, tab):
   code = '''
       function(element, info) {
         if (!element) {
           throw Error('Cannot find element: ' + info);
         }
         window.__mouseClickAction.start({
           element: element
         });
       }'''
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self._selector)
   tab.WaitForJavaScriptCondition2('window.__mouseClickActionDone', timeout=60)
コード例 #16
0
 def RunAction(self, tab):
     code = 'function(element) { return element != null; }'
     try:
         page_action.EvaluateCallbackWithElement(
             tab,
             code,
             selector=self.selector,
             text=self.text,
             element_function=self.element_function,
             wait=True,
             timeout_in_seconds=self.timeout_in_seconds)
     except py_utils.TimeoutException as e:
         # Rethrow with the original stack trace for better debugging.
         raise py_utils.TimeoutException, \
             py_utils.TimeoutException(
                 'Timeout while waiting for element.\n' + e.message), \
             sys.exc_info()[2]
コード例 #17
0
 def RunAction(self, tab):
     code = '''
     function(element, errorMsg) {
       if (!element) {
         throw Error('Cannot find element: ' + errorMsg);
       }
       element.click();
     }'''
     # Click handler that plays media or requests fullscreen may not take
     # effects without user_gesture set to True.
     page_action.EvaluateCallbackWithElement(
         tab,
         code,
         selector=self.selector,
         text=self.text,
         element_function=self.element_function,
         user_gesture=True)
コード例 #18
0
ファイル: drag.py プロジェクト: isabella232/catapult-csm
  def RunAction(self, tab):
    if (self._selector is None and self._text is None and
        self._element_function is None):
      self._element_function = 'document.body'

    gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
    if (page_action.IsGestureSourceTypeSupported(tab, 'mouse') and
        not self._use_touch):
      gesture_source_type = 'chrome.gpuBenchmarking.MOUSE_INPUT'

    code = js_template.Render(
        """
        function(element, info) {
          if (!element) {
            throw Error('Cannot find element: ' + info);
          }
          window.__dragAction.start({
            element: element,
            left_start_ratio: {{ left_start_ratio }},
            top_start_ratio: {{ top_start_ratio }},
            left_end_ratio: {{ left_end_ratio }},
            top_end_ratio: {{ top_end_ratio }},
            speed: {{ speed }},
            gesture_source_type: {{ @gesture_source_type }}
          });
        }""",
        left_start_ratio=self._left_start_ratio,
        top_start_ratio=self._top_start_ratio,
        left_end_ratio=self._left_end_ratio,
        top_end_ratio=self._top_end_ratio,
        speed=self._speed,
        gesture_source_type=gesture_source_type)
    page_action.EvaluateCallbackWithElement(
        tab,
        code,
        selector=self._selector,
        text=self._text,
        element_function=self._element_function)
    tab.WaitForJavaScriptCondition('window.__dragActionDone', timeout=60)
コード例 #19
0
 def RunAction(self, tab):
   scale_factor = (self._scale_factor if self._scale_factor else
                   PinchAction._GetDefaultScaleFactorForPage(tab))
   # TODO(catapult:#3028): Fix interpolation of JavaScript values.
   code = '''
       function(element, info) {
         if (!element) {
           throw Error('Cannot find element: ' + info);
         }
         window.__pinchAction.start({
           element: element,
           left_anchor_ratio: %s,
           top_anchor_ratio: %s,
           scale_factor: %s,
           speed: %s
         });
       }''' % (self._left_anchor_ratio,
               self._top_anchor_ratio,
               scale_factor,
               self._speed)
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self._selector, text=self._text,
       element_function=self._element_function)
   tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
コード例 #20
0
ファイル: wait.py プロジェクト: gam0za/AlbaAlza
 def RunAction(self, tab):
   code = 'function(element) { return element != null; }'
   page_action.EvaluateCallbackWithElement(
       tab, code, selector=self.selector, text=self.text,
       element_function=self.element_function,
       wait=True, timeout_in_seconds=self.timeout_in_seconds)
コード例 #21
0
 def Evaluate2():
     page_action.EvaluateCallbackWithElement(self._tab,
                                             'function() {}',
                                             selector='div',
                                             element_function='foo')
コード例 #22
0
 def Evaluate3():
     page_action.EvaluateCallbackWithElement(self._tab,
                                             'function() {}',
                                             text='foo',
                                             element_function='')