def verify_download(context, filename, timeout): path = os.path.join(context.download_dir, filename) def check(): return os.path.exists(path) assert _retry(check, timeout), u'File has not been downloaded'
def is_enabled(context, xpath, timeout): el = context.browser.find_by_xpath(xpath) assert el, u'Element not found' element = el.first check = lambda: element._element.is_enabled() assert _retry(check, timeout), u'Element is not enabled'
def alert_contains_text_timeout(context, text, timeout): def check(): try: alert = context.browser.get_alert(), u'Alert not found' return alert is not None and text in alert[0].text except NoAlertPresentException: return False assert _retry(check, timeout), u'Alert not found'
def alert_is_present_timeout(context, timeout): def check(): try: alert = context.browser.get_alert(), u'Alert not found' return alert is not None except NoAlertPresentException: return False assert _retry(check, timeout), u'Alert not found'
def is_enabled(context, name, timeout): el = context.browser.find_by_xpath( ("//*[@id='%(name)s']|" "//*[@name='%(name)s']") % {'name': name}) assert el, u'Element not found' element = el.first check = lambda: element._element.is_enabled() assert _retry(check, timeout), u'Element is not enabled'
def alert_contains_text_timeout(context, text, timeout): def check(): try: alert = context.browser.get_alert() return alert is not None and text in alert.text except NoAlertPresentException: return False assert _retry(check, timeout), u"Alert not found"
def verify_download_contents(context, filename, text, timeout): path = os.path.join(context.download_dir, filename) def check(): return os.path.exists(path) assert _retry(check, timeout), u'File has not been downloaded' with open(path, 'r') as f: contents = f.read() assert text.encode('utf-8') in contents, u'Text not found in file'