class test_main(GaiaTestCase): test_msg = "Test message." def setUp(self): GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.contacts = Contacts(self) self.phone_number = self.UTILS.general.get_config_variable("phone_number", "custom") self.email_address = self.UTILS.general.get_config_variable("gmail_1_email", "common") self.test_contact = MockContact(email=[{"type": "Personal", "value": "*****@*****.**"}, {"type": "Personal", "value": "*****@*****.**"}, {"type": "Personal", "value": "*****@*****.**"}]) self.UTILS.general.insertContact(self.test_contact) self.UTILS.general.add_file_to_device('./tests/_resources/contact_face.jpg') self.data_layer.delete_all_sms() def tearDown(self): self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.messages.launch() self.messages.create_and_send_sms([self.phone_number], "Hello {} old bean.".format(self.email_address)) send_time = self.messages.last_sent_message_timestamp() msg = self.messages.wait_for_message(send_time=send_time) # Press the email link. link = msg.find_element("tag name", "a") link.tap() add_btn = self.UTILS.element.getElement(DOM.Messages.header_add_to_contact_btn, "Add to an existing contact button") add_btn.tap() # Verify that the email is in the email field. self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.contacts.view_contact(self.test_contact["givenName"], False) self.UTILS.element.waitForElements(("xpath", "//input[@type='email' and @value='{}']".format(self.email_address)), "New email address") self.contacts.add_gallery_image_to_contact(0) done_button = self.UTILS.element.getElement(DOM.Contacts.edit_update_button, "'Update' button") done_button.tap() # Check that the contacts iframe is now gone. self.marionette.switch_to_frame() self.UTILS.element.waitForNotElements(("xpath", "//iframe[contains(@src,'contacts')]"), "Contact app iframe")
class test_main(GaiaTestCase): def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.dialer = Dialer(self) self.contacts = Contacts(self) self.test_contact = MockContact(tel={'type': 'Mobile', 'value': "665666666"}) # Generate an entry in the call log self.dialer.launch() self.dialer.callLog_clearAll() self.dialer.createMultipleCallLogEntries(self.test_contact["tel"]["value"], 1) # Create contact with image self.UTILS.general.add_file_to_device('./tests/_resources/contact_face.jpg') self.dialer.callLog_createContact(self.test_contact["tel"]["value"]) contFields = self.contacts.get_contact_fields() self.contacts.replace_str(contFields['givenName'], self.test_contact["givenName"]) self.contacts.replace_str(contFields['familyName'], self.test_contact["familyName"]) self.contacts.add_gallery_image_to_contact(0) done_button = self.UTILS.element.getElement(DOM.Contacts.done_button, "'Done' button") done_button.tap() time.sleep(1) self.apps.kill_all() time.sleep(2) def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.dialer.launch() self.dialer.open_call_log() entry = self.UTILS.element.getElement(("xpath", DOM.Dialer.call_log_number_xpath.format(self.test_contact["tel"]["value"])), "The call log for number {}".format(self.test_contact["tel"]["value"])) entry.tap() self.UTILS.iframe.switchToFrame(*DOM.Dialer.frame_locator_calling) self.UTILS.element.waitForElements(("xpath", DOM.Dialer.outgoing_call_numberXP.format(self.test_contact["name"])), "Outgoing call found with number matching {}".format(self.test_contact["name"])) time.sleep(2) self.dialer.hangUp()
class test_main(GaiaTestCase): test_msg = "Test message." def setUp(self): GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.contacts = Contacts(self) self.phone_number = self.UTILS.general.get_config_variable( "phone_number", "custom") self.email_address = self.UTILS.general.get_config_variable( "gmail_1_email", "common") self.test_contact = MockContact(email=[{ "type": "Personal", "value": "*****@*****.**" }, { "type": "Personal", "value": "*****@*****.**" }, { "type": "Personal", "value": "*****@*****.**" }]) self.UTILS.general.insertContact(self.test_contact) self.UTILS.general.add_file_to_device( './tests/_resources/contact_face.jpg') self.data_layer.delete_all_sms() def tearDown(self): self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.messages.launch() self.messages.create_and_send_sms([self.phone_number], "Hello {} old bean.".format( self.email_address)) send_time = self.messages.last_sent_message_timestamp() msg = self.messages.wait_for_message(send_time=send_time) # Press the email link. link = msg.find_element("tag name", "a") link.tap() add_btn = self.UTILS.element.getElement( DOM.Messages.header_add_to_contact_btn, "Add to an existing contact button") add_btn.tap() # Verify that the email is in the email field. self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.contacts.view_contact(self.test_contact["givenName"], False) self.UTILS.element.waitForElements( ("xpath", "//input[@type='email' and @value='{}']".format( self.email_address)), "New email address") self.contacts.add_gallery_image_to_contact(0) done_button = self.UTILS.element.getElement( DOM.Contacts.edit_update_button, "'Update' button") done_button.tap() # Check that the contacts iframe is now gone. self.marionette.switch_to_frame() self.UTILS.element.waitForNotElements( ("xpath", "//iframe[contains(@src,'contacts')]"), "Contact app iframe")
class test_main(GaiaTestCase): _keyboard_frame_locator = (By.CSS_SELECTOR, '#keyboards iframe:not([hidden])') def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact) self.UTILS.general.add_file_to_device('./tests/_resources/contact_face.jpg') def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): # Launch contacts app. self.UTILS.reporting.logResult("info", "Setting up contact ...") self.contacts.launch() # View our contact. self.contacts.view_contact(self.contact['name']) # Edit our contact. self.contacts.press_edit_contact_button() self.UTILS.reporting.logResult("info", "Starting tests ...") self.check_field(True, "phone", "number_0", "number") self.check_field(True, "email", "email_0", "email") self.check_field(True, "address", "streetAddress_0", "streetAddress") # NOTE: for some reason the photo has to tested alone or it screws up the text tests. self.contacts.press_cancel_edit_button() self.contacts.press_edit_contact_button() self.contacts.add_gallery_image_to_contact(0) self.check_field(False, "photo", "thumbnail-action") def check_field(self, text, field_name, field_id, reset_btn_name=""): # Test a text field: default, with reset enabled, with reset disabled. # try to make sure the field is in view (pretty hideous, but it does the job!). try: self.marionette.execute_script("document.getElementById('" + field_id + "').scrollIntoView();") self.marionette.execute_script("document.getElementById('contact-form-title').scrollIntoView();") except: pass self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult("info", "*** '" + field_name + "': default (before testing 'reset' mode) ... ***") self.check_kbd_appears(reset_btn_name, field_name, True) if text else self.check_photo_tap(True) self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult("info", "*** '" + field_name + "': switching 'reset' mode ON ... ***") self.toggle_reset_button(field_name) self.check_kbd_appears(reset_btn_name, field_name, False) if text else self.check_photo_tap(False) self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult("info", "*** '" + field_name + "': switching 'reset' mode OFF ... ***") self.toggle_reset_button(field_name) self.check_kbd_appears(reset_btn_name, field_name, True) if text else self.check_photo_tap(True) self.UTILS.reporting.logResult("info", " ") def toggle_reset_button(self, element): # Press reset button on the required fields ... reset_btn = DOM.Contacts.reset_field_css if element == "photo": x = self.UTILS.element.getElement(("css selector", reset_btn.format("thumbnail-action")), "Photo reset button") x.tap() if element == "phone": x = self.UTILS.element.getElement(("css selector", reset_btn.format("add-phone-0")), "Phone reset button") x.tap() if element == "email": x = self.UTILS.element.getElement(("css selector", reset_btn.format("add-email-0")), "Email reset button") x.tap() if element == "address": x = self.UTILS.element.getElement(("css selector", reset_btn.format("add-address-0")), "Address reset button") x.tap() def check_photo_tap(self, editable): time.sleep(1) # Check tapping photo (same link for add and edit) _comment = "Photo is " + ("not " if not editable else "") x = self.UTILS.element.getElement(DOM.Contacts.add_photo, "Photo") x.tap() time.sleep(1) self.marionette.switch_to_frame() is_editable = False try: self.wait_for_element_present(*DOM.Contacts.photo_from_gallery, timeout=5) self.wait_for_element_present(*DOM.Contacts.cancel_photo_source, timeout=1) x = self.marionette.find_element(*DOM.Contacts.cancel_photo_source) x.tap() is_editable = True except: is_editable = False self.UTILS.test.test(is_editable == editable, _comment + "editable.") self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) def check_kbd_appears(self, item, desc, kbd_displayed): time.sleep(1) """ Taps the field and checks to see if the keyboard appears. When marionette "is_enabled()" is working , we can forget all this. """ comment = "The " + desc + " field can" + ("not" if not kbd_displayed else "") + " be edited." x = self.UTILS.element.getElement(("id", "{}_0".format(item)), "Field for " + desc) # From here on does the keyboard verification. # The problem is that the keyboard frame is always present # once it's been launched, so I need a way to either KILL # the keyboard, or see what's currently displayed. x.tap() self.marionette.switch_to_frame() kbd = False try: self.wait_for_element_displayed(*self._keyboard_frame_locator) screenshot = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult('info', "Keyboard displayed", screenshot) kbd = True except: self.UTILS.reporting.logResult("info", "No wild keyboard appeared") # pass # self.UTILS.reporting.logResult("info", "Is keyboard really there? {}".format(kbd)) self.UTILS.reporting.logResult("info", "Expected: {}".format(kbd_displayed)) self.UTILS.test.test(kbd == kbd_displayed, comment) # Return to the contacts iframe. self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) # Tap the header to remove the keyboard. self.wait_for_element_displayed(*DOM.Contacts.edit_contact_header) x = self.marionette.find_element(*DOM.Contacts.edit_contact_header) x.tap()
class test_main(GaiaTestCase): link = "*****@*****.**" test_msg = "Test " + link + " this." def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.contacts = Contacts(self) # Insert a contact without email addresses self.UTILS.general.add_file_to_device('./tests/_resources/contact_face.jpg') self.contact = MockContact(email={'type': 'Personal', 'value': ''}) self.UTILS.general.insertContact(self.contact) # 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.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): # Launch messages app. self.messages.launch() # Create and send a new test message. self.messages.create_and_send_sms([self.phone_number], self.test_msg) """ Wait for the last message in this thread to be a 'received' one and click the link. """ x = self.messages.wait_for_message() self.UTILS.test.test(x, "Received a message.", True) a = x.find_element("tag name", "a") a.tap() # Press 'add to existing contact' button. w = self.UTILS.element.getElement(DOM.Messages.header_add_to_contact_btn, "Add to existing contact button") w.tap() # Switch to Contacts app. time.sleep(2) self.marionette.switch_to_frame() self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) # Select the contact. prepopulated_contact = (DOM.Contacts.view_all_contact_specific_contact[0], DOM.Contacts.view_all_contact_specific_contact[1].format("OWD")) contact = self.UTILS.element.getElement(prepopulated_contact, "Search item") contact.tap() # Fill out all the other details. contFields = self.contacts.get_contact_fields() """ Put the contact details into each of the fields (this method clears each field first). """ self.contacts.replace_str(contFields['givenName'], self.contact["givenName"] + "bis") self.contacts.replace_str(contFields['familyName'], self.contact["familyName"] + "bis") self.contacts.replace_str(contFields['tel'], self.contact["tel"]["value"] + "bis") self.contacts.replace_str(contFields['street'], self.contact["addr"]["streetAddress"] + "bis") self.contacts.replace_str(contFields['zip'], self.contact["addr"]["postalCode"] + "bis") self.contacts.replace_str(contFields['city'], self.contact["addr"]["locality"] + "bis") self.contacts.replace_str(contFields['country'], self.contact["addr"]["countryName"] + "bis") self.contacts.add_gallery_image_to_contact(0) # Add another email address. self.contacts.add_another_email_address(self.contact["email"]["value"]) # Press the Done button. done_button = self.UTILS.element.getElement(DOM.Contacts.done_button, "'Done' button") done_button.tap() # Check that the contacts iframe is now gone. self.marionette.switch_to_frame() self.UTILS.element.waitForNotElements(("xpath", "//iframe[contains(@src,'contacts')]"), "Contact app iframe") # Now return to the SMS app. self.UTILS.iframe.switchToFrame(*DOM.Messages.frame_locator)
class test_main(GaiaTestCase): def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.dialer = Dialer(self) self.contacts = Contacts(self) self.test_contact = MockContact(tel={ 'type': 'Mobile', 'value': "665666666" }) # Generate an entry in the call log self.dialer.launch() self.dialer.callLog_clearAll() self.dialer.createMultipleCallLogEntries( self.test_contact["tel"]["value"], 1) # Create contact with image self.UTILS.general.add_file_to_device( './tests/_resources/contact_face.jpg') self.dialer.callLog_createContact(self.test_contact["tel"]["value"]) contFields = self.contacts.get_contact_fields() self.contacts.replace_str(contFields['givenName'], self.test_contact["givenName"]) self.contacts.replace_str(contFields['familyName'], self.test_contact["familyName"]) self.contacts.add_gallery_image_to_contact(0) done_button = self.UTILS.element.getElement(DOM.Contacts.done_button, "'Done' button") done_button.tap() time.sleep(1) self.apps.kill_all() time.sleep(2) def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): self.dialer.launch() self.dialer.open_call_log() entry = self.UTILS.element.getElement( ("xpath", DOM.Dialer.call_log_number_xpath.format( self.test_contact["tel"]["value"])), "The call log for number {}".format( self.test_contact["tel"]["value"])) entry.tap() self.UTILS.iframe.switchToFrame(*DOM.Dialer.frame_locator_calling) self.UTILS.element.waitForElements( ("xpath", DOM.Dialer.outgoing_call_numberXP.format( self.test_contact["name"])), "Outgoing call found with number matching {}".format( self.test_contact["name"])) time.sleep(2) self.dialer.hangUp()
class test_main(GaiaTestCase): _keyboard_frame_locator = (By.CSS_SELECTOR, '#keyboards iframe:not([hidden])') def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) # Create test contacts. self.contact = MockContact() self.UTILS.general.insertContact(self.contact) self.UTILS.general.add_file_to_device( './tests/_resources/contact_face.jpg') def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): # Launch contacts app. self.UTILS.reporting.logResult("info", "Setting up contact ...") self.contacts.launch() # View our contact. self.contacts.view_contact(self.contact['name']) # Edit our contact. self.contacts.press_edit_contact_button() self.UTILS.reporting.logResult("info", "Starting tests ...") self.check_field(True, "phone", "number_0", "number") self.check_field(True, "email", "email_0", "email") self.check_field(True, "address", "streetAddress_0", "streetAddress") # NOTE: for some reason the photo has to tested alone or it screws up the text tests. self.contacts.press_cancel_edit_button() self.contacts.press_edit_contact_button() self.contacts.add_gallery_image_to_contact(0) self.check_field(False, "photo", "thumbnail-action") def check_field(self, text, field_name, field_id, reset_btn_name=""): # Test a text field: default, with reset enabled, with reset disabled. # try to make sure the field is in view (pretty hideous, but it does the job!). try: self.marionette.execute_script("document.getElementById('" + field_id + "').scrollIntoView();") self.marionette.execute_script( "document.getElementById('contact-form-title').scrollIntoView();" ) except: pass self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult( "info", "*** '" + field_name + "': default (before testing 'reset' mode) ... ***") self.check_kbd_appears(reset_btn_name, field_name, True) if text else self.check_photo_tap(True) self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult( "info", "*** '" + field_name + "': switching 'reset' mode ON ... ***") self.toggle_reset_button(field_name) self.check_kbd_appears(reset_btn_name, field_name, False) if text else self.check_photo_tap(False) self.UTILS.reporting.logResult("info", " ") self.UTILS.reporting.logResult( "info", "*** '" + field_name + "': switching 'reset' mode OFF ... ***") self.toggle_reset_button(field_name) self.check_kbd_appears(reset_btn_name, field_name, True) if text else self.check_photo_tap(True) self.UTILS.reporting.logResult("info", " ") def toggle_reset_button(self, element): # Press reset button on the required fields ... reset_btn = DOM.Contacts.reset_field_css if element == "photo": x = self.UTILS.element.getElement( ("css selector", reset_btn.format("thumbnail-action")), "Photo reset button") x.tap() if element == "phone": x = self.UTILS.element.getElement( ("css selector", reset_btn.format("add-phone-0")), "Phone reset button") x.tap() if element == "email": x = self.UTILS.element.getElement( ("css selector", reset_btn.format("add-email-0")), "Email reset button") x.tap() if element == "address": x = self.UTILS.element.getElement( ("css selector", reset_btn.format("add-address-0")), "Address reset button") x.tap() def check_photo_tap(self, editable): time.sleep(1) # Check tapping photo (same link for add and edit) _comment = "Photo is " + ("not " if not editable else "") x = self.UTILS.element.getElement(DOM.Contacts.add_photo, "Photo") x.tap() time.sleep(1) self.marionette.switch_to_frame() is_editable = False try: self.wait_for_element_present(*DOM.Contacts.photo_from_gallery, timeout=5) self.wait_for_element_present(*DOM.Contacts.cancel_photo_source, timeout=1) x = self.marionette.find_element(*DOM.Contacts.cancel_photo_source) x.tap() is_editable = True except: is_editable = False self.UTILS.test.test(is_editable == editable, _comment + "editable.") self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) def check_kbd_appears(self, item, desc, kbd_displayed): time.sleep(1) """ Taps the field and checks to see if the keyboard appears. When marionette "is_enabled()" is working , we can forget all this. """ comment = "The " + desc + " field can" + ("not" if not kbd_displayed else "") + " be edited." x = self.UTILS.element.getElement(("id", "{}_0".format(item)), "Field for " + desc) # From here on does the keyboard verification. # The problem is that the keyboard frame is always present # once it's been launched, so I need a way to either KILL # the keyboard, or see what's currently displayed. x.tap() self.marionette.switch_to_frame() kbd = False try: self.wait_for_element_displayed(*self._keyboard_frame_locator) screenshot = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult('info', "Keyboard displayed", screenshot) kbd = True except: self.UTILS.reporting.logResult("info", "No wild keyboard appeared") # pass # self.UTILS.reporting.logResult( "info", "Is keyboard really there? {}".format(kbd)) self.UTILS.reporting.logResult("info", "Expected: {}".format(kbd_displayed)) self.UTILS.test.test(kbd == kbd_displayed, comment) # Return to the contacts iframe. self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) # Tap the header to remove the keyboard. self.wait_for_element_displayed(*DOM.Contacts.edit_contact_header) x = self.marionette.find_element(*DOM.Contacts.edit_contact_header) x.tap()
class field_remove_toggle(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() def field_remove_toggle_test(self, contact, field_definition, item_nums=[0]): """ Imports a contact, goes to the contact, edits it and tests the required 'remove' icon (on and then off). p_field_num: The number of the item, for example if there's >1 phone number, then '0' would be the first one etc... (defaults to zero in case there's only one item). """ del_icon_locator = ("css selector", DOM.Contacts.reset_field_css.format(field_definition)) if field_definition == "thumbnail-action": # The thumbnail is different from the rest. field_locator = DOM.Contacts.edit_image else: field_locator = ("xpath", "//div[@id='{}']/div".format(field_definition)) # Get details of our test contacts. self.UTILS.reporting.logResult("info", "Setting up contact ...") self.UTILS.general.insertContact(contact) # Add image. self.UTILS.general.add_file_to_device('./tests/_resources/contact_face.jpg') self.contacts.launch() self.contacts.view_contact(contact['name']) self.contacts.press_edit_contact_button() self.contacts.add_gallery_image_to_contact(0) self.UTILS.reporting.logResult("info", "Starting tests ...") # Try to make sure this field section is in view (pretty hideous, but it does the job!). try: self.marionette.execute_script("document.getElementById('{}').scrollIntoView();".format(field_definition)) self.marionette.execute_script("document.getElementById('contact-form-title').scrollIntoView();") except: pass x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) self.UTILS.general.checkMarionetteOK() self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.reporting.logResult("info", "<b>For each of our items for this field, "\ "click the icon to set them to 'remove' ...</b>") for i in item_nums: x = self.UTILS.element.getElements(field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test("removed" not in x.get_attribute("class"), "The item is NOT marked as temporarily removed.") x = self.UTILS.element.getElements(del_icon_locator, "Field reset button (item {})".format(i))[i] x.tap() x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) x = self.UTILS.element.getElements(field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test("removed" in x.get_attribute("class"), "The item IS now marked as temporarily removed.") self.UTILS.reporting.logResult("info", "<b>For each of our items for this field, "\ "click the icon to turn off 'remove' ...</b>") for i in item_nums: x = self.UTILS.element.getElements(del_icon_locator, "Field reset button (item {})".format(i))[i] x.tap() x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) x = self.UTILS.element.getElements(field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test("removed" not in x.get_attribute("class"), "The item is now NOT marked as temporarily removed.")
class field_remove_toggle(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.contacts = Contacts(self) def tearDown(self): self.UTILS.general.remove_files() self.UTILS.reporting.reportResults() def field_remove_toggle_test(self, contact, field_definition, item_nums=[0]): """ Imports a contact, goes to the contact, edits it and tests the required 'remove' icon (on and then off). p_field_num: The number of the item, for example if there's >1 phone number, then '0' would be the first one etc... (defaults to zero in case there's only one item). """ del_icon_locator = ( "css selector", DOM.Contacts.reset_field_css.format(field_definition)) if field_definition == "thumbnail-action": # The thumbnail is different from the rest. field_locator = DOM.Contacts.edit_image else: field_locator = ("xpath", "//div[@id='{}']/div".format(field_definition)) # Get details of our test contacts. self.UTILS.reporting.logResult("info", "Setting up contact ...") self.UTILS.general.insertContact(contact) # Add image. self.UTILS.general.add_file_to_device( './tests/_resources/contact_face.jpg') self.contacts.launch() self.contacts.view_contact(contact['name']) self.contacts.press_edit_contact_button() self.contacts.add_gallery_image_to_contact(0) self.UTILS.reporting.logResult("info", "Starting tests ...") # Try to make sure this field section is in view (pretty hideous, but it does the job!). try: self.marionette.execute_script( "document.getElementById('{}').scrollIntoView();".format( field_definition)) self.marionette.execute_script( "document.getElementById('contact-form-title').scrollIntoView();" ) except: pass x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) self.UTILS.general.checkMarionetteOK() self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) self.UTILS.reporting.logResult("info", "<b>For each of our items for this field, "\ "click the icon to set them to 'remove' ...</b>") for i in item_nums: x = self.UTILS.element.getElements( field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test( "removed" not in x.get_attribute("class"), "The item is NOT marked as temporarily removed.") x = self.UTILS.element.getElements( del_icon_locator, "Field reset button (item {})".format(i))[i] x.tap() x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) x = self.UTILS.element.getElements( field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test( "removed" in x.get_attribute("class"), "The item IS now marked as temporarily removed.") self.UTILS.reporting.logResult("info", "<b>For each of our items for this field, "\ "click the icon to turn off 'remove' ...</b>") for i in item_nums: x = self.UTILS.element.getElements( del_icon_locator, "Field reset button (item {})".format(i))[i] x.tap() x = self.UTILS.debug.screenShotOnErr() self.UTILS.reporting.logResult("info", "Screenshot at this point:", x) x = self.UTILS.element.getElements( field_locator, "Field being tested (item {})".format(i))[i] self.UTILS.test.test( "removed" not in x.get_attribute("class"), "The item is now NOT marked as temporarily removed.")
class test_main(GaiaTestCase): link = "*****@*****.**" test_msg = "Test " + link + " this." def setUp(self): # Set up child objects... GaiaTestCase.setUp(self) self.UTILS = UTILS(self) self.messages = Messages(self) self.contacts = Contacts(self) # Insert a contact without email addresses self.UTILS.general.add_file_to_device( './tests/_resources/contact_face.jpg') self.contact = MockContact(email={'type': 'Personal', 'value': ''}) self.UTILS.general.insertContact(self.contact) # 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.general.remove_files() self.UTILS.reporting.reportResults() GaiaTestCase.tearDown(self) def test_run(self): # Launch messages app. self.messages.launch() # Create and send a new test message. self.messages.create_and_send_sms([self.phone_number], self.test_msg) """ Wait for the last message in this thread to be a 'received' one and click the link. """ x = self.messages.wait_for_message() self.UTILS.test.test(x, "Received a message.", True) a = x.find_element("tag name", "a") a.tap() # Press 'add to existing contact' button. w = self.UTILS.element.getElement( DOM.Messages.header_add_to_contact_btn, "Add to existing contact button") w.tap() # Switch to Contacts app. time.sleep(2) self.marionette.switch_to_frame() self.UTILS.iframe.switchToFrame(*DOM.Contacts.frame_locator) # Select the contact. prepopulated_contact = ( DOM.Contacts.view_all_contact_specific_contact[0], DOM.Contacts.view_all_contact_specific_contact[1].format("OWD")) contact = self.UTILS.element.getElement(prepopulated_contact, "Search item") contact.tap() # Fill out all the other details. contFields = self.contacts.get_contact_fields() """ Put the contact details into each of the fields (this method clears each field first). """ self.contacts.replace_str(contFields['givenName'], self.contact["givenName"] + "bis") self.contacts.replace_str(contFields['familyName'], self.contact["familyName"] + "bis") self.contacts.replace_str(contFields['tel'], self.contact["tel"]["value"] + "bis") self.contacts.replace_str( contFields['street'], self.contact["addr"]["streetAddress"] + "bis") self.contacts.replace_str(contFields['zip'], self.contact["addr"]["postalCode"] + "bis") self.contacts.replace_str(contFields['city'], self.contact["addr"]["locality"] + "bis") self.contacts.replace_str(contFields['country'], self.contact["addr"]["countryName"] + "bis") self.contacts.add_gallery_image_to_contact(0) # Add another email address. self.contacts.add_another_email_address(self.contact["email"]["value"]) # Press the Done button. done_button = self.UTILS.element.getElement(DOM.Contacts.done_button, "'Done' button") done_button.tap() # Check that the contacts iframe is now gone. self.marionette.switch_to_frame() self.UTILS.element.waitForNotElements( ("xpath", "//iframe[contains(@src,'contacts')]"), "Contact app iframe") # Now return to the SMS app. self.UTILS.iframe.switchToFrame(*DOM.Messages.frame_locator)