def edge_scroll(marionette, 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.rect['width'] dist *= -1 # travel opposite direction limit = dist * frame.rect['width'] dist_unit = limit * time_increment assert isinstance(marionette, object) action = Actions(marionette) action.press(frame, start_x, frame.rect['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() time.sleep(2) # compensate for the time taken for edge scroll to bring another app to active return action
def double_tap_image(self): image = self.marionette.find_element(*self._current_image_locator) action = Actions(self.marionette) action.double_tap(image) action.perform()
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 add_minute(self): current = self._current(self._minutes_picker_locator) minute = self.minute Actions(self.marionette).press(current).wait(0.2).move_by_offset( 0, -3 * current.rect['height']).wait(0.4).release().perform() Wait(self.marionette).until(lambda m: self.minute != minute)
def wait(self, seconds: int): actions = Actions(self.marionette) actions.wait(seconds).perform()
def clear_phone_number(self): delete_button = self.marionette.find_element( *self._keypad_delete_locator) Actions(self.marionette).long_press(delete_button, 1).perform()
def click(self): action = Actions(driver) action.click(self) action.perform()
def tap_play(self): play = Wait(self.marionette).until( expected.element_present(*self._play_control_locator)) # TODO: Change this to a simple tap when bug 862156 is fixed Actions(self.marionette).tap(play).perform() return PlayerView(self.marionette)
def setUp(self): # Code to execute before a tests are run. MarionetteTestCase.setUp(self) self.actions = Actions(self.marionette)
def __init__(self, parent): self.parent = parent self.marionette = parent.marionette self.actions = Actions(self.marionette)
def cnet(client): global dl_dir_abs url = 'http://download.cnet.com/' elementExists = True try: client.navigate(url) except timeout as texp: log.info("ignoring timeout: %s" % str(texp)) pass element = client.find_element(By.ID, 'pop') elementList = element.find_elements(By.TAG_NAME, 'a') if (len(elementList) == 0): log.critical('no links found! cnet() function broken?') return Status.CRIT, None # remove blacklisted downloads # added self-link ("most-popular") to blacklist whiteList = [ i for i in elementList if not any(b in i.get_attribute('href') for b in blacklist_dls) ] log.info("dls: %s" % str([i.get_attribute('href') for i in whiteList])) # select at random element = choice(whiteList) nextUrl = element.get_attribute('href') # random delay sleep(randint(1, 5)) # open next page in dl process if nextUrl.startswith('/'): nextUrl = url + nextUrl try: client.navigate(nextUrl) except timeout as texp: log.info("ignoring timeout: %s" % str(texp)) pass # random delay sleep(randint(1, 5)) # click on donwload button element = client.find_element(By.CSS_SELECTOR, 'a.dln-a') finalUrl = None try: finalUrl = element.get_attribute('data-href') except errors.MarionetteException: log.warn('error on finalUrl.') return Status.NODL, None if finalUrl is None: log.warn('no finalUrl.') return Status.NODL, None action = Actions(client) action.click(element) assert (dl_dir_abs is not None) file_list = os.listdir(dl_dir_abs) log.info("files: %s" % str(file_list)) action.perform() # wait until dl finishes fn = wait_for_dl_to_finish(dl_dir_abs, file_list, nextUrl, client) # hash downloaded file log.info('-----------------------') if fn is not None: tordl_hash = sha256sum(fn) log.info("file %s downloaded successfully from %s, hash: %s" % (fn, finalUrl, sha256sum(fn))) else: return Status.NODL, None # dl same file over normal internet r = requests.get(finalUrl) soup = BeautifulSoup.BeautifulSoup(r.text) result = soup.find("meta", attrs={"http-equiv": "refresh"}) dl_url = None if result: wait, text = result["content"].split(";") sleep(int(wait)) dl_url = '='.join(text.split('=')[1:]).strip() if dl_url.startswith('/'): dl_url = url + dl_url else: dl_url = finalUrl log.info("file url %s" % dl_url) r = requests.get(dl_url) fo = open('test.exe', 'wb') fo.write(r.content) fo.close() # hash clearnet-downloaded file orig_hash = sha256sum('test.exe') if orig_hash == tordl_hash: return Status.IDENTICAL, fn else: return Status.NONIDENT, fn
def context_click(self): action = Actions(driver) action.context_click(self) action.perform()
def middle_click(self): action = Actions(driver) action.middle_click(self) action.perform()
def _tap_page_switching_key(self, val): locator = (self._page_switching_key_locator[0], self._page_switching_key_locator[1] % val) key = Wait(self.marionette).until(expected.element_present(*locator)) Wait(self.marionette).until(expected.element_displayed(key)) Actions(self.marionette).press(key).release().perform()
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 long_tap_to_install(self): Actions(self.marionette).long_press(self.root_element, 2).perform()
def setUp(self): # Code to execute before a test is being run. super(CommonCaretTestCase, self).setUp() self.actions = Actions(self.marionette)
def _start_long_press_action(self): self.marionette.execute_script('arguments[0].scrollIntoView(false);', [self.root_element]) return Actions(self.marionette).\ press(self.root_element).\ wait(3)
def tap_play(self): play_button = self.marionette.find_element(*DOM.Music.controls_play) # TODO: Change this to a simple tap when bug 862156 is fixed Actions(self.marionette).tap(play_button).perform()