def tap_portrait_crop(self): element = Wait(self.marionette).until( expected.element_present(*self._crop_portrait_locator)) Wait(self.marionette).until(expected.element_displayed(element)) element.tap() Wait(self.marionette).until( lambda m: 'selected' in element.get_attribute('class'))
def launch(self, airplane_mode=False): Base.launch(self) power = Wait(self.marionette).until( expected.element_present(*self._power_button_locator)) if not airplane_mode: Wait(self.marionette).until( lambda m: power.get_attribute('data-enabled') == 'true')
def __init__(self, marionette): Base.__init__(self, marionette) # wait for the pop up screen to open view = Wait(self.marionette).until(expected.element_present(*self._iframe_locator)) self.marionette.switch_to_frame(view) # wait for the page to load email = Wait(self.marionette).until(expected.element_present(*self._email_locator)) Wait(self.marionette).until(lambda m: email.get_attribute("value") != "")
def __init__(self, marionette): Base.__init__(self, marionette) # wait for the pop up screen to open view = Wait(self.marionette).until( expected.element_present(*self._iframe_locator)) self.marionette.switch_to_frame(view) # wait for the page to load email = Wait(self.marionette).until( expected.element_present(*self._email_locator)) Wait(self.marionette).until(lambda m: email.get_attribute('value') != '')
def tap_next(self): next = Wait(self.marionette).until(expected.element_present(*self._next_locator)) Wait(self.marionette).until(lambda m: next.get_attribute('disabled') != 'true') next.tap() account = Wait(self.marionette).until( expected.element_present(*self._account_prefs_section_locator)) Wait(self.marionette).until(lambda m: account.location['x'] == 0) Wait(self.marionette, timeout=120).until(expected.element_displayed( Wait(self.marionette, timeout=120).until(expected.element_present( *self._account_prefs_next_locator))))
def __init__(self, marionette): Base.__init__(self, marionette) self.marionette.switch_to_frame() # wait for the pop up screen to open view = Wait(self.marionette, timeout=60).until( expected.element_present(*self._iframe_locator)) Wait(self.marionette).until(expected.element_displayed(view)) # Change the app to make use of the Facebook developer appId Wait(self.marionette, timeout=60).until(lambda m: view.get_attribute('data-url') != 'about:blank') # Desktop b2g uses this str = view.get_attribute('data-url').replace('123456', '323630664378726') # Device uses this str = str.replace('395559767228801', '323630664378726') self.marionette.switch_to_frame(view) # Wait until the original page has loaded a bit, because sometimes, # trying to load the 2nd page directly after the first, causes a blank page Wait(self.marionette, timeout=60).until(expected.element_present(*self._div_locator)) self.marionette.navigate(str) Wait(self.marionette, timeout=60).until(expected.element_present(*self._email_locator))
def enter_email(self, email=None): self.marionette.switch_to_frame() iframe = Wait(self.marionette, timeout=60).until( expected.element_present(*self._iframe_locator)) Wait(self.marionette).until(expected.element_displayed(iframe)) Wait(self.marionette, timeout=60).until(lambda m: iframe.get_attribute('data-url') != 'about:blank') self.marionette.switch_to_frame(iframe) input = Wait(self.marionette, timeout=60).until( expected.element_present(*self._input_locator)) Wait(self.marionette).until(expected.element_displayed(input)) input.send_keys(email) # Wait until the keyboard is completely displayed, otherwise tapping # the next button is unreliable self.marionette.switch_to_frame() Wait(self.marionette).until(lambda m: self.keyboard.is_keyboard_displayed) self.marionette.switch_to_frame(iframe) self.marionette.find_element(*self._next_locator).tap()
def enter_email(self, email=None): self.marionette.switch_to_frame() iframe = Wait(self.marionette, timeout=60).until( expected.element_present(*self._iframe_locator)) Wait(self.marionette).until(expected.element_displayed(iframe)) Wait(self.marionette, timeout=60).until( lambda m: iframe.get_attribute('data-url') != 'about:blank') self.marionette.switch_to_frame(iframe) input = Wait(self.marionette, timeout=60).until( expected.element_present(*self._input_locator)) Wait(self.marionette).until(expected.element_displayed(input)) input.send_keys(email) # Wait until the keyboard is completely displayed, otherwise tapping # the next button is unreliable self.marionette.switch_to_frame() Wait(self.marionette).until( lambda m: self.keyboard.is_keyboard_displayed) self.marionette.switch_to_frame(iframe) self.marionette.find_element(*self._next_locator).tap()
def wallpaper_preview_src(self): element = Wait(self.marionette).until( expected.element_present(*self._wallpaper_preview_locator)) Wait(self.marionette).until(expected.element_displayed(element)) return element.get_attribute('src')
class HTML5Player(PageRegion): """Represents HTML5 Player. Reference: http://www.w3.org/TR/2012/WD-html5-20121025/media-elements.html#media-element """ _video_element_locator = (By.TAG_NAME, 'video') def __init__(self, marionette): Base.__init__(self, marionette) self.root_element = Wait(self.marionette).until( expected.element_present(*self._video_element_locator)) Wait(self.marionette).until(expected.element_displayed(self.root_element)) def wait_for_video_loaded(self): # Wait long enough to make sure enough of the video has been loaded Wait(self.marionette, timeout=60).until( lambda m: int(self.root_element.get_attribute('readyState')) == 4) @property def is_fullscreen(self): return self.marionette.execute_script("""return document.mozFullScreenElement == document.getElementsByTagName("video")[0]""") @property def is_playing(self): return self.root_element.get_attribute('paused') != 'true' @property def is_muted(self): return self.root_element.get_attribute('muted') == 'true' @property def is_ended(self): return self.root_element.get_attribute('ended') == 'true' @property def controls_visible(self): return (int(self.get_location('playButton')[0]) > 0) def invoke_controls(self): Wait(self.marionette).until(lambda m: self.controls_visible is False) self.root_element.tap() Wait(self.marionette).until(lambda m: self.controls_visible) def show_controls(self): Wait(self.marionette).until(lambda m: self.controls_visible is False) self.marionette.execute_script(""" var a = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"] .getService(SpecialPowers.Ci.inIDOMUtils) .getChildrenForNode(document.getElementsByTagName('video')[0], true); var x = a[1].ownerDocument.getAnonymousElementByAttribute(a[1],'class', 'controlBar'); x.removeAttribute('hidden'); """) Wait(self.marionette).until(lambda m: self.controls_visible) def get_location(self, class_name): return self.marionette.execute_script(""" var a = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"] .getService(SpecialPowers.Ci.inIDOMUtils) .getChildrenForNode(document.getElementsByTagName('video')[0], true); var x1 = document.getElementsByTagName('video')[0].getBoundingClientRect().left; var x2 = a[1].ownerDocument .getAnonymousElementByAttribute(a[1],'class', '%s') .getBoundingClientRect().left; var y1 = document.getElementsByTagName('video')[0] .getBoundingClientRect().top; var y2 = a[1].ownerDocument.getAnonymousElementByAttribute(a[1],'class', '%s') .getBoundingClientRect().top; return (Math.floor(x2-x1) + ',' + Math.floor(y2-y1)); """ % (class_name, class_name)).split(',') def tap_video_control(self, class_name): location = self.get_location(class_name) if location[0] <= 0 or location[1] <= 0: print 'x=%d, y=%d' % (location[0], location[1]) self.assertTrue(False) self.root_element.tap(x=int(location[0])+5, y=int(location[1])+5) def tap_play(self): self.tap_video_control('playButton') Wait(self.marionette).until(lambda m: self.is_playing is True) # Tapping the play button makes the controls disappear, wait for that to happen Wait(self.marionette).until(lambda m: self.controls_visible is False) def tap_pause(self): self.tap_video_control('playButton') Wait(self.marionette).until(lambda m: self.is_playing is False) def tap_mute(self): self.tap_video_control('muteButton') Wait(self.marionette).until(lambda m: self.is_muted is True) def tap_unmute(self): self.tap_video_control('muteButton') Wait(self.marionette).until(lambda m: self.is_muted is False) def tap_full_screen(self): self.tap_video_control('fullscreenButton') def is_video_playing(self): # test that newer timestamp has greater value than previous one tstart = self.current_timestamp time.sleep(2) return tstart < self.current_timestamp @property def current_timestamp(self): return float(self.root_element.get_attribute('currentTime'))
def tap_portrait_crop(self): element = Wait(self.marionette).until(expected.element_present(*self._crop_portrait_locator)) Wait(self.marionette).until(expected.element_displayed(element)) element.tap() Wait(self.marionette).until(lambda m: "selected" in element.get_attribute("class"))
def wait_for_radio_off(self): power = Wait(self.marionette).until( expected.element_present(*self._power_button_locator)) Wait(self.marionette).until( lambda m: not power.get_attribute('data-enabled') == 'true')
def launch(self, airplane_mode=False): Base.launch(self) power = Wait(self.marionette).until( expected.element_present(*self._power_button_locator)) if not airplane_mode: Wait(self.marionette).until(lambda m: power.get_attribute('data-enabled') == 'true')