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 test_move_element(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) start = self.marionette.find_element("id", "mozLink") drop = self.marionette.find_element("id", "mozLinkPos") ele = self.marionette.find_element("id", "mozLinkCopy") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action1.press(start).move(drop).wait(3).release() action2.press(ele).wait().release() multi_action.add(action1).add(action2).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;")) self.assertEqual( "End", self.marionette.execute_script( "return document.getElementById('mozLinkCopy').innerHTML;"))
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 wait(marionette, 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).wait().release().perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
def test_long_press_fail(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).long_press(button, 5) self.assertRaises(MarionetteException, action.perform)
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 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()
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()
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_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').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_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 test_no_mouse_wait(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) self.marionette.send_mouse_event(False) action = Actions(self.marionette) button = self.marionette.find_element("id", "mozMouse") action.press(button).wait().release().perform() time.sleep(15) self.assertEqual("TouchEnd", self.marionette.execute_script("return document.getElementById('mozMouse').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_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;") action.release().perform() wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button1').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 test_chain(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) action = Actions(self.marionette) button1 = self.marionette.find_element("id", "mozLinkCopy2") action.press(button1).perform() button2 = self.marionette.find_element("id", "delayed") time.sleep(5) action.move(button2).release().perform() time.sleep(15) self.assertEqual("End", self.marionette.execute_script("return document.getElementById('delayed').innerHTML;"))
def chain(marionette, wait_for_condition, expected1, expected2): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) marionette.set_search_timeout(15000) action = Actions(marionette) button1 = marionette.find_element("id", "button1") action.press(button1).perform() button2 = marionette.find_element("id", "delayed") wait_for_condition(lambda m: expected1 in m.execute_script("return document.getElementById('button1').innerHTML;")) action.move(button2).release().perform() wait_for_condition(lambda m: expected2 in m.execute_script("return document.getElementById('delayed').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 test_mouse_wait_more(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) self.marionette.send_mouse_event(True) action = Actions(self.marionette) button = self.marionette.find_element("id", "mozMouse") action.press(button).wait(0.1).release().perform() time.sleep(15) self.assertEqual( "MouseClick", self.marionette.execute_script( "return document.getElementById('mozMouse').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 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;"))
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 test_chain(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) action = Actions(self.marionette) button1 = self.marionette.find_element("id", "mozLinkCopy2") action.press(button1).perform() button2 = self.marionette.find_element("id", "delayed") time.sleep(5) action.move(button2).release().perform() time.sleep(15) self.assertEqual( "End", self.marionette.execute_script( "return document.getElementById('delayed').innerHTML;"))
def test_move_offset_element(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) start = self.marionette.find_element("id", "mozLink") ele = self.marionette.find_element("id", "mozLinkCopy") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action1.press(start).move_by_offset(0,300).wait().release() action2.press(ele).wait(5).release() multi_action.add(action1).add(action2).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;")) self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkCopy').innerHTML;"))
def test_move_offset_element(self): testAction = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testAction) start = self.marionette.find_element("id", "button1") ele = self.marionette.find_element("id", "button3") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action1.press(start).move_by_offset(0,300).wait().release() action2.press(ele).wait(5).release() multi_action.add(action1).add(action2).perform() expected = "button1-touchstart" self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected) self.assertEqual("button2-touchmove-touchend", self.marionette.execute_script("return document.getElementById('button2').innerHTML;")) self.assertTrue("button3-touchstart-touchend" in self.marionette.execute_script("return document.getElementById('button3').innerHTML;"))
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 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()
def test_three_fingers(self): testAction = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testAction) start_one = self.marionette.find_element("id", "button1") start_two = self.marionette.find_element("id", "button2") element1 = self.marionette.find_element("id", "button3") element2 = self.marionette.find_element("id", "button4") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action3 = Actions(self.marionette) action1.press(start_one).move_by_offset(0, 300).release() action2.press(element1).wait().wait(5).release() action3.press(element2).wait().wait().release() multi_action.add(action1).add(action2).add(action3).perform() expected = "button1-touchstart" self.wait_for_condition(lambda m: m.execute_script( "return document.getElementById('button1').innerHTML;") == expected ) self.assertEqual( "button2-touchmove-touchend", self.marionette.execute_script( "return document.getElementById('button2').innerHTML;")) button3_text = self.marionette.execute_script( "return document.getElementById('button3').innerHTML;") button4_text = self.marionette.execute_script( "return document.getElementById('button4').innerHTML;") self.assertIn("button3-touchstart-touchend", button3_text) self.assertIn("button4-touchstart-touchend", button4_text) self.assertTrue(int(button3_text.rsplit("-")[-1]) >= 5000) self.assertTrue(int(button4_text.rsplit("-")[-1]) >= 5000)
def test_three_fingers(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) start_one = self.marionette.find_element("id", "mozLink") start_two = self.marionette.find_element("id", "mozLinkStart") drop_two = self.marionette.find_element("id", "mozLinkEnd") ele = self.marionette.find_element("id", "mozLinkCopy2") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action3 = Actions(self.marionette) action1.press(start_one).move_by_offset(0, 300).release() action2.press(ele).wait().wait(5).release() action3.press(start_two).move(drop_two).wait(2).release() multi_action.add(action1).add(action2).add(action3).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;")) self.assertTrue( self.marionette.execute_script( "return document.getElementById('mozLinkCopy2').innerHTML >= 5000;" )) self.assertTrue( self.marionette.execute_script( "return document.getElementById('mozLinkEnd').innerHTML >= 5000;" ))
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()
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 test_three_fingers(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) start_one = self.marionette.find_element("id", "mozLink") start_two = self.marionette.find_element("id", "mozLinkStart") drop_two = self.marionette.find_element("id", "mozLinkEnd") ele = self.marionette.find_element("id", "mozLinkCopy2") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action3 = Actions(self.marionette) action1.press(start_one).move_by_offset(0,300).release() action2.press(ele).wait().wait(5).release() action3.press(start_two).move(drop_two).wait(2).release() multi_action.add(action1).add(action2).add(action3).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;")) self.assertTrue(self.marionette.execute_script("return document.getElementById('mozLinkCopy2').innerHTML >= 5000;")) self.assertTrue(self.marionette.execute_script("return document.getElementById('mozLinkEnd').innerHTML >= 5000;"))
def test_three_fingers(self): testAction = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testAction) start_one = self.marionette.find_element("id", "button1") start_two = self.marionette.find_element("id", "button2") element1 = self.marionette.find_element("id", "button3") element2 = self.marionette.find_element("id", "button4") multi_action = MultiActions(self.marionette) action1 = Actions(self.marionette) action2 = Actions(self.marionette) action3 = Actions(self.marionette) action1.press(start_one).move_by_offset(0,300).release() action2.press(element1).wait().wait(5).release() action3.press(element2).wait().wait().release() multi_action.add(action1).add(action2).add(action3).perform() expected = "button1-touchstart" self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected) self.assertEqual("button2-touchmove-touchend", self.marionette.execute_script("return document.getElementById('button2').innerHTML;")) button3_text = self.marionette.execute_script("return document.getElementById('button3').innerHTML;") button4_text = self.marionette.execute_script("return document.getElementById('button4').innerHTML;") self.assertTrue("button3-touchstart-touchend" in button3_text) self.assertTrue("button4-touchstart-touchend" in button4_text) self.assertTrue(int(button3_text.rsplit("-")[-1]) >= 5000) self.assertTrue(int(button4_text.rsplit("-")[-1]) >= 5000)
class SelectionCaretsTest(MarionetteTestCase): _long_press_time = 1 # 1 second _input_selector = (By.ID, 'input') _textarea_selector = (By.ID, 'textarea') _textarea_rtl_selector = (By.ID, 'textarea_rtl') _contenteditable_selector = (By.ID, 'contenteditable') _content_selector = (By.ID, 'content') _contenteditable2_selector = (By.ID, 'contenteditable2') def setUp(self): # Code to execute before a tests are run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette) def openTestHtml(self, enabled=True): '''Open html for testing and locate elements, and enable/disable touch caret.''' self.marionette.execute_script( 'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' % ('true' if enabled else 'false')) test_html = self.marionette.absolute_url('test_selectioncarets.html') self.marionette.navigate(test_html) self._input = self.marionette.find_element(*self._input_selector) self._textarea = self.marionette.find_element(*self._textarea_selector) self._textarea_rtl = self.marionette.find_element(*self._textarea_rtl_selector) self._contenteditable = self.marionette.find_element(*self._contenteditable_selector) self._content = self.marionette.find_element(*self._content_selector) self._contenteditable2 = self.marionette.find_element(*self._contenteditable2_selector) def _first_word_location(self, el): '''Get the location (x, y) of the first word in el. Note: this function has a side effect which changes focus to the target element el. ''' sel = SelectionManager(el) # Move caret behind the first character to get the location of the first # word. el.tap() sel.move_caret_to_front() sel.move_caret_by_offset(1) return sel.caret_location() def _long_press_to_select(self, el, x, y): '''Long press the location (x, y) to select a word. SelectionCarets should appear. On Windows, those spaces after the word will also be selected. ''' long_press_without_contextmenu(self.marionette, el, self._long_press_time, x, y) def _test_long_press_to_select_a_word(self, el, assertFunc): sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue(len(words) >= 2, 'Expect at least two words in the content.') target_content = words[0] # Goal: Select the first word. x, y = self._first_word_location(el) self._long_press_to_select(el, x, y) # Ignore extra spaces selected after the word. assertFunc(target_content, sel.selected_content.rstrip()) def _test_move_selection_carets(self, el, assertFunc): sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.') # Goal: Select all text after the first word. target_content = original_content[len(words[0]):] # Get the location of the selection carets at the end of the content for # later use. el.tap() sel.select_all() (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location() x, y = self._first_word_location(el) self._long_press_to_select(el, x, y) # Move the right caret to the end of the content. (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform() # Move the left caret to the previous position of the right caret. self.actions.flick(el, caret1_x, caret1_y, caret2_x, caret2_y).perform() # Ignore extra spaces at the beginning of the content in comparison. assertFunc(target_content.lstrip(), sel.selected_content.lstrip()) def _test_minimum_select_one_character(self, el, assertFunc, x=None, y=None): sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.') # Get the location of the selection carets at the end of the content for # later use. sel.select_all() (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location() el.tap() # Goal: Select the first character. target_content = original_content[0] if x and y: # If we got x and y from the arguments, use it as a hint of the # location of the first word pass else: x, y = self._first_word_location(el) self._long_press_to_select(el, x, y) # Move the right caret to the end of the content. (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(el, caret2_x, caret2_y, end_caret_x, end_caret_y).perform() # Move the right caret to the position of the left caret. (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(el, caret2_x, caret2_y, caret1_x, caret1_y).perform() assertFunc(target_content, sel.selected_content) def _test_focus_obtained_by_long_press(self, el1, el2): '''Test the focus could be changed from el1 to el2 by long press. If the focus is changed to e2 successfully, SelectionCarets should appear and could be dragged. ''' # Goal: Tap to focus el1, and then select the first character on # el2. # We want to collect the location of the first word in el2 here # since self._first_word_location() has the side effect which would # change the focus. x, y = self._first_word_location(el2) el1.tap() self._test_minimum_select_one_character(el2, self.assertEqual, x=x, y=y) def _test_handle_tilt_when_carets_overlap_to_each_other(self, el, assertFunc): '''Test tilt handling when carets overlap to each other. Let SelectionCarets overlap to each other. If SelectionCarets are set to tilted successfully, tapping the tilted carets should not cause the selection to be collapsed and the carets should be draggable. ''' sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue(len(words) >= 1, 'Expect at least one word in the content.') # Goal: Select the first word. x, y = self._first_word_location(el) self._long_press_to_select(el, x, y) target_content = sel.selected_content # Move the left caret to the position of the right caret to trigger # carets overlapping. (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(el, caret1_x, caret1_y, caret2_x, caret2_y).perform() # Caret width is 29px, so we make a series of hit tests for the two # tilted carets. If any of the hits is missed, selection would be # collapsed and both two carets should not be draggable. (caret3_x, caret3_y), (caret4_x, caret4_y) = sel.selection_carets_location() right_x = int(caret4_x + 0.5) for i in range (right_x, right_x + 29, + 1): self.actions.press(el, i, caret4_y).release().perform() left_x = int(caret3_x - 0.5) for i in range (left_x, left_x - 29, - 1): self.actions.press(el, i, caret3_y).release().perform() # Drag the left caret back to the initial selection, the first word. self.actions.flick(el, caret3_x, caret3_y, caret1_x, caret1_y).perform() assertFunc(target_content, sel.selected_content) ######################################################################## # <input> test cases with selection carets enabled ######################################################################## def test_input_long_press_to_select_a_word(self): self.openTestHtml(enabled=True) self._test_long_press_to_select_a_word(self._input, self.assertEqual) def test_input_move_selection_carets(self): self.openTestHtml(enabled=True) self._test_move_selection_carets(self._input, self.assertEqual) def test_input_minimum_select_one_character(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._input, self.assertEqual) def test_input_focus_obtained_by_long_press_from_textarea(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._textarea, self._input) def test_input_focus_obtained_by_long_press_from_contenteditable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._contenteditable, self._input) def test_input_focus_obtained_by_long_press_from_content_non_editable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._content, self._input) def test_input_handle_tilt_when_carets_overlap_to_each_other(self): self.openTestHtml(enabled=True) self._test_handle_tilt_when_carets_overlap_to_each_other(self._input, self.assertEqual) ######################################################################## # <input> test cases with selection carets disabled ######################################################################## def test_input_long_press_to_select_a_word_disabled(self): self.openTestHtml(enabled=False) self._test_long_press_to_select_a_word(self._input, self.assertNotEqual) def test_input_move_selection_carets_disabled(self): self.openTestHtml(enabled=False) self._test_move_selection_carets(self._input, self.assertNotEqual) ######################################################################## # <textarea> test cases with selection carets enabled ######################################################################## def test_textarea_long_press_to_select_a_word(self): self.openTestHtml(enabled=True) self._test_long_press_to_select_a_word(self._textarea, self.assertEqual) def test_textarea_move_selection_carets(self): self.openTestHtml(enabled=True) self._test_move_selection_carets(self._textarea, self.assertEqual) def test_textarea_minimum_select_one_character(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._textarea, self.assertEqual) def test_textarea_focus_obtained_by_long_press_from_input(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._input, self._textarea) def test_textarea_focus_obtained_by_long_press_from_contenteditable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._contenteditable, self._textarea) def test_textarea_focus_obtained_by_long_press_from_content_non_editable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._content, self._textarea) def test_textarea_handle_tilt_when_carets_overlap_to_each_other(self): self.openTestHtml(enabled=True) self._test_handle_tilt_when_carets_overlap_to_each_other(self._textarea, self.assertEqual) ######################################################################## # <textarea> test cases with selection carets disabled ######################################################################## def test_textarea_long_press_to_select_a_word_disabled(self): self.openTestHtml(enabled=False) self._test_long_press_to_select_a_word(self._textarea, self.assertNotEqual) def test_textarea_move_selection_carets_disable(self): self.openTestHtml(enabled=False) self._test_move_selection_carets(self._textarea, self.assertNotEqual) ######################################################################## # <textarea> right-to-left test cases with selection carets enabled ######################################################################## def test_textarea_rtl_long_press_to_select_a_word(self): self.openTestHtml(enabled=True) self._test_long_press_to_select_a_word(self._textarea_rtl, self.assertEqual) def test_textarea_rtl_move_selection_carets(self): self.openTestHtml(enabled=True) self._test_move_selection_carets(self._textarea_rtl, self.assertEqual) def test_textarea_rtl_minimum_select_one_character(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._textarea_rtl, self.assertEqual) ######################################################################## # <textarea> right-to-left test cases with selection carets disabled ######################################################################## def test_textarea_rtl_long_press_to_select_a_word_disabled(self): self.openTestHtml(enabled=False) self._test_long_press_to_select_a_word(self._textarea_rtl, self.assertNotEqual) def test_textarea_rtl_move_selection_carets_disabled(self): self.openTestHtml(enabled=False) self._test_move_selection_carets(self._textarea_rtl, self.assertNotEqual) ######################################################################## # <div> contenteditable test cases with selection carets enabled ######################################################################## def test_contenteditable_long_press_to_select_a_word(self): self.openTestHtml(enabled=True) self._test_long_press_to_select_a_word(self._contenteditable, self.assertEqual) def test_contenteditable_move_selection_carets(self): self.openTestHtml(enabled=True) self._test_move_selection_carets(self._contenteditable, self.assertEqual) def test_contenteditable_minimum_select_one_character(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._contenteditable, self.assertEqual) def test_contenteditable_focus_obtained_by_long_press_from_input(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._input, self._contenteditable) def test_contenteditable_focus_obtained_by_long_press_from_textarea(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._textarea, self._contenteditable) def test_contenteditable_focus_obtained_by_long_press_from_content_non_editable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._content, self._contenteditable) def test_contenteditable_handle_tilt_when_carets_overlap_to_each_other(self): self.openTestHtml(enabled=True) self._test_handle_tilt_when_carets_overlap_to_each_other(self._contenteditable, self.assertEqual) ######################################################################## # <div> contenteditable test cases with selection carets disabled ######################################################################## def test_contenteditable_long_press_to_select_a_word_disabled(self): self.openTestHtml(enabled=False) self._test_long_press_to_select_a_word(self._contenteditable, self.assertNotEqual) def test_contenteditable_move_selection_carets_disabled(self): self.openTestHtml(enabled=False) self._test_move_selection_carets(self._contenteditable, self.assertNotEqual) ######################################################################## # <div> non-editable test cases with selection carets enabled ######################################################################## def test_content_non_editable_minimum_select_one_character_by_selection(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._content, self.assertEqual) def test_content_non_editable_focus_obtained_by_long_press_from_input(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._input, self._content) def test_content_non_editable_focus_obtained_by_long_press_from_textarea(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._textarea, self._content) def test_content_non_editable_focus_obtained_by_long_press_from_contenteditable(self): self.openTestHtml(enabled=True) self._test_focus_obtained_by_long_press(self._contenteditable, self._content) def test_content_non_editable_handle_tilt_when_carets_overlap_to_each_other(self): self.openTestHtml(enabled=True) self._test_handle_tilt_when_carets_overlap_to_each_other(self._content, self.assertEqual) ######################################################################## # <div> contenteditable2 test cases with selection carets enabled ######################################################################## def test_contenteditable_minimum_select_one_character(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(self._contenteditable2, self.assertEqual)
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 SelectionCaretsMultipleRangeTest(MarionetteTestCase): _long_press_time = 1 # 1 second def setUp(self): # Code to execute before a tests are run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette) def openTestHtml(self, enabled=True): # Open html for testing and enable selectioncaret and # non-editable support self.marionette.execute_script( 'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' % ('true' if enabled else 'false')) self.marionette.execute_script( 'SpecialPowers.setBoolPref("selectioncaret.noneditable", %s);' % ('true' if enabled else 'false')) test_html = self.marionette.absolute_url( 'test_selectioncarets_multiplerange.html') self.marionette.navigate(test_html) self._body = self.marionette.find_element(By.ID, 'bd') self._sel3 = self.marionette.find_element(By.ID, 'sel3') self._sel4 = self.marionette.find_element(By.ID, 'sel4') self._sel6 = self.marionette.find_element(By.ID, 'sel6') self._nonsel1 = self.marionette.find_element(By.ID, 'nonsel1') def _long_press_without_contextmenu(self, el, x, y): return self.actions.press(el, x, y).move_by_offset(0, 0).\ wait(self._long_press_time).release() def _long_press_to_select_word(self, el, wordOrdinal): sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue( wordOrdinal < len(words), 'Expect at least %d words in the content.' % wordOrdinal) # Calc offset offset = 0 for i in range(wordOrdinal): offset += (len(words[i]) + 1) # Move caret inside the word. el.tap() sel.move_caret_to_front() sel.move_caret_by_offset(offset) x, y = sel.caret_location() # Long press the caret position. Selection carets should appear, and the # word will be selected. On Windows, those spaces after the word # will also be selected. self._long_press_without_contextmenu(el, x, y).perform() def _to_unix_line_ending(self, s): """Changes all Windows/Mac line endings in s to UNIX line endings.""" return s.replace('\r\n', '\n').replace('\r', '\n') def test_long_press_to_select_non_selectable_word(self): '''Testing long press on non selectable field. We should not select anything when long press on non selectable fields.''' self.openTestHtml(enabled=True) halfY = self._nonsel1.size['height'] / 2 self._long_press_without_contextmenu(self._nonsel1, 0, halfY).perform() sel = SelectionManager(self._nonsel1) range_count = sel.range_count() self.assertEqual(range_count, 0) def test_drag_caret_over_non_selectable_field(self): '''Testing drag caret over non selectable field. So that the selected content should exclude non selectable field and end selection caret should appear in last range's position.''' self.openTestHtml(enabled=True) # Select target element and get target caret location self._long_press_to_select_word(self._sel4, 3) sel = SelectionManager(self._body) (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location() self._long_press_to_select_word(self._sel6, 0) (_, _), (end_caret2_x, end_caret2_y) = sel.selection_carets_location() # Select start element self._long_press_to_select_word(self._sel3, 3) # Drag end caret to target location (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(self._body, caret2_x, caret2_y, end_caret_x, end_caret_y, 1).perform() self.assertEqual( self._to_unix_line_ending(sel.selected_content.strip()), 'this 3\nuser can select this') (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(self._body, caret2_x, caret2_y, end_caret2_x, end_caret2_y, 1).perform() self.assertEqual( self._to_unix_line_ending(sel.selected_content.strip()), 'this 3\nuser can select this 4\nuser can select this 5\nuser')
class SelectionCaretsMultipleRangeTest(MarionetteTestCase): _long_press_time = 1 # 1 second def setUp(self): # Code to execute before a tests are run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette) def openTestHtml(self, enabled=True): # Open html for testing and enable selectioncaret and # non-editable support self.marionette.execute_script( 'SpecialPowers.setBoolPref("selectioncaret.enabled", %s);' % ('true' if enabled else 'false')) self.marionette.execute_script( 'SpecialPowers.setBoolPref("selectioncaret.noneditable", %s);' % ('true' if enabled else 'false')) test_html = self.marionette.absolute_url('test_selectioncarets_multiplerange.html') self.marionette.navigate(test_html) self._body = self.marionette.find_element(By.ID, 'bd') self._sel3 = self.marionette.find_element(By.ID, 'sel3') self._sel4 = self.marionette.find_element(By.ID, 'sel4') self._sel6 = self.marionette.find_element(By.ID, 'sel6') self._nonsel1 = self.marionette.find_element(By.ID, 'nonsel1') def _long_press_without_contextmenu(self, el, x, y): return self.actions.press(el, x, y).move_by_offset(0, 0).\ wait(self._long_press_time).release() def _long_press_to_select_word(self, el, wordOrdinal): sel = SelectionManager(el) original_content = sel.content words = original_content.split() self.assertTrue(wordOrdinal < len(words), 'Expect at least %d words in the content.' % wordOrdinal) # Calc offset offset = 0 for i in range(wordOrdinal): offset += (len(words[i]) + 1) # Move caret inside the word. el.tap() sel.move_caret_to_front() sel.move_caret_by_offset(offset) x, y = sel.caret_location() # Long press the caret position. Selection carets should appear, and the # word will be selected. On Windows, those spaces after the word # will also be selected. self._long_press_without_contextmenu(el, x, y).perform() def _to_unix_line_ending(self, s): """Changes all Windows/Mac line endings in s to UNIX line endings.""" return s.replace('\r\n', '\n').replace('\r', '\n') def test_long_press_to_select_non_selectable_word(self): '''Testing long press on non selectable field. We should not select anything when long press on non selectable fields.''' self.openTestHtml(enabled=True) halfY = self._nonsel1.size['height'] / 2 self._long_press_without_contextmenu(self._nonsel1, 0, halfY).perform() sel = SelectionManager(self._nonsel1) range_count = sel.range_count() self.assertEqual(range_count, 0) def test_drag_caret_over_non_selectable_field(self): '''Testing drag caret over non selectable field. So that the selected content should exclude non selectable field and end selection caret should appear in last range's position.''' self.openTestHtml(enabled=True) # Select target element and get target caret location self._long_press_to_select_word(self._sel4, 3) sel = SelectionManager(self._body) (_, _), (end_caret_x, end_caret_y) = sel.selection_carets_location() self._long_press_to_select_word(self._sel6, 0) (_, _), (end_caret2_x, end_caret2_y) = sel.selection_carets_location() # Select start element self._long_press_to_select_word(self._sel3, 3) # Drag end caret to target location (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(self._body, caret2_x, caret2_y, end_caret_x, end_caret_y, 1).perform() self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), 'this 3\nuser can select this') (caret1_x, caret1_y), (caret2_x, caret2_y) = sel.selection_carets_location() self.actions.flick(self._body, caret2_x, caret2_y, end_caret2_x, end_caret2_y, 1).perform() self.assertEqual(self._to_unix_line_ending(sel.selected_content.strip()), 'this 3\nuser can select this 4\nuser can select this 5\nuser')
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