Пример #1
0
def pinch(marionette_session,
          element,
          x1,
          y1,
          x2,
          y2,
          x3,
          y3,
          x4,
          y4,
          duration=200):
    time = 0
    time_increment = 10
    if time_increment >= duration:
        time_increment = duration
    move_x1 = time_increment * 1.0 / duration * (x3 - x1)
    move_y1 = time_increment * 1.0 / duration * (y3 - y1)
    move_x2 = time_increment * 1.0 / duration * (x4 - x2)
    move_y2 = time_increment * 1.0 / duration * (y4 - y2)
    multiAction = MultiActions(marionette_session)
    action1 = Actions(marionette_session)
    action2 = Actions(marionette_session)
    action1.press(element, x1, y1)
    action2.press(element, x2, y2)
    while (time < duration):
        time += time_increment
        action1.move_by_offset(move_x1, move_y1).wait(time_increment / 1000)
        action2.move_by_offset(move_x2, move_y2).wait(time_increment / 1000)
    action1.release()
    action2.release()
    multiAction.add(action1).add(action2).perform()
Пример #2
0
    def edge_scroll(self, frame, direction, dist, release=True):
        """edge scroll - performs task switching action.

        direction = 'LtoR' or 'RtoL' (finger movement direction)
        dist = percentage of horizontal distance travel, max is 1.0
        release = if set to False, the Action object will be returned so the user can complete the release action"""

        start_x = 0
        dist_travelled = 0
        time_increment = 0.01

        if dist > 1:
            dist = 1
        if direction == 'LtoR':
            start_x = 0
        elif direction == 'RtoL':
            start_x = frame.size['width']
            dist *= -1  # travel opposite direction

        limit = dist * frame.size['width']
        dist_unit = limit * time_increment

        action = Actions(self.marionette)
        action.press(frame, start_x, frame.size['height'] /
                     2)  # press either the left or right edge

        while abs(dist_travelled) < abs(limit):
            action.move_by_offset(dist_unit, 0)
            action.wait(time_increment)
            dist_travelled += dist_unit
        if release:
            action.release()
        action.perform()

        return action
Пример #3
0
def pinch(marionette_session, element, x1, y1, x2, y2, x3, y3, x4, y4, duration=200):
    """
        :param element: target
        :param x1, y1: 1st finger starting position relative to the target
        :param x3, y3: 1st finger ending position relative to the target
        :param x2, y2: 2nd finger starting position relative to the target
        :param x4, y4: 2nd finger ending position relative to the target
        :param duration: Amount of time in milliseconds to complete the pinch.
    """
    time = 0
    time_increment = 10
    if time_increment >= duration:
        time_increment = duration
    move_x1 = time_increment * 1.0 / duration * (x3 - x1)
    move_y1 = time_increment * 1.0 / duration * (y3 - y1)
    move_x2 = time_increment * 1.0 / duration * (x4 - x2)
    move_y2 = time_increment * 1.0 / duration * (y4 - y2)
    multiAction = MultiActions(marionette_session)
    action1 = Actions(marionette_session)
    action2 = Actions(marionette_session)
    action1.press(element, x1, y1)
    action2.press(element, x2, y2)
    while time < duration:
        time += time_increment
        action1.move_by_offset(move_x1, move_y1).wait(time_increment / 1000)
        action2.move_by_offset(move_x2, move_y2).wait(time_increment / 1000)
    action1.release()
    action2.release()
    multiAction.add(action1).add(action2).perform()
