def long_press_action(marionette, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) button = marionette.find_element("id", "button1") action = Actions(marionette) action.long_press(button, 5).perform() wait_for_condition_else_raise(marionette, wait_for_condition, expected, "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 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 scroll(self): action = Actions(self.marionette) for page in self.marionette.find_elements(By.CSS_SELECTOR, '#icongrid > div')[:-1]: self.logger.debug('Swiping to next page of apps') action.flick( page, page.size['width'] / 100 * 90, page.size['width'] / 2, page.size['width'] / 100 * 10, page.size['width'] / 2, 200).perform() MarionetteWait(self.marionette, 30).until( lambda m: page.get_attribute('aria-hidden') or not page.is_displayed()) for page in reversed(self.marionette.find_elements( By.CSS_SELECTOR, '#icongrid > div')[1:]): MarionetteWait(self.marionette, 30).until_not( lambda m: page.get_attribute('aria-hidden') or not page.is_displayed()) self.logger.debug('Swiping to previous page of apps') action.flick( page, page.size['width'] / 100 * 10, page.size['width'] / 2, page.size['width'] / 100 * 90, page.size['width'] / 2, 200).perform()
def double_tap(marionette, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) button = marionette.find_element("id", "button1") action = Actions(marionette) action.double_tap(button).perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
def long_press_action(marionette, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) button = marionette.find_element("id", "button1") action = Actions(marionette) action.long_press(button, 5).perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
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_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
def scroll(self): action = Actions(self.marionette) for page in self.marionette.find_elements(By.CSS_SELECTOR, "#icongrid > div")[:-1]: self.logger.debug("Swiping to next page of apps") action.flick( page, page.size["width"] / 100 * 90, page.size["width"] / 2, page.size["width"] / 100 * 10, page.size["width"] / 2, 200, ).perform() Wait(self.marionette, timeout=30).until( lambda m: page.get_attribute("aria-hidden") or not page.is_displayed() ) for page in reversed(self.marionette.find_elements(By.CSS_SELECTOR, "#icongrid > div")[1:]): Wait(self.marionette, timeout=30).until( lambda m: page.is_displayed() or not page.get_attribute("aria-hidden") ) self.logger.debug("Swiping to previous page of apps") action.flick( page, page.size["width"] / 100 * 10, page.size["width"] / 2, page.size["width"] / 100 * 90, page.size["width"] / 2, 200, ).perform()
def chain_flick(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.flick(button, 0, 0, 0, 200).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('buttonFlick').innerHTML;"))
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_long_press_action(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) button = self.marionette.find_element("id", "mozLinkCopy") action = Actions(self.marionette) action.long_press(button, 5).perform() time.sleep(10) self.assertEqual("ContextEnd", self.marionette.execute_script("return document.getElementById('mozLinkCopy').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_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 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 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 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_mouse_double_tap(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) self.marionette.send_mouse_event(True) button = self.marionette.find_element("id", "mozMouse") action = Actions(self.marionette) action.double_tap(button).perform() time.sleep(15) self.assertEqual("MouseClick2", self.marionette.execute_script("return document.getElementById('mozMouse').innerHTML;"))
def test_chain_flick(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) button = self.marionette.find_element("id", "mozLinkScrollStart") action = Actions(self.marionette) action.flick(button, 0, 0, 0, -250).perform() time.sleep(15) self.assertEqual("End", self.marionette.execute_script("return document.getElementById('mozLinkScroll').innerHTML;")) self.assertEqual("Start", self.marionette.execute_script("return document.getElementById('mozLinkScrollStart').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 test_long_press_action(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) button = self.marionette.find_element("id", "mozLinkCopy") action = Actions(self.marionette) action.long_press(button, 5).perform() time.sleep(10) self.assertEqual( "ContextEnd", self.marionette.execute_script( "return document.getElementById('mozLinkCopy').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 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 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 test_dbtouch(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) self.marionette.send_mouse_event(False) button = self.marionette.find_element("id", "mozMouse") action = Actions(self.marionette) action.double_tap(button).perform() time.sleep(10) self.assertEqual( "TouchEnd2", self.marionette.execute_script( "return document.getElementById('mozMouse').innerHTML;"))
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;"))
def long_press_on_xy_action(marionette, wait_for_condition, expected): testAction = marionette.absolute_url("testAction.html") marionette.navigate(testAction) html = marionette.find_element("tag name", "html") button = marionette.find_element("id", "button1") action = Actions(marionette) # Press the center of the button with respect to html. x = button.location['x'] + button.size['width'] / 2.0 y = button.location['y'] + button.size['height'] / 2.0 action.long_press(html, 5, x, y).perform() wait_for_condition(lambda m: expected in m.execute_script("return document.getElementById('button1').innerHTML;"))
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_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 scroll_app(self, app_name): touch_duration = float(200) apps = gaiatest.GaiaApps(self.marionette) #wait up to 30secs for the elements we want to show up self.marionette.set_search_timeout(30000) if app_name == 'Homescreen': action = Actions(self.marionette) landing_page = self.marionette.find_element('id', 'landing-page') action.flick( landing_page, landing_page.size['width'] / 100 * 90, landing_page.size['width'] / 2, landing_page.size['width'] / 100 * 10, landing_page.size['width'] / 2, touch_duration).perform() first_page = self.marionette.find_elements('css selector', '.page')[0] action.flick( first_page, first_page.size['width'] / 100 * 10, first_page.size['width'] / 2, first_page.size['width'] / 100 * 90, first_page.size['width'] / 2, touch_duration).perform() elif app_name == 'Contacts': name = self.marionette.find_element("css selector", ".contact-item p > strong") MarionetteWait(self.marionette, 30).until(lambda m: name.is_displayed()) smooth_scroll(self.marionette, name, "y", -1, 5000, scroll_back=False) elif app_name == 'Browser': self.marionette.execute_script("return window.wrappedJSObject.Browser.navigate('http://taskjs.org/');", new_sandbox=False) MarionetteWait(self.marionette, 30).until(lambda m: 'http://taskjs.org/' == m.execute_script('return window.wrappedJSObject.Browser.currentTab.url;', new_sandbox=False)) MarionetteWait(self.marionette, 30).until(lambda m: not m.execute_script('return window.wrappedJSObject.Browser.currentTab.loading;', new_sandbox=False)) # check when the tab's document is ready tab_frame = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;") self.marionette.switch_to_frame(tab_frame) MarionetteWait(self.marionette, 30).until(lambda m: m.execute_script('return window.document.readyState;', new_sandbox=False) == 'complete') # we have to fire smooth_scroll from the browser app, so let's go back self.marionette.switch_to_frame() apps.launch(app_name) # since the app is launched, launch will switch us back to the app frame without relaunching tab_dom = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;", new_sandbox=False) smooth_scroll(self.marionette, tab_dom, "y", -1, 5000, scroll_back=True) elif app_name == 'Email': email = self.marionette.find_element("class name", "msg-header-author") MarionetteWait(self.marionette, 30).until(lambda m: email.is_displayed() or not email.get_attribute('hidden')) emails = self.marionette.find_elements("class name", "msg-header-author") #we're dynamically adding these elements from a template, and the first one found is blank. MarionetteWait(self.marionette, 30).until(lambda m: emails[0].get_attribute('innerHTML')) emails = self.marionette.find_elements("class name", "msg-header-author") smooth_scroll(self.marionette, emails[0], "y", -1, 2000, scroll_back=True)
def test_chain_flick(self): testTouch = self.marionette.absolute_url("testAction.html") self.marionette.navigate(testTouch) button = self.marionette.find_element("id", "mozLinkScrollStart") action = Actions(self.marionette) action.flick(button, 0, 0, 0, -250).perform() time.sleep(15) self.assertEqual( "End", self.marionette.execute_script( "return document.getElementById('mozLinkScroll').innerHTML;")) self.assertEqual( "Start", self.marionette.execute_script( "return document.getElementById('mozLinkScrollStart').innerHTML;" ))
def scroll_app(self, app_name): touch_duration = float(200) #wait up to 30secs for the elements we want to show up self.marionette.set_search_timeout(30000) if app_name.lower() == 'homescreen': action = Actions(self.marionette) landing_page = self.marionette.find_element('id', 'landing-page') self.logger.debug('Swiping to first page of apps') action.flick( landing_page, landing_page.size['width'] / 100 * 90, landing_page.size['width'] / 2, landing_page.size['width'] / 100 * 10, landing_page.size['width'] / 2, touch_duration).perform() first_page = self.marionette.find_elements('css selector', '.page')[0] self.logger.debug('Swiping back to home screen') action.flick( first_page, first_page.size['width'] / 100 * 10, first_page.size['width'] / 2, first_page.size['width'] / 100 * 90, first_page.size['width'] / 2, touch_duration).perform() elif app_name.lower() == 'contacts': name = self.marionette.find_element("css selector", ".contact-item p > strong") MarionetteWait(self.marionette, 30).until(lambda m: name.is_displayed()) self.logger.debug('Scrolling through contacts') smooth_scroll(self.marionette, name, "y", -1, 5000, scroll_back=False) elif app_name.lower() == 'browser': tab_dom = self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.dom;", new_sandbox=False) self.logger.debug('Scrolling through browser content') smooth_scroll(self.marionette, tab_dom, "y", -1, 5000, scroll_back=True) elif app_name.lower() == 'email': email = self.marionette.find_element("class name", "msg-header-author") MarionetteWait(self.marionette, 30).until(lambda m: email.is_displayed() or not email.get_attribute('hidden')) emails = self.marionette.find_elements("class name", "msg-header-author") #we're dynamically adding these elements from a template, and the first one found is blank. MarionetteWait(self.marionette, 30).until(lambda m: emails[0].get_attribute('innerHTML')) emails = self.marionette.find_elements("class name", "msg-header-author") self.logger.debug('Scrolling through emails') smooth_scroll(self.marionette, emails[0], "y", -1, 2000, scroll_back=True)
def setUp(self): MarionetteTestCase.setUp(self) if self.marionette.session_capabilities['platformName'] == 'DARWIN': self.mod_key = Keys.META else: self.mod_key = Keys.CONTROL test_html = self.marionette.absolute_url("javascriptPage.html") self.marionette.navigate(test_html) self.reporter_element = self.marionette.find_element("id", "keyReporter") self.reporter_element.click() self.key_action = Actions(self.marionette)
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 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 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 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_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)
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 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_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)
def setUp(self): # Code to execute before a tests are run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette)
def setUp(self): # Code to execute before a test is being run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette) self.original_expiration_time = self.expiration_time
class TouchCaretTest(MarionetteTestCase): _input_selector = (By.ID, 'input') _textarea_selector = (By.ID, 'textarea') _contenteditable_selector = (By.ID, 'contenteditable') _large_expiration_time = 3000 * 20 # 60 seconds def setUp(self): # Code to execute before a test is being run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette) self.original_expiration_time = self.expiration_time def tearDown(self): # Code to execute after a test is being run. self.expiration_time = self.original_expiration_time MarionetteTestCase.tearDown(self) @property def expiration_time(self): 'Return touch caret expiration time in milliseconds.' return self.marionette.execute_script( 'return SpecialPowers.getIntPref("touchcaret.expiration.time");') @expiration_time.setter def expiration_time(self, expiration_time): 'Set touch caret expiration time in milliseconds.' self.marionette.execute_script( 'SpecialPowers.setIntPref("touchcaret.expiration.time", arguments[0]);', script_args=[expiration_time]) def openTestHtml(self, enabled=True, expiration_time=None): '''Open html for testing and locate elements, enable/disable touch caret, and set touch caret expiration time in milliseconds). ''' self.marionette.execute_script( 'SpecialPowers.setBoolPref("touchcaret.enabled", %s);' % ('true' if enabled else 'false')) # Set a larger expiration time to avoid intermittent test failures. if expiration_time is not None: self.expiration_time = expiration_time test_html = self.marionette.absolute_url('test_touchcaret.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._contenteditable = self.marionette.find_element( *self._contenteditable_selector) def _test_move_caret_to_the_right_by_one_character(self, el, assertFunc): sel = SelectionManager(el) content_to_add = '!' target_content = sel.content target_content = target_content[:1] + content_to_add + target_content[ 1:] # Get touch caret (x, y) at position 1 and 2. el.tap() sel.move_caret_to_front() caret0_x, caret0_y = sel.caret_location() touch_caret0_x, touch_caret0_y = sel.touch_caret_location() sel.move_caret_by_offset(1) touch_caret1_x, touch_caret1_y = sel.touch_caret_location() # Tap the front of the input to make touch caret appear. el.tap(caret0_x, caret0_y) # Move touch caret self.actions.flick(el, touch_caret0_x, touch_caret0_y, touch_caret1_x, touch_caret1_y).perform() el.send_keys(content_to_add) assertFunc(target_content, sel.content) def _test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self, el, assertFunc): sel = SelectionManager(el) content_to_add = '!' target_content = sel.content + content_to_add # Tap the front of the input to make touch caret appear. el.tap() sel.move_caret_to_front() el.tap(*sel.caret_location()) # Move touch caret to the bottom-right corner of the element. src_x, src_y = sel.touch_caret_location() dest_x, dest_y = el.size['width'], el.size['height'] self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform() el.send_keys(content_to_add) assertFunc(target_content, sel.content) def _test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self, el, assertFunc): sel = SelectionManager(el) content_to_add = '!' target_content = content_to_add + sel.content # Tap to make touch caret appear. Note: it's strange that when the caret # is at the end, the rect of the caret in <textarea> cannot be obtained. # A bug perhaps. el.tap() sel.move_caret_to_end() sel.move_caret_by_offset(1, backward=True) el.tap(*sel.caret_location()) # Move touch caret to the top-left corner of the input box. src_x, src_y = sel.touch_caret_location() dest_x, dest_y = 0, 0 self.actions.flick(el, src_x, src_y, dest_x, dest_y).perform() el.send_keys(content_to_add) assertFunc(target_content, sel.content) def _test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout( self, el, assertFunc): sel = SelectionManager(el) content_to_add = '!' non_target_content = content_to_add + sel.content # Get touch caret expiration time in millisecond, and convert it to second. timeout = self.expiration_time / 1000.0 # Tap to make touch caret appear. Note: it's strange that when the caret # is at the end, the rect of the caret in <textarea> cannot be obtained. # A bug perhaps. el.tap() sel.move_caret_to_end() sel.move_caret_by_offset(1, backward=True) el.tap(*sel.caret_location()) # Wait until touch caret disappears, then pretend to move it to the # top-left corner of the input box. src_x, src_y = sel.touch_caret_location() dest_x, dest_y = 0, 0 self.actions.wait(timeout).flick(el, src_x, src_y, dest_x, dest_y).perform() el.send_keys(content_to_add) assertFunc(non_target_content, sel.content) ######################################################################## # <input> test cases with touch caret enabled ######################################################################## def test_input_move_caret_to_the_right_by_one_character(self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_the_right_by_one_character( self._input, self.assertEqual) def test_input_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self._input, self.assertEqual) def test_input_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._input, self.assertEqual) def test_input_touch_caret_timeout(self): self.openTestHtml(enabled=True) self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout( self._input, self.assertNotEqual) ######################################################################## # <input> test cases with touch caret disabled ######################################################################## def test_input_move_caret_to_the_right_by_one_character_disabled(self): self.openTestHtml(enabled=False) self._test_move_caret_to_the_right_by_one_character( self._input, self.assertNotEqual) def test_input_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled( self): self.openTestHtml(enabled=False) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._input, self.assertNotEqual) ######################################################################## # <textarea> test cases with touch caret enabled ######################################################################## def test_textarea_move_caret_to_the_right_by_one_character(self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_the_right_by_one_character( self._textarea, self.assertEqual) def test_textarea_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self._textarea, self.assertEqual) def test_textarea_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._textarea, self.assertEqual) def test_textarea_touch_caret_timeout(self): self.openTestHtml(enabled=True) self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout( self._textarea, self.assertNotEqual) ######################################################################## # <textarea> test cases with touch caret disabled ######################################################################## def test_textarea_move_caret_to_the_right_by_one_character_disabled(self): self.openTestHtml(enabled=False) self._test_move_caret_to_the_right_by_one_character( self._textarea, self.assertNotEqual) def test_textarea_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled( self): self.openTestHtml(enabled=False) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._textarea, self.assertNotEqual) ######################################################################## # <div> contenteditable test cases with touch caret enabled ######################################################################## def test_contenteditable_move_caret_to_the_right_by_one_character(self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_the_right_by_one_character( self._contenteditable, self.assertEqual) def test_contenteditable_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_end_by_dragging_touch_caret_to_bottom_right_corner( self._contenteditable, self.assertEqual) def test_contenteditable_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self): self.openTestHtml(enabled=True, expiration_time=self._large_expiration_time) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._contenteditable, self.assertEqual) def test_contenteditable_touch_caret_timeout(self): self.openTestHtml(enabled=True) self._test_touch_caret_timeout_by_dragging_it_to_top_left_corner_after_timout( self._contenteditable, self.assertNotEqual) ######################################################################## # <div> contenteditable test cases with touch caret disabled ######################################################################## def test_contenteditable_move_caret_to_the_right_by_one_character_disabled( self): self.openTestHtml(enabled=False) self._test_move_caret_to_the_right_by_one_character( self._contenteditable, self.assertNotEqual) def test_contenteditable_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner_disabled( self): self.openTestHtml(enabled=False) self._test_move_caret_to_front_by_dragging_touch_caret_to_top_left_corner( self._contenteditable, self.assertNotEqual)
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
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') 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) def _long_press_to_select_first_word(self, el, sel): # Move caret inside the first word. el.tap() sel.move_caret_to_front() sel.move_caret_by_offset(1) x, y = sel.caret_location() # Long press the caret position. Selection carets should appear, and the # first word will be selected. 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. self._long_press_to_select_first_word(el, sel) # 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() self._long_press_to_select_first_word(el, sel) # 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, caret2_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): 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 character. target_content = original_content[0] self._long_press_to_select_first_word(el, sel) # 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) ######################################################################## # <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_caracter(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(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_caracter(self): self.openTestHtml(enabled=True) self._test_minimum_select_one_character(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_caracter(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) ######################################################################## # <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)