def test_submit_unencrypted_info_warning(self): with self.marionette.using_context('content'): self.marionette.navigate(self.url) # Get the page's search box and submit button. searchbox = self.marionette.find_element(By.ID, 'q') button = self.marionette.find_element(By.ID, 'submit') # Use the page's search box to submit information. searchbox.send_keys(self.test_string) button.click() # Get the expected warning text and replace its two instances of "##" with "\n\n". message = self.browser.get_property('formPostSecureToInsecureWarning.message') message = message.replace('##', '\n\n') # Wait for the warning, verify the expected text matches warning, accept the warning warning = Alert(self.marionette) try: Wait(self.marionette, ignored_exceptions=NoAlertPresentException).until( lambda _: warning.text == message) finally: warning.accept() # Wait while the page updates self.wait_for_condition(expected.element_stale(searchbox)) # Check that search_term contains the test string. search_term = self.marionette.find_element(By.ID, 'search-term') self.assertEqual(search_term.get_attribute('textContent'), self.test_string)
def test_submit_unencrypted_info_warning(self): with self.marionette.using_context('content'): self.marionette.navigate(self.url) # Get the page's search box and submit button. searchbox = self.marionette.find_element(By.ID, 'q') button = self.marionette.find_element(By.ID, 'submit') # Use the page's search box to submit information. searchbox.send_keys(self.test_string) button.click() # Get the expected warning text and replace its two instances of "##" with "\n\n". message = self.browser.get_property( 'formPostSecureToInsecureWarning.message') message = message.replace('##', '\n\n') # Wait for the warning, verify the expected text matches warning, accept the warning warning = Alert(self.marionette) try: Wait(self.marionette, ignored_exceptions=NoAlertPresentException).until( lambda _: warning.text == message) finally: warning.accept() # Wait while the page updates self.wait_for_condition(expected.element_stale(searchbox)) # Check that search_term contains the test string. search_term = self.marionette.find_element(By.ID, 'search-term') self.assertEqual(search_term.get_attribute('textContent'), self.test_string)
def test_set_text_throws(self): self.assertRaises(NoAlertPresentException, Alert(self.marionette).send_keys, "Foo") self.marionette.find_element('id', 'modal-alert').click() self.wait_for_alert() alert = self.marionette.switch_to_alert() self.assertRaises(ElementNotVisibleException, alert.send_keys, "Foo") alert.accept()
def test_set_text_throws(self): with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).send_keys("Foo") self.marionette.find_element(By.ID, "tab-modal-alert").click() self.wait_for_alert() alert = self.marionette.switch_to_alert() with self.assertRaises(errors.ElementNotInteractableException): alert.send_keys("Foo") alert.accept()
def check_page_status(page, expected_history_length): if "alert_text" in page: if page["alert_text"] is None: # navigation auto-dismisses beforeunload prompt with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).text else: self.assertEqual(Alert(self.marionette).text, page["alert_text"]) self.assertEqual(page["url"], self.marionette.get_url()) self.assertEqual(self.history_length, expected_history_length) if "is_remote" in page: self.assertEqual(page["is_remote"], self.is_remote_tab, "'{}' doesn't match expected remoteness state: {}".format( page["url"], page["is_remote"])) if "callback" in page and callable(page["callback"]): page["callback"]()
def test_submit_unencrypted_info_warning(self): with self.marionette.using_context('content'): self.marionette.navigate(self.url) # Get the page's search box and submit button. searchbox = self.marionette.find_element(By.ID, 'q') button = self.marionette.find_element(By.ID, 'submit') # Use the page's search box to submit information. searchbox.send_keys(self.test_string) button.click() # Get the expected warning text and replace its two instances of "##" with "\n\n". message = self.browser.get_property( 'formPostSecureToInsecureWarning.message') message = message.replace('##', '\n\n') # Wait for the warning, verify the expected text matches warning, accept the warning warning = Alert(self.marionette) try: Wait(self.marionette, ignored_exceptions=NoAlertPresentException, timeout=self.browser.timeout_page_load).until( lambda _: warning.text == message) finally: warning.accept() # Wait for the search box to become stale, then wait for the page to be reloaded. Wait(self.marionette).until(expected.element_stale(searchbox)) # TODO: Bug 1140470: use replacement for mozmill's waitforPageLoad Wait(self.marionette, timeout=self.browser.timeout_page_load).until( lambda mn: mn.execute_script( 'return document.readyState == "DOMContentLoaded" ||' ' document.readyState == "complete";')) # Check that search_term contains the test string. search_term = self.marionette.find_element(By.ID, 'search-term') self.assertEqual(search_term.get_attribute('textContent'), self.test_string)
def test_submit_unencrypted_info_warning(self): with self.marionette.using_context('content'): self.marionette.navigate(self.url) # Get the page's search box and submit button. searchbox = self.marionette.find_element(By.ID, 'q') button = self.marionette.find_element(By.ID, 'submit') # Use the page's search box to submit information. searchbox.send_keys(self.test_string) button.click() # Get the expected warning text and replace its two instances of "##" with "\n\n". message = self.browser.get_property('formPostSecureToInsecureWarning.message') message = message.replace('##', '\n\n') # Wait for the warning, verify the expected text matches warning, accept the warning warning = Alert(self.marionette) try: Wait(self.marionette, ignored_exceptions=NoAlertPresentException, timeout=self.browser.timeout_page_load).until( lambda _: warning.text == message) finally: warning.accept() # Wait for the search box to become stale, then wait for the page to be reloaded. Wait(self.marionette).until(expected.element_stale(searchbox)) # TODO: Bug 1140470: use replacement for mozmill's waitforPageLoad Wait(self.marionette, timeout=self.browser.timeout_page_load).until( lambda mn: mn.execute_script('return document.readyState == "DOMContentLoaded" ||' ' document.readyState == "complete";') ) # Check that search_term contains the test string. search_term = self.marionette.find_element(By.ID, 'search-term') self.assertEqual(search_term.get_property('textContent'), self.test_string)
def test_dismissed_beforeunload_prompt(self): self.marionette.navigate(inline(""" <input type="text"> <script> window.addEventListener("beforeunload", function (event) { event.preventDefault(); }); </script> """)) self.marionette.find_element(By.TAG_NAME, "input").send_keys("foo") self.marionette.refresh() # navigation auto-dismisses beforeunload prompt with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).text
def test_click_link_page_load_dismissed_beforeunload_prompt(self): self.marionette.navigate( inline(""" <input type="text"></input> <a href="{}">Click</a> <script> window.addEventListener("beforeunload", function (event) {{ event.preventDefault(); }}); </script> """.format(self.marionette.absolute_url("clicks.html")))) self.marionette.find_element(By.TAG_NAME, "input").send_keys("foo") self.marionette.find_element(By.TAG_NAME, "a").click() # navigation auto-dismisses beforeunload prompt with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).text
def test_no_alert_raises(self): with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).accept() with self.assertRaises(errors.NoAlertPresentException): Alert(self.marionette).dismiss()
def alert_present(self): try: Alert(self.marionette).text return True except errors.NoAlertPresentException: return False
def test_no_alert_raises(self): self.assertRaises(NoAlertPresentException, Alert(self.marionette).accept) self.assertRaises(NoAlertPresentException, Alert(self.marionette).dismiss)
logger.info('<chromescript>\n%s\n</chromescript>', chrome_script) result = client.execute_script( chrome_script, sandbox='system', script_args=[client.timeout.script], script_timeout=client.timeout.script) logger.info('chrome script result: %s\n', result) except errors.ScriptTimeoutException, e: logger.warning('chrome script: %s', e) except Exception, e: logger.error('chrome script: %s', e) time.sleep(float(args.wait)) while True: try: logger.info('alert: %s', Alert(client).text) Alert(client).dismiss() except errors.NoAlertPresentException: break except Exception, e: logger.error('alert: %s', e) break try: client.quit(in_app=True) except: pass except (errors.TimeoutException, errors.UnknownException, IOError), e: logger.warning("ABNORMAL: %s", e) try: client.quit(in_app=True) if client.session: