def test_get_substring(): assert get_substring('9\xa0700') == '9 700' assert get_substring('42 02,00', float=True) == 4202.00 assert get_substring('333 44', int=True) == 33344 assert isinstance(get_substring('42 02,00', int=True), int) assert isinstance(get_substring('42 02,00', float=True), float) with pytest.raises(QWebValueMismatchError): get_substring('foobar', float=True) with pytest.raises(QWebValueMismatchError): get_substring('foobar', int=True)
def get_list(index=None, **kwargs): """Verify that text is not in the list. Examples -------- .. code-block:: robotframework UseList Qentinel ${LIST} GetList #Get list to variable ${VAL} GetList 2 #Get value from list index 2 #Get substring from list index 1 ${VAL} GetList 1 between=word???another Parameters ---------- index : if given, gets text only from that index. kwargs : | Accepted kwargs: | between : str/int - Start???End - Return all chars between texts Start and End. | from_start : int - Return x amount of chars. Starting from first char | from_end : int - Return x amount of chars. Starting from last char | include_locator : True - Starting text is part of returned string | exclude_post : False - Ending text is part of returned string | int : True - Return integer instead of string | float : int - Return float instead of string """ active = ACTIVE_LIST.update_list() if index: index = _check_index(index) text = active.web_list[index] return util.get_substring(text, **kwargs) return active.web_list
def get_input_value(locator, anchor='1', timeout=0, index=1, **kwargs): r"""Get input value from input field. Examples -------- .. code-block:: robotframework ${value}= GetInputValue OrderNro ${value}= GetInputValue OrderNro Submit ${value}= GetInputValue someattrs from_end=3 int=True #Return empty if there is not value in input element: ${value}= GetInputValue OrderNro blind=True With table(Pick table with use table keyword first): .. code-block:: robotframework ${value}= GetInputValue r1c1 ${value}= GetInputValue r?OrderNro/c1 My Order Parameters ---------- locator : str Text that locates the input field. The input field that is closest to the text is selected. Also one can use xpath by adding xpath= prefix and then the xpath. Error is raised if the xpath matches to multiple elements. When using XPaths, the equal sign "=" must be escaped with a "\". anchor : str Index number or text near the input field's locator element. If the page contains many places where the locator is then anchor is used to select the wanted item. Index number selects the item from the list of matching entries starting with 1. Text selects the entry with the closest distance. timeout : str | int How long we find element before failing. Default 10 (seconds) index : int If table cell contains more than one input elements or if there is some kind of nested structure inside of given input index may needed. Default = 1 (first) kwargs : | Accepted kwargs: | limit_traverse : False. If limit traverse is set to false we are heading up to | fifth parent element if needed when finding relative input element for some label. | between : str/int - Start???End - Return all chars between texts Start and End. | from_start : int - Return x amount of chars. Starting from first char | from_end : int - Return x amount of chars. Starting from last char | include_locator : True - Starting text is part of returned string | exclude_post : False - Ending text is part of returned string | int : True - Return integer instead of string | float : int - Return float instead of string | partial_match: True. If element is found by it's attribute set partial_match | to True to allow partial match | blind : True - Return empty instead of error if input element is empty """ input_element = input_.get_input_elements_from_all_documents( locator, anchor, timeout=timeout, index=index, **kwargs) val = actions.input_value(input_element, timeout=timeout, **kwargs) return util.get_substring(val, **kwargs)
def compare_input_values(input_element, expected_value, timeout): # pylint: disable=unused-argument try: real_value = util.get_substring(input_value(input_element, timeout="0.5s")) except QWebValueError: real_value = "" logger.debug('Real value: {}, expected value {}'.format(real_value, expected_value)) if fnmatch.fnmatch(real_value.strip(), expected_value): return True raise QWebValueMismatchError('Expected value "{}" didn\'t match to real value "{}"' .format(expected_value, real_value))
def get_cell_text(coordinates, anchor="1", timeout=0, **kwargs): r"""Get cell text to variable. Locates cell by coordinates from active table and return value Examples -------- .. code-block:: robotframework ${value} GetCellText r2c3 ${value} GetCellText r-2c5 #Row is second to last. Get value from cell c5 ${value} GetCellText r?Robot/c5 #Row contains text Robot. Get value from cell c5 ${value} GetCellText r?Robot/c-1 #Row contains text Robot. Get value from last cell Parameters ---------- coordinates : str Row and column coordinates in table. R specifies row and c column. r1 = first row, r-1 = last row, r?Qentinel/ = row that contains word Qentinel anchor : str If row is located by text which is not unique, use anchor to point correct one. Anchor can be some other text in same row or index. Default = 1 timeout : str | int How long we search before failing. Default = Search Strategy default timeout (10s) kwargs : | Accepted kwargs: | between : str/int - Start???End - Return all chars between texts Start and End. | from_start : int - Return x amount of chars. Starting from first char | from_end : int - Return x amount of chars. Starting from last char | include_locator : True - Starting text is part of returned string | exclude_post : False - Ending text is part of returned string | int : True - Return integer instead of string | float : int - Return float instead of string Raises ------ QWebValueError If the table is not defined by UseTable keyword Related keywords ---------------- \`ClickCell\`, \`GetTableRow\`, \`UseTable\`, \`VerifyTable\` """ table = Table.ACTIVE_TABLE.update_table() if isinstance(ACTIVE_TABLE, Table) is False: raise QWebInstanceDoesNotExistError('Table has not been defined with UseTable keyword') table_cell = table.get_table_cell(coordinates, anchor) try: text = actions.get_element_text(table_cell, timeout=timeout) return util.get_substring(text, **kwargs) except QWebTimeoutError: return ""
def save_file(locator, filename=None, anchor=1, timeout=0, path=None, **kwargs): # pylint: disable=unused-argument r"""Save file using http-request. Needs url of the downloadable content which usually is in element's href attribute. Text or tooltip can be used as a locator (Works as ClickText or ClickItem). If locator element is not the one with href-attribute, tries to get href from closest parent with <a> tag in it. url can be used as a locator too. Available element types without using tag attribute: *a, span, img, li, h1, h2, h3, h4, h5, h6, div, svg, p, button, input\* (\*submit buttons only).* Examples -------- .. code-block:: robotframework SaveFile ClickMe filename.pdf SaveFile tooltip filename.xml # Locators parent or child element is the one with href: SaveFile ClickMe filename.pdf child=a SaveFile tooltip filename.xml parent=div # Create folder for downloadable files: SaveFile ClickMe pdf/filename.pdf SaveFile tooltip xml/filename.xml SaveFile Robot pics/filename.png # Using url as locator SaveFile https://www.robot.fi/robot.xml filename.xml # Get html content of given url SaveFile https://www.qentinel.com qentinel.html Parameters ---------- locator : str Text or item to be "clicked". filename: str Wanted filename anchor : str Text near the element to be clicked or index. If the page contains many places where the text argument is then anchor is used to get the one that is closest to it. (default 1) timeout : str | int How long we wait for element to be ready for click path : str Wanted path for files. Default path is users download folder. kwargs : | Accepted kwargs: | tag : html tag of preferred element - | If tag is used then element is found | by some of it's attribute | parent : str: tag name for clickable parent | child : str: tag name for clickable child. | index : str: use index if there is multiple | childs with same tag name | headers : dict -Pass headers to http request Related keywords ---------------- \`ExpectFileDownload\`, \`UploadFile\`, \`UseFile\`, \`VerifyFile\`, \`VerifyFileDownload\` """ if locator.startswith('http'): url = locator else: url = ajax.get_url_for_http_request(locator, anchor, **kwargs) response = ajax.http_request_with_browser_cookies(url) if not filename: filename = util.get_substring(response.headers.get( 'Content-Disposition', 'filename=unnamed.{}'.format( response.headers.get('Content-Type').split('/')[1].split(';') [0])), between='filename=???') ajax.save_response_as_file(response, filename, path)
def get(self, **kwargs): if kwargs: return util.get_substring(self.content, **kwargs) return self.content