def tap_submit(self): el = self.marionette.find_element(*self._submit_locator) from gaiatest.apps.keyboard.app import Keyboard k = Keyboard(self.marionette) # The keyboard can overlay the submit button on desktop b2g, so close it k.dismiss() self.marionette.find_element(*self._submit_locator).tap()
def test_sms_semicolon_completes_the_entered_recipient(self): """ https://moztrap.mozilla.org/manage/case/10925/ """ self.messages = Messages(self.marionette) self.messages.launch() new_message = self.messages.tap_create_new_message() from gaiatest.apps.keyboard.app import Keyboard keyboard = Keyboard(self.marionette) keyboard.send('074') keyboard.send(';') # Verify if recipient is valid and uneditable self.assertNotIn('invalid', new_message.recipient_css_class) self.assertTrue(new_message.is_recipient_name_editable == 'false') keyboard.send('777') keyboard.send(';') self.assertEqual(new_message.number_of_recipients, 2) new_message.tap_message() self.assertEqual(new_message.number_of_recipients, 2) self.marionette.switch_to_frame() self.assertTrue(new_message.keyboard.is_keyboard_displayed)
def test_sms_contact_validation(self): self.messages = Messages(self.marionette) self.messages.launch() new_message = self.messages.tap_create_new_message() from gaiatest.apps.keyboard.app import Keyboard keyboard = Keyboard(self.marionette) keyboard.send('test_contact') keyboard.tap_enter() # Verify if recipient is invalid and uneditable self.assertIn('invalid', new_message.recipient_css_class) self.assertTrue(new_message.is_recipient_name_editable == 'false') new_message.tap_recipient_name() self.assertTrue(new_message.is_recipient_name_editable == 'true') # Type_message will tap in the field to focus it new_message.type_message('Test message') self.assertFalse(new_message.is_send_button_enabled)
def __init__(self, parent): self.apps = parent.apps self.data_layer = parent.data_layer self.parent = parent self.marionette = parent.marionette self.UTILS = parent.UTILS self.actions = Actions(self.marionette) self.keyboard = Keyboard(self.marionette)
def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.keyboard = Keyboard(self.marionette) # Establish which phone number to use. self.phone_number = self.UTILS.general.get_config_variable("phone_number", "custom") self.UTILS.reporting.logComment("Sending sms to telephone number " + self.phone_number)
class test_main(GaiaTestCase): def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.keyboard = Keyboard(self.marionette) # Establish which phone number to use. self.phone_number = self.UTILS.general.get_config_variable("phone_number", "custom") self.UTILS.reporting.logComment("Sending sms to telephone number " + self.phone_number) def tearDown(self): self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): # Launch messages app. self.messages.launch() # Start a new sms. self.messages.startNewSMS() # Enter a number in the target field. self.messages.addNumbersInToField([self.phone_number]) # Enter a message the message area. test_msg = "test message" self.messages.enterSMSMsg(test_msg) # Check the 'Send' button is now enabled. send_btn = self.UTILS.element.getElement(DOM.Messages.send_message_button, "Send message button") self.UTILS.test.test(send_btn.is_enabled(), "Send button is enabled when everything's filled in.") """ Delete the text (we should already be in the message area with the keyboard present, but we need to 'manually' use the keyboard for this). """ for i in range(len(test_msg)): self.keyboard.tap_backspace() self.UTILS.iframe.switchToFrame(*DOM.Messages.frame_locator) msg_area = self.UTILS.element.getElement(DOM.Messages.input_message_area, "Message area") self.UTILS.test.test(msg_area.text == "", "Message area is clear after deleting all characters in it.") # Check the Send button isn't enabled any more. send_btn = self.UTILS.element.getElement(DOM.Messages.send_message_button, "Send message button") self.UTILS.test.test(not send_btn.is_enabled(), "Send button is not enabled after target number is supplied, but message still empty.")
def setUp(self): MarionetteTestCase.setUp(self) self.marionette.__class__ = type('Marionette', (Marionette, MarionetteTouchMixin), {}) self.device = GaiaDevice(self.marionette) if self.restart and (self.device.is_android_build or self.marionette.instance): self.device.stop_b2g() if self.device.is_android_build: # revert device to a clean state self.device.manager.removeDir('/data/local/indexedDB') self.device.manager.removeDir('/data/b2g/mozilla') self.device.start_b2g() self.marionette.setup_touch() # the emulator can be really slow! self.marionette.set_script_timeout(self._script_timeout) self.marionette.set_search_timeout(self._search_timeout) self.lockscreen = LockScreen(self.marionette) self.apps = GaiaApps(self.marionette) self.data_layer = GaiaData(self.marionette, self.testvars) from gaiatest.apps.keyboard.app import Keyboard self.keyboard = Keyboard(self.marionette) self.cleanUp()
def setUp(self): try: MarionetteTestCase.setUp(self) except InvalidResponseException: if self.restart: pass self.device = GaiaDevice(self.marionette, self.testvars) if self.restart and (self.device.is_android_build or self.marionette.instance): self.device.stop_b2g() if self.device.is_android_build: # revert device to a clean state self.device.manager.removeDir('/data/local/storage/persistent') self.device.manager.removeDir('/data/b2g/mozilla') self.device.start_b2g() # the emulator can be really slow! self.marionette.set_script_timeout(self._script_timeout) self.marionette.set_search_timeout(self._search_timeout) self.lockscreen = LockScreen(self.marionette) self.apps = GaiaApps(self.marionette) self.data_layer = GaiaData(self.marionette, self.testvars) from gaiatest.apps.keyboard.app import Keyboard self.keyboard = Keyboard(self.marionette) self.cleanUp()
def create_passcode(self, passcode): # switch to keyboard, input passcode keyboard = Keyboard(self.marionette) keyboard.switch_to_keyboard() for times in range(2): keyboard.send("".join(passcode)) # switch to settings frame self.marionette.switch_to_frame() self.marionette.switch_to_frame(self.apps.displayed_app.frame) # create passcode self.wait_for_element_displayed(*self._phone_lock_passcode_section_locator) self.marionette.find_element(*self._passcode_create_locator).tap() self.wait_for_element_displayed(*self._phone_lock_section_locator)
def tap_number_input(self): number_input = self.marionette.find_element(*self._number_input_locator) self.marionette.execute_script("arguments[0].scrollIntoView(false);", [number_input]) number_input.tap() from gaiatest.apps.keyboard.app import Keyboard return Keyboard(self.marionette)
def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) self.keyboard = Keyboard(self.marionette) self.gmail_user = self.UTILS.general.get_config_variable( "gmail_1_user", "common") self.gmail_passwd = self.UTILS.general.get_config_variable( "gmail_1_pass", "common") self.connect_to_network() # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact)
def test_post_bluetooth(self): lock_screen = LockScreen(self.marionette) homescreen = lock_screen.unlock() settings = Settings(self.marionette) settings.launch() bluetooth_settings = settings.open_bluetooth() self.data_layer.bluetooth_disable() # make sure it starts out disabled self.data_layer.bluetooth_enable() print "Enabled bluetooth" time.sleep(20) # Sometimes the BT device doesn't show up in the list right off. Try and click it, # if we can't then do an actual search and then try to click it again print "First Try" if not bluetooth_settings.tap_device('HC-06'): print "About to search for devices" bluetooth_settings.tap_search_for_devices() time.sleep(1) print "Second Try" if not bluetooth_settings.tap_device('HC-06'): assert False, "Unable to find bluetooth device 'HC-06'..." keyboard = Keyboard(self.marionette) #time.sleep(1) keyboard.send("1234") keyboard.tap_enter() time.sleep(35) print "Attempting to unpair with device" bluetooth_settings.refresh_root_element() if bluetooth_settings.tap_device('HC-06'): print "Confirming unpair" time.sleep(2) bluetooth_settings.tap_confirm_unpair_device() time.sleep(10) print "Device unpaired" print "Done sleep, disabling bluetooth" self.data_layer.bluetooth_disable() print "Disabled bluetooth" self.device.turn_screen_off() print "" print "Running Post Bluetooth Test" self.runPowerTest("post_idle_bluetooth", "Settings", "settings")
def setUp(self): try: MarionetteTestCase.setUp(self) except InvalidResponseException: if self.restart: pass if self.yocto: """ with the yocto ammeter we only get amp measurements so we also need to use the linux kernel voltage device to sample the voltage at the start of each test so we can calculate watts.""" try: self.ammeter = YoctoAmmeter() except: self.ammeter = None self.device = GaiaDevice(self.marionette, self.testvars) if self.device.is_android_build: self.device.add_device_manager( self.get_device_manager( deviceSerial=self.marionette.device_serial)) if self.restart and (self.device.is_android_build or self.marionette.instance): self.device.stop_b2g() if self.device.is_android_build: self.cleanup_data() self.device.start_b2g() # we need to set the default timeouts because we may have a new session if self.marionette.timeout is not None: self.marionette.timeouts(self.marionette.TIMEOUT_SEARCH, self.marionette.timeout) self.marionette.timeouts(self.marionette.TIMEOUT_SCRIPT, self.marionette.timeout) self.marionette.timeouts(self.marionette.TIMEOUT_PAGE, self.marionette.timeout) else: self.marionette.timeouts(self.marionette.TIMEOUT_SEARCH, 10000) self.marionette.timeouts(self.marionette.TIMEOUT_PAGE, 30000) self.lockscreen = LockScreen(self.marionette) self.apps = GaiaApps(self.marionette) self.data_layer = GaiaData(self.marionette, self.testvars) from gaiatest.apps.keyboard.app import Keyboard self.keyboard = Keyboard(self.marionette) if self.device.is_android_build: self.cleanup_sdcard() if self.restart: self.cleanup_gaia(full_reset=False) else: self.cleanup_gaia(full_reset=True)
def test_contact_match(self): # insert contact self.contact = MockContact(tel={ 'value': '555%s' % repr(time.time()).replace('.', '')[8:]}) self.data_layer.insert_contact(self.contact) # launch Messages app self.messages = Messages(self.marionette) self.messages.launch() new_message = self.messages.tap_create_new_message() from gaiatest.apps.keyboard.app import Keyboard keyboard = Keyboard(self.marionette) keyboard.send(self.contact['name']) keyboard.tap_enter() # verify that contacts and tel number match self.assertEqual(self.contact['name'], new_message.first_recipient_name) self.assertEqual(self.contact['tel']['value'], new_message.first_recipient_number_attribute)
def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) self.keyboard = Keyboard(self.marionette) self.gmail_user = self.UTILS.general.get_config_variable("gmail_1_user", "common") self.gmail_passwd = self.UTILS.general.get_config_variable("gmail_1_pass", "common") self.connect_to_network() # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact)
def create_passcode(self, passcode): # switch to keyboard, input passcode keyboard = Keyboard(self.marionette) keyboard.switch_to_keyboard() for times in range(2): keyboard.send("".join(passcode)) # switch to settings frame self.marionette.switch_to_frame() self.marionette.switch_to_frame(self.apps.displayed_app.frame) # create passcode self.wait_for_element_displayed( *self._phone_lock_passcode_section_locator) self.marionette.find_element(*self._passcode_create_locator).tap() self.wait_for_element_displayed(*self._phone_lock_section_locator)
def test_contact_match(self): # insert contact self.contact = MockContact( tel={'value': '555%s' % repr(time.time()).replace('.', '')[8:]}) self.data_layer.insert_contact(self.contact) # launch Messages app self.messages = Messages(self.marionette) self.messages.launch() new_message = self.messages.tap_create_new_message() from gaiatest.apps.keyboard.app import Keyboard keyboard = Keyboard(self.marionette) keyboard.send(self.contact['name']) keyboard.tap_enter() # verify that contacts and tel number match self.assertEqual(self.contact['name'], new_message.first_recipient_name) self.assertEqual(self.contact['tel']['value'], new_message.first_recipient_number_attribute)
def keyboard(self): from gaiatest.apps.keyboard.app import Keyboard return Keyboard(self.marionette)
def test_ftu_skip_tour(self): # https://moztrap.mozilla.org/manage/case/3876/ # 3876, 3879 self.wait_for_element_displayed(*self._section_languages_locator) listed_languages = self.marionette.find_elements( *self._listed_languages_locator) self.assertGreater(len(listed_languages), 0, "No languages listed on screen") # select en-US due to the condition of this test is only for en-US language_item = self.marionette.find_element( *self.create_language_locator("en-US")) language_item.tap() # Tap next self.wait_for_element_displayed(*self._next_button_locator) self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_cell_data_locator) # Tap enable data self.marionette.find_element(*self._enable_data_checkbox_locator).tap() self.wait_for_condition( lambda m: self.data_layer.is_cell_data_connected, message="Cell data was not connected by FTU app") # Tap next self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_wifi_locator) # Wait for some networks to be found self.wait_for_condition(lambda m: len( m.find_elements(*self._found_wifi_networks_locator)) > 0, message="No networks listed on screen") wifi_network = self.marionette.find_element( By.ID, self.testvars['wifi']['ssid']) wifi_network.tap() # This is in the event we are using a Wifi Network that requires a password # We cannot be sure of this thus need the logic if self.testvars['wifi'].get('keyManagement'): self.wait_for_element_displayed(*self._password_input_locator) password = self.marionette.find_element( *self._password_input_locator) password.send_keys(self.testvars['wifi'].get('psk') or self.testvars['wifi'].get('wep')) # Wait for Keyboard app init and be displayed self.wait_for_condition( lambda m: Keyboard(self.marionette).is_displayed()) self.marionette.find_element(*self._join_network_locator).tap() self.wait_for_condition( lambda m: m.find_element(By.ID, self.testvars['wifi']['ssid']). find_element(*self._network_state_locator).text == "Connected") self.assertTrue( self.data_layer.is_wifi_connected(self.testvars['wifi']), "WiFi was not connected via FTU app") # is_wifi_connected() calls switch_to_frame() self.apps.switch_to_displayed_app() # Tap next self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_date_time_locator) # Set timezone continent_select = self.marionette.find_element( *self._timezone_continent_locator) continent_select.tap() self._select("Asia") city_select = self.marionette.find_element( *self._timezone_city_locator) city_select.tap() self._select("Almaty") self.assertEqual( self.marionette.find_element(*self._time_zone_title_locator).text, "UTC+06:00 Asia/Almaty") self.marionette.find_element(*self._next_button_locator).tap() # Verify Geolocation section appears self.wait_for_element_displayed(*self._section_geolocation_locator) # Disable geolocation self.wait_for_element_displayed( *self._enable_geolocation_checkbox_locator) self.marionette.find_element( *self._enable_geolocation_checkbox_locator).tap() self.wait_for_condition( lambda m: not self.data_layer.get_setting('geolocation.enabled'), message="Geolocation was not disabled by the FTU app") self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_import_contacts_locator) # Tap import from SIM # You can do this as many times as you like without db conflict self.marionette.find_element(*self._import_from_sim_locator).tap() # pass third condition when contacts are 0~N self.wait_for_condition( lambda m: self._pattern_contacts.match( m.find_element(*self._sim_import_feedback_locator).text ) is not None, message="Contact did not import from sim before timeout") # Find how many contacts are imported. import_sim_message = self.marionette.find_element( *self._sim_import_feedback_locator).text import_sim_count = None if self._pattern_contacts_0.match(import_sim_message) is not None: import_sim_count = 0 elif self._pattern_contacts_1.match(import_sim_message) is not None: import_sim_count = 1 elif self._pattern_contacts_N.match(import_sim_message) is not None: count = self._pattern_contacts_N.match(import_sim_message).group(1) import_sim_count = int(count) self.assertEqual(len(self.data_layer.all_contacts), import_sim_count) # all_contacts switches to top frame; Marionette needs to be switched back to ftu self.apps.switch_to_displayed_app() # Tap next self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_welcome_browser_locator) # Tap the statistics box and check that it sets a setting # TODO assert via settings API that this is set. Currently it is not used self.marionette.find_element( *self._enable_statistic_checkbox_locator).tap() # Tap next self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_browser_privacy_locator) # Enter a dummy email address and check it set inside the os # TODO assert that this is preserved in the system somewhere. Currently it is not used self.marionette.find_element( *self._email_field_locator).send_keys("*****@*****.**") # Tap next self.marionette.find_element(*self._next_button_locator).tap() self.wait_for_element_displayed(*self._section_finish_locator) # Skip the tour self.marionette.find_element(*self._skip_tour_button_locator).tap() # Switch back to top level now that FTU app is gone self.marionette.switch_to_frame()
class Browser(object): """Object representing the Browser application. """ search_manifest_url = "app://search.gaiamobile.org/manifest.webapp" def __init__(self, parent): self.apps = parent.apps self.data_layer = parent.data_layer self.parent = parent self.marionette = parent.marionette self.UTILS = parent.UTILS self.actions = Actions(self.marionette) self.keyboard = Keyboard(self.marionette) def launch(self): """ Launch the app. """ self.app = self.apps.launch(self.__class__.__name__) self.UTILS.element.waitForNotElements(DOM.GLOBAL.loading_overlay, self.__class__.__name__ + " app - loading overlay") return self.app def open_url(self, url, timeout=30, trusted=True): self.marionette.switch_to_frame() self.parent.wait_for_element_displayed(*DOM.Browser.url_input) url_input = self.marionette.find_element(*DOM.Browser.url_input) url_input.tap() # Now, rocketbar should be displayed self.parent.wait_for_element_displayed(*DOM.Browser.rocket_bar_input) rocket_bar_input = self.marionette.find_element(*DOM.Browser.rocket_bar_input) rocket_bar_input.clear() rocket_bar_input.send_keys(url) self.keyboard.tap_enter() self.marionette.switch_to_frame() self.wait_for_page_to_load() self.switch_to_content() # If the site is trusted, check for the warning and get rid of it. if trusted: # If the untrusted site warning is present, just accept it. Otherwise, silently pass. try: understand = self.marionette.find_element(*DOM.Browser.understand_risks) understand.tap() btn = self.marionette.find_element(*DOM.Browser.add_permanent_exception) btn.tap() except: pass def wait_for_page_to_load(self, timeout=30): self.parent.wait_for_condition(lambda m: m.find_element( *DOM.Browser.browser_app).get_attribute("loading-state") == "false", timeout=timeout) def switch_to_content(self): web_frames = self.marionette.find_elements(*DOM.Browser.frame_locator) for web_frame in web_frames: if web_frame.is_displayed(): self.marionette.switch_to_frame(web_frame) break def switch_to_chrome(self): self.marionette.switch_to_frame() try: app_frame = self.app.frame except AttributeError: app_frame = self.apps.displayed_app.frame self.marionette.switch_to_frame(app_frame) def loaded_url(self): """ Returns the url of the currently loaded web page. """ return self.marionette.find_element(*DOM.Browser.frame_locator).get_attribute("src") ################################################################################ ################################################################################ ################################################################################ def tap_go_button(self, timeout=30): self.marionette.find_element(*DOM.Browser.url_go_button).tap() # TODO wait_for_throbber can resolve before the page has started loading time.sleep(2) try: self.wait_for_throbber_not_visible(timeout=timeout) except: # maybe something went wrong, so try to find the reload button self.switch_to_content() screenshot = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult('info', "Screenshot when failing open_url", screenshot) if self.is_page_not_loaded(): self.retry_load_page() self.switch_to_chrome() self.wait_for_throbber_not_visible(timeout=timeout) self.parent.wait_for_element_displayed(*DOM.Browser.bookmarkmenu_button) self.switch_to_content() def wait_for_throbber_not_visible(self, timeout=30): # TODO see if we can reduce this timeout in the future. >10 seconds is poor UX self.parent.wait_for_condition(lambda m: not self.is_throbber_visible(), timeout=timeout) def is_page_not_loaded(self): try: self.parent.wait_for_element_displayed(*DOM.Browser.embarrasing_tag) self.UTILS.reporting.logResult('info', 'Page not loaded') return True except: self.UTILS.reporting.logResult('info', 'Page loaded') return False def retry_load_page(self): self.parent.wait_for_element_displayed(*DOM.Browser.embarrasing_reload) reload_btn = self.marionette.find_element(*DOM.Browser.embarrasing_reload) reload_btn.tap() def is_throbber_visible(self): return self.marionette.find_element(*DOM.Browser.throbber).get_attribute('class') == 'loading' def switch_to_frame_by_url(self, url, position=0): """ Switch to a frame inside the browser with the given url. The frame with the given url will be switched to. It can be selected the position as well, in case there are more frames for the same url. Returns True if the switch was successful. False otherwise. """ web_frames = self.marionette.find_elements(*DOM.Browser.frame_locator) result = False for web_frame in web_frames: if url in web_frame.get_attribute("src") and web_frame.is_displayed(): result = self.marionette.switch_to_frame(web_frame) break return result def add_current_page_to_bookmarks(self): """ Open the Edit menu and add the current page to the bookmarks list """ self.marionette.switch_to_frame() menu = self.UTILS.element.getElement(DOM.Browser.current_browser_menu, "Current browser window") menu.tap() add_btn = self.UTILS.element.getElement(DOM.Browser.search_add_to_homescreen, "Add to homescreen button") add_btn.tap() self.UTILS.iframe.switchToFrame(*DOM.Browser.bookmark_frame_locator) done_btn = self.UTILS.element.getElement(DOM.Browser.bookmark_done_button, "Add bookmark Done button") done_btn.tap()
class test_main(GaiaTestCase): def __init__(self, *args, **kwargs): kwargs['restart'] = True super(test_main, self).__init__(*args, **kwargs) def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) self.keyboard = Keyboard(self.marionette) self.gmail_user = self.UTILS.general.get_config_variable( "gmail_1_user", "common") self.gmail_passwd = self.UTILS.general.get_config_variable( "gmail_1_pass", "common") self.connect_to_network() # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact) def tearDown(self): self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.contacts.launch() self.contacts.import_gmail_login(self.gmail_user, self.gmail_passwd) # Get the contacts. contact_list = self.UTILS.element.getElements( DOM.Contacts.import_conts_list, "Contact list") gmail_contacts = [] for y in contact_list: gmail_contacts.append(y.get_attribute("data-search")) search_name = gmail_contacts[0][:gmail_contacts[0].index('@')] # Use the search bar to test ... self.marionette.execute_script( "document.getElementById('search-start').click();") self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.iframe.switchToFrame(*DOM.Contacts.gmail_import_frame, via_root_frame=False) self.marionette.execute_script(""" var getElementByXpath = function (path) { return document.evaluate(path, document, null, 9, null).singleNodeValue; }; getElementByXpath("/html/body/section/section[2]/form/p/label").click(); """) self.marionette.switch_to_frame() # Keyboard appears. self.UTILS.element.waitForElements(("xpath", "//iframe[contains(@{},'{}')]".\ format(DOM.Keyboard.frame_locator[0], DOM.Keyboard.frame_locator[1])), "Keyboard") # Typing works and allows real-time filtering. self.UTILS.reporting.logResult("info", "Typing '{}' with the keyboard (without pressing ENTER) ...".\ format(search_name)) self.keyboard.send(search_name) self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.iframe.switchToFrame(*DOM.Contacts.gmail_import_frame, via_root_frame=False) after_search_count = self.UTILS.element.getElements( DOM.Contacts.import_search_list, "Search list") self.UTILS.test.test(len(after_search_count) == 1, "After typing the name '{}' the search list contains 1 contact (out of {}).".\ format(search_name, len(gmail_contacts)))
def tap_recipient_section(self): self.marionette.find_element(*self._recipient_section_locator).tap() from gaiatest.apps.keyboard.app import Keyboard return Keyboard(self.marionette)
class Browser(object): """Object representing the Browser application. """ search_manifest_url = "app://search.gaiamobile.org/manifest.webapp" def __init__(self, parent): self.apps = parent.apps self.data_layer = parent.data_layer self.parent = parent self.marionette = parent.marionette self.UTILS = parent.UTILS self.actions = Actions(self.marionette) self.keyboard = Keyboard(self.marionette) def launch(self): """ Launch the app. """ self.app = self.apps.launch(self.__class__.__name__) self.UTILS.element.waitForNotElements( DOM.GLOBAL.loading_overlay, self.__class__.__name__ + " app - loading overlay") return self.app def open_url(self, url, timeout=30, trusted=True): self.marionette.switch_to_frame() self.parent.wait_for_element_displayed(*DOM.Browser.url_input) url_input = self.marionette.find_element(*DOM.Browser.url_input) url_input.tap() # Now, rocketbar should be displayed self.parent.wait_for_element_displayed(*DOM.Browser.rocket_bar_input) rocket_bar_input = self.marionette.find_element( *DOM.Browser.rocket_bar_input) rocket_bar_input.clear() rocket_bar_input.send_keys(url) self.keyboard.tap_enter() self.marionette.switch_to_frame() self.wait_for_page_to_load() self.switch_to_content() # If the site is trusted, check for the warning and get rid of it. if trusted: # If the untrusted site warning is present, just accept it. Otherwise, silently pass. try: understand = self.marionette.find_element( *DOM.Browser.understand_risks) understand.tap() btn = self.marionette.find_element( *DOM.Browser.add_permanent_exception) btn.tap() except: pass def wait_for_page_to_load(self, timeout=30): self.parent.wait_for_condition( lambda m: m.find_element(*DOM.Browser.browser_app).get_attribute( "loading-state") == "false", timeout=timeout) def switch_to_content(self): web_frames = self.marionette.find_elements(*DOM.Browser.frame_locator) for web_frame in web_frames: if web_frame.is_displayed(): self.marionette.switch_to_frame(web_frame) break def switch_to_chrome(self): self.marionette.switch_to_frame() try: app_frame = self.app.frame except AttributeError: app_frame = self.apps.displayed_app.frame self.marionette.switch_to_frame(app_frame) def loaded_url(self): """ Returns the url of the currently loaded web page. """ return self.marionette.find_element( *DOM.Browser.frame_locator).get_attribute("src") ################################################################################ ################################################################################ ################################################################################ def tap_go_button(self, timeout=30): self.marionette.find_element(*DOM.Browser.url_go_button).tap() # TODO wait_for_throbber can resolve before the page has started loading time.sleep(2) try: self.wait_for_throbber_not_visible(timeout=timeout) except: # maybe something went wrong, so try to find the reload button self.switch_to_content() screenshot = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult('info', "Screenshot when failing open_url", screenshot) if self.is_page_not_loaded(): self.retry_load_page() self.switch_to_chrome() self.wait_for_throbber_not_visible(timeout=timeout) self.parent.wait_for_element_displayed( *DOM.Browser.bookmarkmenu_button) self.switch_to_content() def wait_for_throbber_not_visible(self, timeout=30): # TODO see if we can reduce this timeout in the future. >10 seconds is poor UX self.parent.wait_for_condition( lambda m: not self.is_throbber_visible(), timeout=timeout) def is_page_not_loaded(self): try: self.parent.wait_for_element_displayed( *DOM.Browser.embarrasing_tag) self.UTILS.reporting.logResult('info', 'Page not loaded') return True except: self.UTILS.reporting.logResult('info', 'Page loaded') return False def retry_load_page(self): self.parent.wait_for_element_displayed(*DOM.Browser.embarrasing_reload) reload_btn = self.marionette.find_element( *DOM.Browser.embarrasing_reload) reload_btn.tap() def is_throbber_visible(self): return self.marionette.find_element( *DOM.Browser.throbber).get_attribute('class') == 'loading' def switch_to_frame_by_url(self, url, position=0): """ Switch to a frame inside the browser with the given url. The frame with the given url will be switched to. It can be selected the position as well, in case there are more frames for the same url. Returns True if the switch was successful. False otherwise. """ web_frames = self.marionette.find_elements(*DOM.Browser.frame_locator) result = False for web_frame in web_frames: if url in web_frame.get_attribute( "src") and web_frame.is_displayed(): result = self.marionette.switch_to_frame(web_frame) break return result def add_current_page_to_bookmarks(self): """ Open the Edit menu and add the current page to the bookmarks list """ self.marionette.switch_to_frame() menu = self.UTILS.element.getElement(DOM.Browser.current_browser_menu, "Current browser window") menu.tap() add_btn = self.UTILS.element.getElement( DOM.Browser.search_add_to_homescreen, "Add to homescreen button") add_btn.tap() self.UTILS.iframe.switchToFrame(*DOM.Browser.bookmark_frame_locator) done_btn = self.UTILS.element.getElement( DOM.Browser.bookmark_done_button, "Add bookmark Done button") done_btn.tap()
class general(object): def __init__(self, parent): self.parent = parent self.marionette = parent.marionette self.keyboard = Keyboard(self.marionette) def add_file_to_device(self, file_name, count=1): """ Put a file onto the device (path is relative to the dir you are physically in when running the tests). """ self.parent.device.file_manager.push_file( local_path=file_name, remote_path=self.parent.device.storage_path, count=count) def checkMarionetteOK(self): """ Sometimes marionette session 'vanishes', so this makes sure we have one still. <b>NOTE: </b>This leaves you in the 'top -level' iframe, so you'll need to navigate back to your frame after running this. """ try: self.marionette.start_session() self.parent.reporting.logResult("debug", "<i>(*** The Marionette session was " "restarted due to a possible crash. ***)</i>") except: self.parent.reporting.logResult('debug', "Marionette session still running") pass self.parent.parent.apps.switch_to_displayed_app() def clearGeolocPermission(self, allow_geoloc=False): """ This method clears the Geolocation permission dialog (if necessary) with allow_geoloc. """ permission_yes = ("id", "permission-yes") permission_no = ("id", "permission-no") orig_frame = self.parent.iframe.currentIframe() self.marionette.switch_to_frame() try: if allow_geoloc: self.parent.parent.wait_for_element_displayed(*permission_yes, timeout=2) x = self.marionette.find_element(*permission_yes) else: self.parent.parent.wait_for_element_displayed(*permission_no, timeout=2) x = self.marionette.find_element(*permission_no) x.tap() except: pass self.parent.iframe.switchToFrame("src", orig_frame) def get_current_date_string(self): """Return the current date as a formatted string, to include it in logs, SMS bodies, etc. """ now = datetime.datetime.now() return now.strftime("%Y/%m/%d %H:%M:%S.%f") def get_config_variable(self, name, group=None): """Get a configuration variable. """ try: if group: return self.parent.data_layer.testvars[group][name] else: return self.parent.data_layer.testvars[name] except: return False def insertContact(self, contact): self.marionette.switch_to_frame() mozcontact = contact.create_mozcontact() result = self.marionette.execute_async_script('return GaiaDataLayer.insertContact({});'. format(json.dumps(mozcontact)), special_powers=True) assert result, 'Unable to insert contact {}'.format(contact) def is_device_dual_sim(self): import os try: with open(os.devnull, 'w') as DEVNULL: prop = subprocess32.check_output( 'adb shell cat /system/build.prop | grep multisim', shell=True, stderr=DEVNULL).strip().split("=")[-1] self.parent.reporting.logResult("info", "Value of property: {}".format(prop)) return prop == "dsds" except: self.parent.reporting.logResult("info", "That property was not found") return False def selectFromSystemDialog(self, p_str): """ Selects an item from a system select box (such as country / timezone etc...). """ # Remember the current frame then switch to the system level one. orig_iframe = self.parent.iframe.currentIframe() self.marionette.switch_to_frame() """ Find and click the list item (it may be off the screen, so 'displayed' would be false, but Marionette will scroll it into view automatically so it can be clicked just as it would it real life). """ xpath_val = "//section[@id='value-selector-container']//li[label[span[text()='{}']]]".format(p_str) list_item = self.parent.element.getElement(("xpath", xpath_val), "'{}' in the selector".format(p_str), False) list_item.click() """ A bug in Marionette just now moves the entire screen up, so the statusbar dissappears off the top of the display. This hack corrects it. """ self.marionette.execute_script("document.getElementById('statusbar').scrollIntoView();") # Find and click OK. close_button = self.parent.element.getElement(DOM.GLOBAL.modal_valueSel_ok, "OK button", True, 30) close_button.click() # Return to the orginal frame. self.parent.iframe.switchToFrame("src", orig_iframe) def setSetting(self, item, value, silent=False): """ Just a container function to catch any issues when using gaiatest's 'set_setting()' function. """ try: self.parent.data_layer.set_setting(item, value) if not silent: self.parent.reporting.logResult("info", "Setting '{}' to '{}' returned no issues.".format(item, value)) return True except: if not silent: self.parent.reporting.logResult("info", "WARNING: Unable to set '{}' to '{}'!".format(item, value)) return False def setupDataConn(self): """ Set the phone's details for data conn (apn etc...). """ apn = "telefonica.es" conn_id = "telefonica" passwd = "telefonica" host = "10.138.255.133" port = "8080" self.parent.reporting.logResult("info", "Ensuring dataconn settings (APN, etc...) are correct.") self.set_item("ril.data.apn", apn) self.set_item("ril.data.user", conn_id) self.set_item("ril.data.passwd", passwd) self.set_item("ril.data.httpProxyHost", host) self.set_item("ril.data.httpProxyPort", port) self.parent.reporting.logResult("info", "Done.") def set_item(self, item, value): """ Just a quick function to report issues setting this. """ try: self.parent.data_layer.set_setting(item, value) except: self.parent.reporting.logResult(False, "Unable to set '{}' to '{}'.".format(item, value)) def typeThis(self, p_element_array, p_desc, p_str, p_no_keyboard=False, p_clear=True, p_enter=True, p_validate=True, p_remove_keyboard=True): """ Types this string into this element. If p_no_keyboard = True then it doesn't use the keyboard. <b>NOTE:</b> If os variable "NO_KEYBOARD" is set (to anything), then regardless of what you send to this method, it will never use the keyboard. """ no_keyboard = self.parent.general.get_config_variable("NO_KEYBOARD") # Remember the current frame. orig_frame = self.parent.iframe.currentIframe() self.parent.reporting.debug("Original frame filtered name: {}".format(orig_frame)) input_elem = self.parent.element.getElement(p_element_array, p_desc) # Need to click in the bottom right corner, or the cursor may not be properly located to append. input_elem.tap(x=input_elem.size["width"] - 1, y=input_elem.size["height"] - 1) if p_clear: input_elem.clear() if no_keyboard or p_no_keyboard: # Don't use the keyboard. self.parent.reporting.logResult("info", u"(Sending '{}' to this field without using the keyboard.)". format(p_str)) input_elem.send_keys(p_str) else: # Tap the element to get the keyboard to popup. self.parent.reporting.logResult("info", u"(Sending '{}' to this field using the keyboard.)". format(p_str)) # Type the string. self.keyboard.send(p_str) """ Tap ENTER on the keyboard (helps to remove the keyboard even if you didn't use it to type)? """ if p_enter: self.keyboard.tap_enter() # Switch back to the frame we were in and get the element again. self.parent.reporting.debug("Switching back to original frame {}".format(orig_frame)) self.parent.iframe.switchToFrame("src", orig_frame) # Validate that the field now has the value we sent it. if p_validate: elem = self.marionette.find_element(*p_element_array) value = elem.get_attribute("value") self.parent.reporting.debug("*** VALUE of cmp-body-text: [{}]".format(value)) if value is None: value = elem.text self.parent.reporting.debug("*** No value found. Using TEXT of cmp-body-text: [{}]".format(value)) if p_clear: fieldText = value else: fieldText = value[-(len(p_str)):] self.parent.test.test(p_str == fieldText, "The field contains the correct string ...|{}|- vs. -|{}".format(fieldText, p_str)) if p_remove_keyboard: # Try to tap the header to remove the keyboard now that we've finished. try: self.parent.parent.wait_for_element_displayed(*DOM.GLOBAL.app_head, timeout=1) app_header = self.marionette.find_element(*DOM.GLOBAL.app_head) app_header.tap() time.sleep(0.5) except: pass def remove_files(self): """ Removes all files from the sdcard """ self.parent.device.file_manager.remove(self.parent.device.storage_path) def restart(self): self.parent.reporting.logResult('info', 'Restarting the device...') # Lockscreen does not get on very well with restarts lock_enabled = self.parent.data_layer.get_setting("lockscreen.enabled") if lock_enabled: self.parent.data_layer.set_setting("lockscreen.enabled", False) # After restarting we need to re-instantiate javascript objects self.parent.device.restart_b2g() self.apps = GaiaApps(self.marionette) self.parent.data_layer = GaiaData(self.marionette, self.parent.parent.testvars) # Restore lockscreen status self.parent.data_layer.set_setting("lockscreen.enabled", lock_enabled) @retry(5, 5) def connect_to_cell_data(self): self.parent.reporting.debug(">>> Trying to connect to cell data...") self.parent.data_layer.connect_to_cell_data() self.parent.reporting.debug(" Connected: {}".format(self.parent.data_layer.is_cell_data_connected)) def insert_some_mock_contacts(self, number_of_contacts): """Insert the given number of contacts in the device.""" contact_given = "Test" contact_family = map(str, range(1, number_of_contacts + 1)) contact_name = ["{} {}".format(contact_given, contact_family[i]) for i in range(number_of_contacts)] contact_numbers = [str(i) * 12 for i in range(1, number_of_contacts + 1)] test_contacts = [MockContact(name=contact_name[i], givenName=contact_given, familyName=contact_family[i], tel={'type': 'Mobile', 'value': contact_numbers[i]}) for i in range(number_of_contacts)] map(self.insertContact, test_contacts) def show_all_settings(self): self.parent.reporting.debug("** Device current settings: {}".format(self.parent.data_layer.all_settings))
def __init__(self, parent): self.parent = parent self.marionette = parent.marionette self.keyboard = Keyboard(self.marionette)
def tap_url_input(self): self.marionette.find_element(*self._url_input_locator).tap() from gaiatest.apps.keyboard.app import Keyboard return Keyboard(self.marionette)
class test_main(GaiaTestCase): def __init__(self, *args, **kwargs): kwargs['restart'] = True super(test_main, self).__init__(*args, **kwargs) def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) self.keyboard = Keyboard(self.marionette) self.gmail_user = self.UTILS.general.get_config_variable("gmail_1_user", "common") self.gmail_passwd = self.UTILS.general.get_config_variable("gmail_1_pass", "common") self.connect_to_network() # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact) def tearDown(self): self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.contacts.launch() self.contacts.import_gmail_login(self.gmail_user, self.gmail_passwd) # Get the contacts. contact_list = self.UTILS.element.getElements(DOM.Contacts.import_conts_list, "Contact list") gmail_contacts = [] for y in contact_list: gmail_contacts.append(y.get_attribute("data-search")) search_name = gmail_contacts[0][:gmail_contacts[0].index('@')] # Use the search bar to test ... self.marionette.execute_script("document.getElementById('search-start').click();") self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.iframe.switchToFrame(*DOM.Contacts.gmail_import_frame, via_root_frame=False) self.marionette.execute_script(""" var getElementByXpath = function (path) { return document.evaluate(path, document, null, 9, null).singleNodeValue; }; getElementByXpath("/html/body/section/section[2]/form/p/label").click(); """) self.marionette.switch_to_frame() # Keyboard appears. self.UTILS.element.waitForElements(("xpath", "//iframe[contains(@{},'{}')]".\ format(DOM.Keyboard.frame_locator[0], DOM.Keyboard.frame_locator[1])), "Keyboard") # Typing works and allows real-time filtering. self.UTILS.reporting.logResult("info", "Typing '{}' with the keyboard (without pressing ENTER) ...".\ format(search_name)) self.keyboard.send(search_name) self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.iframe.switchToFrame(*DOM.Contacts.gmail_import_frame, via_root_frame=False) after_search_count = self.UTILS.element.getElements(DOM.Contacts.import_search_list, "Search list") self.UTILS.test.test(len(after_search_count) == 1, "After typing the name '{}' the search list contains 1 contact (out of {}).".\ format(search_name, len(gmail_contacts)))