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()
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
def addAppToHomescreen(self, p_name): # # Pick an app from the apps listed in this group. # x = self.UTILS.getElements(DOM.EME.apps, "Apps list", True, 30) for appLink in x: if appLink.get_attribute("data-name") == p_name: from marionette import Actions actions = Actions(self.marionette) actions.press(appLink).wait(2).release() actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.EME.add_app_to_homescreen, "Add app to homescreen button") x.tap() # # Might need to do this again for Geoloc. ... # try: x = self.marionette.find_element(*DOM.EME.add_app_to_homescreen) x.tap() except: pass # This isn't obvious, but you need to scroll the screen right # to reset the position for finding the app later, so I'm # doing it here. time.sleep(2) self.UTILS.goHome() self.UTILS.scrollHomescreenRight() return True return False
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
def wait_with_value(marionette, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) button = marionette.find_element("id", "button1") action = Actions(marionette) action.press(button).wait(0.01).release() action.perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
def test_wait(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).release() action.perform() time.sleep(15) self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
def move_element_offset(marionette, wait_for_condition, expected1, expected2): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) ele = marionette.find_element("id", "button1") action = Actions(marionette) action.press(ele).move_by_offset(0,150).move_by_offset(0, 150).release() action.perform() wait_for_condition(lambda m: expected1 in m.execute_script("return document.getElementById('button1').innerHTML;")) wait_for_condition(lambda m: expected2 in m.execute_script("return document.getElementById('button2').innerHTML;"))
def test_move_by_offset(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) ele = self.marionette.find_element("id", "mozLink") action = Actions(self.marionette) action.press(ele).move_by_offset(0,150).move_by_offset(0,150).release() action.perform() time.sleep(15) self.assertEqual("Move", self.marionette.execute_script("return document.getElementById('mozLink').innerHTML;")) self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkPos').innerHTML;"))
def move_element(marionette, wait_for_condition, expected1, expected2): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) ele = marionette.find_element("id", "button1") drop = marionette.find_element("id", "button2") action = Actions(marionette) action.press(ele).move(drop).release() action.perform() wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;") wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
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()
def press_release(marionette, times, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) action = Actions(marionette) button = marionette.find_element("id", "button1") action.press(button).release() # Insert wait between each press and release chain. for _ in range(times-1): action.wait(0.1) action.press(button).release() action.perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
class test_19231(GaiaTestCase): _Description = "[HOME SCREEN] Verify that the user can uninstall a everything.me app through the grid edit mode." _appName = "Wikipedia" def setUp(self): # # Set up child objects... # GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.actions = Actions(self.marionette) self.settings = AppSettings(self) # self.market = AppMarket(self) self.eme = AppEverythingMe(self) # # def tearDown(self): self.UTILS.reportResults() def test_run(self): # # Get a conection. # self.UTILS.getNetworkConnection() self.UTILS.uninstallApp(self._appName) # # Get the app. # self.eme.launch() x = self.eme.searchForApp(self._appName) self.UTILS.TEST(x, "Icon for " + self._appName + " is found.", True) x = self.UTILS.getElement( ("xpath", DOM.EME.search_result_icon_xpath % self._appName), self._appName + " icon") self.actions.press(x).wait(2).release() self.actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.GLOBAL.modal_ok_button, "OK button") x.tap() time.sleep(2) self.UTILS.goHome() self.UTILS.uninstallApp(self._appName)
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()
class test_main(GaiaTestCase): _appName = "Wikipedia" def setUp(self): # # Set up child objects... # GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.actions = Actions(self.marionette) self.settings = Settings(self) self.eme = EverythingMe(self) def tearDown(self): self.UTILS.reportResults() def test_run(self): # # Get a conection. # self.UTILS.getNetworkConnection() self.UTILS.uninstallApp(self._appName) # # Get the app. # self.eme.launch() x = self.eme.searchForApp(self._appName) self.UTILS.TEST(x, "Icon for " + self._appName + " is found.", True) # # Long-press the app to install it to the homescreen. # x = self.UTILS.getElement( ("xpath", DOM.EME.search_result_icon_xpath % self._appName), self._appName + " icon") self.actions.press(x).wait(2).release() self.actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.GLOBAL.modal_ok_button1, "OK button") x.tap() time.sleep(2) self.UTILS.goHome() self.UTILS.uninstallApp(self._appName)
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 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 addAppToHomescreen(self, p_name): # # Pick an app from the apps listed in this group. # x = self.UTILS.getElements(DOM.EME.apps, "Apps list", True, 30) for appLink in x: if appLink.get_attribute("data-name") == p_name: from marionette import Actions actions = Actions(self.marionette) actions.press(appLink).wait(2).release() actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.EME.add_app_to_homescreen, "Add app to homescreen button") x.tap() # # Might need to do this again for Geoloc. ... # try: x = self.marionette.find_element( *DOM.EME.add_app_to_homescreen) x.tap() except: pass # This isn't obvious, but you need to scroll the screen right # to reset the position for finding the app later, so I'm # doing it here. time.sleep(2) self.UTILS.goHome() self.UTILS.scrollHomescreenRight() return True return False
class AppEverythingMe(GaiaTestCase): # # When you create your instance of this class, include the # "self" object so we can access the calling class' objects. # def __init__(self, p_parent): self.apps = p_parent.apps self.data_layer = p_parent.data_layer self.marionette = p_parent.marionette self.UTILS = p_parent.UTILS self.actions = Actions(self.marionette) def launch(self): # # Go to the homescreen. # self.UTILS.goHome() # # Scroll to the left to expose the 'everything.me' screen. # self.UTILS.scrollHomescreenLeft() self.UTILS.waitForElements(DOM.EME.groups, "EME groups", True, 30) def searchForApp(self, p_name): # # Uses the search field to find the app (waits for the # result to appear etc...).<br> # Returns the element for the icon (or False if it's not found). # self.UTILS.typeThis(DOM.EME.search_field, "Search field", p_name, p_no_keyboard=True) boolOK = True try: self.wait_for_element_displayed("xpath", DOM.EME.search_result_icon_xpath % p_name, timeout=60) except: boolOK = False return boolOK def pickGroup(self, p_name): # # Pick a group from the main icons. # x = self.UTILS.getElements(DOM.EME.groups, "EME group list") boolOK = False for groupLink in x: if groupLink.get_attribute("data-query") == p_name: groupLink.tap() time.sleep(10) boolOK = True break # # At this point the geolocation sometimes wants to know # if it can remember our location. # self.UTILS.clearGeolocPermission() return boolOK def removeGroup(self, p_group): # # Removes a group from the EME group page. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = False iconPos = -1 counter = -1 for i in x: counter = counter + 1 if i.get_attribute("data-query") == p_group: boolOK = True # # Long press to activate edit mode. # self.actions.press(i).wait(2).release() self.actions.perform() iconPos = counter break # # If the group was present, remove it. # if boolOK: self.UTILS.logResult("info", "(Removing group '" + p_group + "'.)") x = self.UTILS.getElements(DOM.EME.groups, "Groups")[iconPos] y = x.find_element(*DOM.EME.remove_group_icon) y.tap() # # Disactivate edit mode (just tap the search field). # x = self.marionette.find_element(*DOM.EME.search_field) x.tap() # # Verify that the group has been removed. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = True for i in x: if i.get_attribute("data-query") == p_group: boolOK = False break self.UTILS.TEST(boolOK, "Group is no longer present in Everything.Me.") else: self.UTILS.logResult("info", "(Group '" + p_group + "' not found in Everything.Me, so no need to remove it.)") return def addGroup(self, p_group): # # Adds a group to EME (assumes you're already in the EME group screen). # self.UTILS.logResult("info", "(Adding group '" + p_group + "'.)") # # Click the 'More' icon. # x = self.UTILS.getElement(DOM.EME.add_group_button, "'More' icon") x.tap() # # Wait for the 'loading' spinner to go away (can take a while!). # self.UTILS.waitForNotElements(DOM.EME.loading_groups_message, "'Loading' message", True, 120) # # Chose an item from the groups list... # self.UTILS.selectFromSystemDialog(p_group) # # Verify the new group is in the groups list. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = False for i in x: if i.get_attribute("data-query") == p_group: boolOK = True break self.UTILS.TEST(boolOK, "New group '" + p_group + "' is now present in the EME groups.") return boolOK def addAppToHomescreen(self, p_name): # # Pick an app from the apps listed in this group. # x = self.UTILS.getElements(DOM.EME.apps, "Apps list", True, 30) for appLink in x: if appLink.get_attribute("data-name") == p_name: from marionette import Actions actions = Actions(self.marionette) actions.press(appLink).wait(2).release() actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.EME.add_app_to_homescreen, "Add app to homescreen button") x.tap() # # Might need to do this again for Geoloc. ... # try: x = self.marionette.find_element(*DOM.EME.add_app_to_homescreen) x.tap() except: pass # This isn't obvious, but you need to scroll the screen right # to reset the position for finding the app later, so I'm # doing it here. time.sleep(2) self.UTILS.goHome() self.UTILS.scrollHomescreenRight() return True return False
class AppEverythingMe(GaiaTestCase): # # When you create your instance of this class, include the # "self" object so we can access the calling class' objects. # def __init__(self, p_parent): self.apps = p_parent.apps self.data_layer = p_parent.data_layer self.marionette = p_parent.marionette self.UTILS = p_parent.UTILS self.actions = Actions(self.marionette) def launch(self): # # Go to the homescreen. # self.UTILS.goHome() # # Scroll to the left to expose the 'everything.me' screen. # self.UTILS.scrollHomescreenLeft() self.UTILS.waitForElements(DOM.EME.groups, "EME groups", True, 30) def searchForApp(self, p_name): # # Uses the search field to find the app (waits for the # result to appear etc...).<br> # Returns the element for the icon (or False if it's not found). # self.UTILS.typeThis(DOM.EME.search_field, "Search field", p_name, p_no_keyboard=True) boolOK = True try: self.wait_for_element_displayed("xpath", DOM.EME.search_result_icon_xpath % p_name, timeout=60) except: boolOK = False return boolOK def pickGroup(self, p_name): # # Pick a group from the main icons. # x = self.UTILS.getElements(DOM.EME.groups, "EME group list") boolOK = False for groupLink in x: if groupLink.get_attribute("data-query") == p_name: groupLink.tap() time.sleep(10) boolOK = True break # # At this point the geolocation sometimes wants to know # if it can remember our location. # self.UTILS.clearGeolocPermission() return boolOK def removeGroup(self, p_group): # # Removes a group from the EME group page. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = False iconPos = -1 counter = -1 for i in x: counter = counter + 1 if i.get_attribute("data-query") == p_group: boolOK = True # # Long press to activate edit mode. # self.actions.press(i).wait(2).release() self.actions.perform() iconPos = counter break # # If the group was present, remove it. # if boolOK: self.UTILS.logResult("info", "(Removing group '" + p_group + "'.)") x = self.UTILS.getElements(DOM.EME.groups, "Groups")[iconPos] y = x.find_element(*DOM.EME.remove_group_icon) y.tap() # # Disactivate edit mode (just tap the search field). # x = self.marionette.find_element(*DOM.EME.search_field) x.tap() # # Verify that the group has been removed. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = True for i in x: if i.get_attribute("data-query") == p_group: boolOK = False break self.UTILS.TEST(boolOK, "Group is no longer present in Everything.Me.") else: self.UTILS.logResult( "info", "(Group '" + p_group + "' not found in Everything.Me, so no need to remove it.)") return def addGroup(self, p_group): # # Adds a group to EME (assumes you're already in the EME group screen). # self.UTILS.logResult("info", "(Adding group '" + p_group + "'.)") # # Click the 'More' icon. # x = self.UTILS.getElement(DOM.EME.add_group_button, "'More' icon") x.tap() # # Wait for the 'loading' spinner to go away (can take a while!). # self.UTILS.waitForNotElements(DOM.EME.loading_groups_message, "'Loading' message", True, 120) # # Chose an item from the groups list... # self.UTILS.selectFromSystemDialog(p_group) # # Verify the new group is in the groups list. # x = self.UTILS.getElements(DOM.EME.groups, "Groups") boolOK = False for i in x: if i.get_attribute("data-query") == p_group: boolOK = True break self.UTILS.TEST( boolOK, "New group '" + p_group + "' is now present in the EME groups.") return boolOK def addAppToHomescreen(self, p_name): # # Pick an app from the apps listed in this group. # x = self.UTILS.getElements(DOM.EME.apps, "Apps list", True, 30) for appLink in x: if appLink.get_attribute("data-name") == p_name: from marionette import Actions actions = Actions(self.marionette) actions.press(appLink).wait(2).release() actions.perform() self.marionette.switch_to_frame() x = self.UTILS.getElement(DOM.EME.add_app_to_homescreen, "Add app to homescreen button") x.tap() # # Might need to do this again for Geoloc. ... # try: x = self.marionette.find_element( *DOM.EME.add_app_to_homescreen) x.tap() except: pass # This isn't obvious, but you need to scroll the screen right # to reset the position for finding the app later, so I'm # doing it here. time.sleep(2) self.UTILS.goHome() self.UTILS.scrollHomescreenRight() return True return False