def execute_click_and_verify_condition(web_element, text_appear=True, **kwargs): """Click and optionally verify condition after click. Accepted kwargs: text(str) = In case we want to verify that some text appears/disappears after click interval = How long we wait between the clicks timeout = How long we are trying if element is not enabled or some other error exists js = if js parameter exists, try javascript click instead of selenium """ js = util.par2bool(kwargs.get('js', False)) dbl_click = util.par2bool(kwargs.get('doubleclick', CONFIG["DoubleClick"])) if web_element.is_enabled(): try: if js: js_click(web_element) elif dbl_click: double_click(web_element) else: wd_click(web_element, **kwargs) logger.debug('element clicked') except WebDriverException as e: logger.info('Got {} when tried to click.'.format(e)) if 'text' not in kwargs: raise e if 'text' in kwargs: logger.debug('button clicked. Verifying expected condition..') try: if text_appearance(kwargs['text'], text_appear=text_appear, timeout=kwargs.get('interval')): return True except QWebTimeoutError as e: logger.debug('timeout err') raise QWebUnexpectedConditionError('Unexpected condition') from e return True raise QWebInvalidElementStateError('Element is not enabled')
def verify_no_file_text(text, normalize=False): r"""Verify text not exists in pdf-file. Examples -------- .. code-block:: robotframework VerifyNoFileText Robot Parameters ---------- text : str Text that should not exist. normalize : bool Remove extra newline (\\\\n) Related keywords ---------------- \`VerifyFileText\`, \`VerifyPdfText\` """ _file_exists() try: if ACTIVE_FILE.verify(text, normalize) is True: raise QWebUnexpectedConditionError('Text {} exists in file'.format(text)) except QWebValueMismatchError: return
def get_callable(pw): """Return function by Paceword name if exists.""" lib = BuiltIn().get_library_instance('QWeb') pacewords = lib.__dir__() for paceword in pacewords: if not paceword.startswith('__'): if str(pw).replace(' ', '').lower() == paceword.replace('_', ''): fn = lib.__getattribute__(paceword) return fn raise QWebUnexpectedConditionError('Paceword {} not found'.format(pw))
def prefs_to_dict(prefs): if isinstance(prefs, dict): d = prefs else: prefs_j = "{" + prefs + "}" try: d = json.loads(prefs_j) except json.decoder.JSONDecodeError: try: d = _handle_old_style_prefs(prefs) except QWebUnexpectedConditionError as e: raise QWebUnexpectedConditionError( 'Invalid argument! Experimental opts should given in robot dict ' 'or string in format: key1:value1, key2:value2') from e return d
def perform(*args, **kwargs): params = signature(fn).parameters args, kwargs = _args_to_kwargs(params, args, kwargs) timeout = get_timeout(**kwargs) err = None msg = None performed = False logger.debug('time to run {}'.format(timeout)) start = time.time() while time.time() < timeout + start: try: return fn(*args, **kwargs) except QWebValueMismatchError as mismatch: if 'text_appearance' not in str( fn) and 'get_or_compare_text' not in str(fn): err = QWebValueError msg = mismatch logger.trace('Value mismatch: {}'.format(mismatch)) continue except (QWebElementNotFoundError, UnexpectedAlertPresentException): logger.debug('Not found') time.sleep(SHORT_DELAY) except QWebValueError as ve: if performed: break raise ve except (QWebStalingElementError, StaleElementReferenceException) as S: if 'execute_click' in str(fn) or 'text_appearance' in str(fn): logger.info('Got staling element err from retry click.' 'Action is probably triggered.') raise QWebUnexpectedConditionError(S) raise QWebStalingElementError('Staling element') except (WebDriverException, QWebDriverError) as wde: if 'alert' in str(fn): time.sleep(LONG_DELAY) logger.info( "Got webdriver exception..{}. Retrying..".format(wde)) err = QWebDriverError msg = wde else: raise QWebDriverError(wde) if msg: raise err(msg) raise QWebTimeoutError('Timeout exceeded')
def appstate(block, *args): r"""Appstate is a pre-condition of a test case. It sets Application(s) under test to correct, known state. First keyword of every test case is Appstate. It is a navigation system across different states in system under test, or between separate applications. They are typically set under resources folder, keywords.robot file. Examples -------- .. code-block:: robotframework Appstate Login #with arguments: Appstate Login fenix rising123 #Example block: Login [Arguments] ${USER}=username ${PASS}=password Goto https://www.qentinel.com TypeText Username ${USER} TypeText Password ${PASS} ClickText Login VerifyText Welcome, ${USER} Parameters ---------- block : str Action word/Block to execute args : any Possible args for block Related keywords ---------------- \`RunBlock\`, \`SetConfig\` """ status, res = BuiltIn().run_keyword_and_ignore_error(block, *args) if status == 'FAIL': raise QWebUnexpectedConditionError( 'Unable to set correct pre-condition for test due error: {}'.format(res))
def verify_no_file_text(text): """Verify text not exists in pdf-file. Examples -------- .. code-block:: robotframework VerifyNoFileText Robot Parameters ---------- text : str Text that should not exist. """ _file_exists() try: if ACTIVE_FILE.verify(text) is True: raise QWebUnexpectedConditionError( 'Text {} exists in file'.format(text)) except QWebValueMismatchError: return