def expandEnhancedOptions(self, notchElem=None): if notchElem == None: notchElem = self.getGhosteryNotch() start = self.centerLocation(notchElem) end = {'x': start['x'], 'y': 50} notchElem.click() TA(self.settings.driver).long_press(x=start['x'], y=start['y'], duration=1)\ .move_to(x=end['x'], y=end['y'])\ .release().perform()
def close(self, action='click'): if self.is_drawer_visible(): if not main.is_desktop(): # ios: Base coordinates off window.innerWidth/innerHeight # y position needs to be lower than browser header web_width = self.driver.execute_script('return window.innerWidth') click_x = web_width - 10 click_y = 100 duration = 100 # milliseconds # Android: TA only works in NATIVE view if main.is_android(): # go to native context main.native_context(self.driver) # use native dimensions (different from webview dimensions) native_dimensions = self.driver.get_window_size() native_width = native_dimensions['width'] click_x = native_width - 10 # needs bigger value than WEBVIEW (to avoid clicking URL) click_y = 300 if action == 'click': # Either option should work # position = [(click_x, click_y)] # self.driver.tap(position, duration) TA(self.driver).tap(x=click_x, y=click_y).perform() # 2nd click opens /account-detail on iOS native # TA(self.driver).tap(x=click_x, y=click_y).perform() elif action == 'swipe': # Either option should work # second set of coordinates are RELATIVE to click position # self.driver.swipe(click_x, click_y, -300, 0, duration) TA(self.driver).press(x=click_x, y=click_y).wait( duration).move_to(x=-200, y=0).release().perform() # back to webview context if main.is_android(): main.webview_context(self.driver) # wait until drawer disappears WDW(self.driver, 10).until(lambda x: not self.is_profile_loaded()) else: # Press escape self.toggle_button.click()
def ios_scroll(self, direction, pixels): """Use TouchActions to scroll given amount up or down (ios) Note: cannot use TA on android w/out switching to native context""" if main.is_ios(): prefix = '-' if direction.lower() == 'up': prefix = '' move_amount = int(prefix + str(pixels)) TA(self.driver).press(None, 10, 400).move_to( None, 0, move_amount).release().perform() time.sleep(.6)
def mobileScroll(self, start=None, end=None, direction="", count=1): if start == None: screenSize = self.getScreenSize() start = { 'x': screenSize['width'] / 2, 'y': screenSize['height'] / 2 } offset = 150 if self.settings.device_type != "default" else 50 if end == None and direction == "": raise ScriptFailure("Enter End Point or a Direction.") elif end == None and direction != "": if direction.lower() == "up": end = { 'x': start['x'], 'y': start['y'] - offset if self.isPlatform("ios") else offset } elif direction.lower() == "down": end = {'x': start['x'], 'y': start['y'] + offset} elif direction.lower() == "left": start = { 'x': screenSize['width'] - 1, 'y': screenSize['height'] / 2 } end = {'x': 1, 'y': start['y']} elif direction.lower() == "right": start = {'x': 1, 'y': screenSize['height'] / 2} end = {'x': screenSize['width'] - 1, 'y': start['y']} elif end != None and direction != "": self.log( "End Point will take preference and the direction will be ignored." ) for i in range(0, count): self.log(str(start) + " to " + str(end)) TA(self.settings.driver)\ .press(x=start['x'], y=start['y']).wait(150)\ .move_to(x=end['x'], y=end['y']).wait(150)\ .release().perform()
def longPress(self, elem): loc = self.centerLocation(elem) TA(self.driver).long_press(x=loc['x'], y=loc['y']).release().perform()
def tapOnLoc(self, loc, pressTime=100): TA(self.settings.driver).press( x=loc['x'], y=loc['y']).wait(pressTime).release().perform()
def clickElemCenter(self, elem, pressTime=100): loc = self.centerLocation(elem) TA(self.settings.driver).press( x=loc['x'], y=loc['y']).wait(pressTime).release().perform()