def test_download_pdf(self): m = self.marionette m.set_search_timeout(1000) m.set_window_size(1024, 300) with m.using_context('content'): current_window = m.current_chrome_window_handle m.navigate(self.URL) download_button = m.find_element('id', 'download') action = Actions(m) action.click(download_button) action.wait(time=3) action.perform() closed_window = 0 with m.using_context('chrome'): for window in m.chrome_window_handles: if window != current_window: m.switch_to_window(window) info_msg = m.find_element('id', 'info.body') self.assertRegexpMatches( info_msg.text, 'Tails', msg='Pop up window text does not include Tails') m.close() closed_window += 1 m.switch_to_window(current_window) self.assertEqual(closed_window, 1, msg="no download pop up")
def test_download_pdf(self): m = self.marionette m.set_search_timeout(1000) m.set_window_size(1024, 300) with m.using_context('content'): current_window = m.current_chrome_window_handle m.navigate(self.URL) download_button = m.find_element('id', 'download') action = Actions(m) action.click(download_button) action.wait(time=3) action.perform() closed_window = 0 with m.using_context('chrome'): for window in m.chrome_window_handles: if window != current_window: m.switch_to_window(window) info_msg = m.find_element('id', 'info.body') self.assertRegexpMatches(info_msg.text, 'Tails', msg='Pop up window text does not include Tails') m.close() closed_window += 1 m.switch_to_window(current_window) self.assertEqual(closed_window, 1, msg="no download pop up")
class Base(object): def __init__(self, marionette): self.marionette = marionette self.CHROME = 'chrome' self.CONTENT = 'content' self.set_context(self.CONTENT) self.action = Actions(marionette) def launch(self, url): if url is not None: regex = re.compile( r'^(?:http|ftp)s?://' r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)' r'+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' r'localhost|' r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' r'(?::\d+)?' r'(?:/?|[/?]\S+)$', re.IGNORECASE) if regex.match(url): self.marionette.navigate(url) else: raise ValueError('Url is malformed.') else: raise ValueError("Url must contain a value.") def is_element_present(self, by, locator): try: self.marionette.find_element(by, locator) return True except NoSuchElementException: return False def is_element_displayed(self, by, locator): try: return self.marionette.find_element(by, locator).is_displayed() except NoSuchElementException: return False def wait_for_element_displayed(self, by, locator): return Wait(self.marionette).until(expected.element_displayed( Wait(self.marionette).until( expected.element_present(by, locator)))) def wait_for_element_present(self, by, locator): Wait(self.marionette).until(expected.element_present(by, locator)) def wait_for_element_enabled(self, by, locator): Wait(self.marionette).until( expected.element_enabled(lambda m: m.find_element(by, locator))) def wait_for_element_not_displayed(self, by, locator): Wait(self.marionette).until(expected.element_not_displayed( Wait(self.marionette).until( expected.element_present(by, locator)))) def wait_for_element_not_present(self, by, locator): Wait(self.marionette).until(expected.element_not_present(by, locator)) def wait_for_element_not_enabled(self, by, locator): Wait(self.marionette).until( expected.element_not_enabled( lambda m: m.find_element(by, locator))) def set_context(self, context): if context != self.CHROME and context != self.CONTENT: raise AttributeError( '{} is not a context that you can switch to'.format(context)) else: self.marionette.set_context(context) def click_element(self, by, locator): self.marionette.find_element(by, locator).click() def send_keys_to_element(self, by, locator, string): self.marionette.find_element(by, locator).send_keys(string) def wait(self, time): self.action.wait(time).perform()