Пример #4
0
def smooth_scroll(marionette_session, start_element, axis, direction, length, increments=None, wait_period=None, scroll_back=None):
    if axis not in ["x", "y"]:
        raise Exception("Axis must be either 'x' or 'y'")
    if direction not in [-1, 0]:
        raise Exception("Direction must either be -1 negative or 0 positive")
    increments = increments or 100
    wait_period = wait_period or 0.05
    scroll_back = scroll_back or False
    current = 0
    if axis is "x":
        if direction is -1:
            offset = [-increments, 0]
        else:
            offset = [increments, 0]
    else:
        if direction is -1:
            offset = [0, -increments]
        else:
            offset = [0, increments]
    action = Actions(marionette_session)
    action.press(start_element)
    while (current < length):
        current += increments
        action.move_by_offset(*offset).wait(wait_period)
    if scroll_back:
        offset = [-value for value in offset]
        while (current > 0):
            current -= increments
            action.move_by_offset(*offset).wait(wait_period)
    action.release()
    action.perform()
Пример #5
0
    def edge_scroll(self, frame, direction, dist, release=True):
        """edge scroll - performs task switching action.

        direction = 'LtoR' or 'RtoL' (finger movement direction)
        dist = percentage of horizontal distance travel, max is 1.0
        release = if set to False, the Action object will be returned so the user can complete the release action"""

        start_x = 0
        dist_travelled = 0
        time_increment = 0.01

        if dist > 1:
            dist = 1
        if direction == "LtoR":
            start_x = 0
        elif direction == "RtoL":
            start_x = frame.size["width"]
            dist *= -1  # travel opposite direction

        limit = dist * frame.size["width"]
        dist_unit = limit * time_increment

        action = Actions(self.marionette)
        action.press(frame, start_x, frame.size["height"] / 2)  # press either the left or right edge

        while abs(dist_travelled) < abs(limit):
            action.move_by_offset(dist_unit, 0)
            action.wait(time_increment)
            dist_travelled += dist_unit
        if release:
            action.release()
        action.perform()

        return action
Пример #6
0
def context_menu(marionette, wait_for_condition, expected1, expected2):
    testAction = marionette.absolute_url("testAction.html")
    marionette.navigate(testAction)
    button = marionette.find_element("id", "button1")
    action = Actions(marionette)
    action.press(button).wait(5).perform()
    wait_for_condition(lambda m: expected1 in m.execute_script("return document.getElementById('button1').innerHTML;"))
    action.release().perform()
    wait_for_condition(lambda m: expected2 in m.execute_script("return document.getElementById('button1').innerHTML;"))
def context_menu(marionette, wait_for_condition, expected1, expected2):
    testAction = marionette.absolute_url("testAction.html")
    marionette.navigate(testAction)
    button = marionette.find_element("id", "button1")
    action = Actions(marionette)
    action.press(button).wait(5).perform()
    wait_for_condition(lambda m: expected1 in m.execute_script("return document.getElementById('button1').innerHTML;"))
    action.release().perform()
    wait_for_condition(lambda m: expected2 in m.execute_script("return document.getElementById('button1').innerHTML;"))
