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 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 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 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_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 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 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)
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)))
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))
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)))