Пример #8
0
 def test_long_press(self):
     testTouch = self.marionette.absolute_url("testAction.html")
     self.marionette.navigate(testTouch)
     button = self.marionette.find_element("id", "mozLinkCopy")
     action = Actions(self.marionette)
     action.press(button).wait(5).perform()
     time.sleep(10)
     self.assertEqual("Context", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
     action.release().perform()
     time.sleep(10)
     self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
Пример #9
0
def long_press_without_contextmenu(marionette_session,
                                   element,
                                   time_in_seconds,
                                   x=None,
                                   y=None):
    action = Actions(marionette_session)
    action.press(element, x, y)
    action.move_by_offset(0, 0)
    action.wait(time_in_seconds)
    action.release()
    action.perform()
Пример #10
0
def long_press_without_contextmenu(marionette_session, element, time_in_seconds, x=None, y=None):
    """
        :param element: The element to press.
        :param time_in_seconds: Time in seconds to wait before releasing the press.
        #x: Optional, x-coordinate to tap, relative to the top-left corner of the element.
        #y: Optional, y-coordinate to tap, relative to the top-leftcorner of the element.
    """
    action = Actions(marionette_session)
    action.press(element, x, y)
    action.move_by_offset(0, 0)
    action.wait(time_in_seconds)
    action.release()
    action.perform()
Пример #11
0
def smooth_scroll(marionette_session,
                  start_element,
                  axis,
                  direction,
                  length,
                  increments=None,
                  wait_period=None,
                  scroll_back=None):
    """
        :param axis:  y or x
        :param direction: 0 for positive, and -1 for negative
        :param length: total length of scroll scroll
        :param increments: Amount to be moved per scrolling
        :param wait_period: Seconds to wait between scrolling
        :param scroll_back: Scroll back to original view?
    """
    if axis not in ["x", "y"]:
        raise Exception("Axis must be either 'x' or 'y'")
    if direction not in [-1, 0]:
        raise Exception("Direction must either be -1 negative or 0 positive")
    increments = increments or 100
    wait_period = wait_period or 0.05
    scroll_back = scroll_back or False
    current = 0
    if axis is "x":
        if direction is -1:
            offset = [-increments, 0]
        else:
            offset = [increments, 0]
    else:
        if direction is -1:
            offset = [0, -increments]
        else:
            offset = [0, increments]
    action = Actions(marionette_session)
    action.press(start_element)
    while (current < length):
        current += increments
        action.move_by_offset(*offset).wait(wait_period)
    if scroll_back:
        offset = [-value for value in offset]
        while (current > 0):
            current -= increments
            action.move_by_offset(*offset).wait(wait_period)
    action.release()
    action.perform()
 def test_long_press(self):
     testTouch = self.marionette.absolute_url("testAction.html")
     self.marionette.navigate(testTouch)
     button = self.marionette.find_element("id", "mozLinkCopy")
     action = Actions(self.marionette)
     action.press(button).wait(5).perform()
     time.sleep(10)
     self.assertEqual(
         "Context",
         self.marionette.execute_script(
             "return document.getElementById('mozLinkCopy').innerHTML;"))
     action.release().perform()
     time.sleep(10)
     self.assertEqual(
         "ContextEnd",
         self.marionette.execute_script(
             "return document.getElementById('mozLinkCopy').innerHTML;"))
Пример #13
0
def long_press_without_contextmenu(marionette_session,
                                   element,
                                   time_in_seconds,
                                   x=None,
                                   y=None):
    """
        :param element: The element to press.
        :param time_in_seconds: Time in seconds to wait before releasing the press.
        #x: Optional, x-coordinate to tap, relative to the top-left corner of the element.
        #y: Optional, y-coordinate to tap, relative to the top-leftcorner of the element.
    """
    action = Actions(marionette_session)
    action.press(element, x, y)
    action.move_by_offset(0, 0)
    action.wait(time_in_seconds)
    action.release()
    action.perform()
Пример #14
0
def smooth_scroll(
    marionette_session, start_element, axis, direction, length, increments=None, wait_period=None, scroll_back=None
):
    """
        :param axis:  y or x
        :param direction: 0 for positive, and -1 for negative
        :param length: total length of scroll scroll
        :param increments: Amount to be moved per scrolling
        :param wait_period: Seconds to wait between scrolling
        :param scroll_back: Scroll back to original view?
    """
    if axis not in ["x", "y"]:
        raise Exception("Axis must be either 'x' or 'y'")
    if direction not in [-1, 0]:
        raise Exception("Direction must either be -1 negative or 0 positive")
    increments = increments or 100
    wait_period = wait_period or 0.05
    scroll_back = scroll_back or False
    current = 0
    if axis is "x":
        if direction is -1:
            offset = [-increments, 0]
        else:
            offset = [increments, 0]
    else:
        if direction is -1:
            offset = [0, -increments]
        else:
            offset = [0, increments]
    action = Actions(marionette_session)
    action.press(start_element)
    while current < length:
        current += increments
        action.move_by_offset(*offset).wait(wait_period)
    if scroll_back:
        offset = [-value for value in offset]
        while current > 0:
            current -= increments
            action.move_by_offset(*offset).wait(wait_period)
    action.release()
    action.perform()
Пример #15
0
def pinch(marionette_session, element, x1, y1, x2, y2, x3, y3, x4, y4, duration=200):
    time = 0
    time_increment = 10
    if time_increment >= duration:
        time_increment = duration
    move_x1 = time_increment*1.0/duration * (x3 - x1)
    move_y1 = time_increment*1.0/duration * (y3 - y1)
    move_x2 = time_increment*1.0/duration * (x4 - x2)
    move_y2 = time_increment*1.0/duration * (y4 - y2)
    multiAction = MultiActions(marionette_session)
    action1 = Actions(marionette_session)
    action2 = Actions(marionette_session)
    action1.press(element, x1, y1)
    action2.press(element, x2, y2)
    while (time < duration):
        time += time_increment
        action1.move_by_offset(move_x1, move_y1).wait(time_increment/1000)
        action2.move_by_offset(move_x2, move_y2).wait(time_increment/1000)
    action1.release()
    action2.release()
    multiAction.add(action1).add(action2).perform()
Пример #16
0
def pinch(marionette_session,
          element,
          x1,
          y1,
          x2,
          y2,
          x3,
          y3,
          x4,
          y4,
          duration=200):
    """
        :param element: target
        :param x1, y1: 1st finger starting position relative to the target
        :param x3, y3: 1st finger ending position relative to the target
        :param x2, y2: 2nd finger starting position relative to the target
        :param x4, y4: 2nd finger ending position relative to the target
        :param duration: Amount of time in milliseconds to complete the pinch.
    """
    time = 0
    time_increment = 10
    if time_increment >= duration:
        time_increment = duration
    move_x1 = time_increment * 1.0 / duration * (x3 - x1)
    move_y1 = time_increment * 1.0 / duration * (y3 - y1)
    move_x2 = time_increment * 1.0 / duration * (x4 - x2)
    move_y2 = time_increment * 1.0 / duration * (y4 - y2)
    multiAction = MultiActions(marionette_session)
    action1 = Actions(marionette_session)
    action2 = Actions(marionette_session)
    action1.press(element, x1, y1)
    action2.press(element, x2, y2)
    while (time < duration):
        time += time_increment
        action1.move_by_offset(move_x1, move_y1).wait(time_increment / 1000)
        action2.move_by_offset(move_x2, move_y2).wait(time_increment / 1000)
    action1.release()
    action2.release()
    multiAction.add(action1).add(action2).perform()
Пример #17
0
def smooth_scroll(marionette_session,
                  start_element,
                  axis,
                  direction,
                  length,
                  increments=None,
                  wait_period=None,
                  scroll_back=None):
    if axis not in ["x", "y"]:
        raise Exception("Axis must be either 'x' or 'y'")
    if direction not in [-1, 0]:
        raise Exception("Direction must either be -1 negative or 0 positive")
    increments = increments or 100
    wait_period = wait_period or 0.05
    scroll_back = scroll_back or False
    current = 0
    if axis is "x":
        if direction is -1:
            offset = [-increments, 0]
        else:
            offset = [increments, 0]
    else:
        if direction is -1:
            offset = [0, -increments]
        else:
            offset = [0, increments]
    action = Actions(marionette_session)
    action.press(start_element)
    while (current < length):
        current += increments
        action.move_by_offset(*offset).wait(wait_period)
    if scroll_back:
        offset = [-value for value in offset]
        while (current > 0):
            current -= increments
            action.move_by_offset(*offset).wait(wait_period)
    action.release()
    action.perform()
Пример #18
0
 def test_no_press(self):
     testAction = self.marionette.absolute_url("testAction.html")
     self.marionette.navigate(testAction)
     action = Actions(self.marionette)
     action.release()
     self.assertRaises(MarionetteException, action.perform)
Пример #19
0
 def test_no_press(self):
     testTouch = self.marionette.absolute_url("testAction.html")
     self.marionette.navigate(testTouch)
     action = Actions(self.marionette)
     action.release()
     self.assertRaises(NoSuchElementException, action.perform)