Exemplo n.º 1
0
def press_key(locator, key, anchor="1", timeout='0', **kwargs):
    r"""Simulate user pressing keyboard key on element identified by "locator".

    The parameter "key" is either a single character or a keyboard key surrounded by '{ }'.

    Examples
    --------
    .. code-block:: robotframework

        PressKey    text_field     q
        PressKey    text_field     {ENTER}
        PressKey    text_field     {CONTROL + A}    # Select all
        PressKey    text_field     {CONTROL + C}    # Copy selected text
        PressKey    other_field    {CONTROL + V}    # Paste copied text
        PressKey    text_field     {PASTE}          # Paste copied text

    Related keywords
    ----------------
    \`TypeSecret\`, \`TypeText\`, \`WriteText\`
    """
    try:
        input_element = input_.get_input_elements_from_all_documents(
            locator, anchor, timeout=timeout, index=1, **kwargs)
        key = input_handler.check_key(key)
        input_element.send_keys(key)
    except AttributeError as e:
        raise QWebValueError('Could not find key "{}"'.format(key)) from e
Exemplo n.º 2
0
def upload_file(locator, filename, anchor='1', timeout=0, index=1, **kwargs):
    r"""Upload file.

    Examples
    --------
    .. code-block:: robotframework

       UploadFile   Upload      text.txt
       UploadFile   Foo         C:/path/to/file/test.pdf
       UploadFile   1           text.txt #Using index as locator

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

       UploadFile   r1c1        text.txt

    Parameters
    ----------
    locator : str
        Text or index that locates the upload element.
    filename : file to upload
        Default folders = users/downloads and project_dir/files
    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 element. 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.

    Raises
    ------
    ValueError: File not found

    Related keywords
    ----------------
    \`SaveFile\`
    """
    kwargs['css'] = kwargs.get('css', '[type="file"]')
    kwargs['upload'] = util.par2bool(kwargs.get('upload', True))
    filepath = download.get_path(filename)
    if filepath:
        input_element = input_.get_input_elements_from_all_documents(
            locator, anchor, timeout=timeout, index=index, **kwargs)
        input_element.send_keys(str(filepath.resolve()))
        return
    raise QWebFileNotFoundError(
        'Unable to find file {}. Tried from project/files and users/downloads'.
        format(filename))
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def verify_input_element(locator, anchor='1', timeout=0, index=1, **kwargs):
    r"""Verify that input element exist.

    Examples
    --------
    .. code-block:: robotframework

        VerifyInputElement   Username

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        VerifyInputElement   r1c1

    With anchor

    .. code-block:: robotframework

        VerifyInputElement   Password       Username
        VerifyInputElement   r?Qentinel/c3  Robot   #row contains texts Qentinel and Robot, cell 3

    Parameters
    ----------
    locator : str
        Text that locates the element.
    anchor : str
        Text near the checkbox's locator element. If the page contains many
        places where the locator text is then anchor is used to get the
        one that is closest to it. (default None)
    timeout : str | int
        How long we try to 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.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match

    Raises
    ------
    NoSuchElementException: Checkbox element not found

    Related keywords
    ----------------
    \`GetInputValue\`, \`VerifyInputStatus\`, \`VerifyInputValue\`, \`VerifyInputValues\`
    """
    input_element = input_.get_input_elements_from_all_documents(
        locator, anchor, timeout=timeout, index=index, **kwargs)
    if input_element:
        return
Exemplo n.º 5
0
def verify_input_value(locator, expected_value, anchor=u"1", timeout=0, index=1, **kwargs):
    r"""Verify input field has given value.

    Examples
    --------
    .. code-block:: robotframework

        VerifyInputValue    Username          Qentinel
        VerifyInputValue    Phone Nro         0401234567

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        VerifyInputValue     r1c1        0401234567
        VerifyInputValue     r-1c-1      Qentinel  #last row, last cell
        VerifyInputValue     r?Robot/c3  Qentinel  #row that contains text Robot, cell c3

    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 "\".
    expected_value : str
        Text that the input field should contain.
    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
        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.
    |       partial_match: True. If element is found by it's attribute set partial_match
    |       to True to allow partial match

    Raises
    ------
    ValueError
        If the input value is not the same
    """
    input_element = input_.get_input_elements_from_all_documents(
        locator, anchor, timeout=timeout, index=index, **kwargs)
    actions.compare_input_values(input_element, expected_value, timeout=timeout)
Exemplo n.º 6
0
def verify_input_status(locator,
                        status,
                        anchor="1",
                        timeout=0,
                        index=1,
                        **kwargs):
    r"""Verify input field is enabled or disabled.

    In other words verify can user interact with an input field or not.
    Element is considered to be disabled if disabled or readonly attribute exists


    Examples
    --------
    .. code-block:: robotframework

        VerifyInputStatus   Password        Enabled
        VerifyInputStatus   SSN             Disabled
        VerifyInputStatus   SSN             ReadOnly

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        VerifyInputStatus    r1c1        Enabled
        VerifyInputStatus    r-1c-1      Disabled  #last row, last cell

    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 "\\".
    status : str
        Status for the input field. Either enabled, readonly or disabled.
    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.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match

    Raises
    ------
    QWebValueError
        If the field interaction is not the same

    Related keywords
    ----------------
    \`GetInputValue\`, \`VerifyInputElement\`, \`VerifyInputValue\`, \`VerifyInputValues\`
    """
    input_element = input_.get_input_elements_from_all_documents(
        locator,
        anchor,
        timeout=timeout,
        index=index,
        enable_check=True,
        **kwargs)
    if status.lower() == "enabled":
        if not element.is_enabled(input_element) or element.is_readonly(
                input_element):
            raise QWebValueError('The input field was disabled')
    elif status.lower() == "disabled":
        if element.is_enabled(input_element):
            raise QWebValueError('The input field was enabled')
    elif status.lower() == "readonly":
        if not element.is_readonly(input_element):
            raise QWebValueError('readonly attr not found')
    else:
        raise QWebValueError('Unkown status: "{}"'.format(status))
Exemplo n.º 7
0
def type_text(locator, input_text, anchor="1", timeout=0, index=1, **kwargs):
    r"""Type given text to a text field.

    First look through if there are any input fields that have the
    locator as a placeholder. If not then locates the input field by
    which is closest to the locator text.

    When input field is found, it is first cleared of all text and after
    that the text is input.

    Simple Example
    --------------
    .. code-block:: robotframework

         TypeText            username    Qentinel


    Parameters
    ----------
    locator : str | selenium.webdriver.remote.webelement.WebElement
        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 "\\".
        Can also be a WebElement instance returned by GetWebElement keyword or javascript.
    input_text : str
        Text that will be written in the input field
    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 try to 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:
        |       check : bool(True/False)
        |       - Shortcut to switch CheckInputValue on or off for one time use.
        |       - If CheckInputValue is used, use expected parameter when expected value
        |       is different than written value. Expected: str | int
        |       click : bool(True/False)
        |       - Shortcut to switch ClickToFocus on or off for one time use.
        |       - If click is set to True, input field is focused by clicking it before typing.
        |       - CheckInputValue defines if TypeText verifies input field value after it is typed.
        |       - Default is Off. Valid parameters are On, True, Off and False.
        |       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.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match
        |       clear_key: key or character
        |       - used generally if there's problems clearing input field with default methods
        |       - sets what key or key combination is is used to clear the input field
        |       - using clear_key will set clear key
        |       - enclose special keys in curly brackets, for example {CONTROL + a} or {BACKSPACE}
        |       - corresponding configuration parameter is ClearKey

    Examples with settings
    ----------------------
    .. code-block:: robotframework

         SetConfig          CheckInputValue     True
         SetConfig          CheckInputValue     On
         TypeText            username           Qentinel


    SetConfig LineBreak defines what kind of line break is typed after input text. Default is
    tab key.

    .. code-block:: robotframework

        SetConfig           LineBreak   None
        TypeText            username    Qentinel
        TypeText            someattr    Qentinel

    Examples with table
    -------------------


    (Pick table with use table keyword first):

    .. code-block:: robotframework

        TypeText            r1c1        Qentinel
        TypeText            r-1c-1      Qentinel  #last row, last cell
        TypeText            r?Robot/c3  Qentinel  #row that contains text Robot, cell c3

    More Examples
    -------------
    .. code-block:: robotframework

        TypeText            company     Qentinel    clear_key={BACKSPACE}
        TypeText            company     Qentinel    clear_key={CONTROL + a}
        # same thing with using SetConfig
        SetConfig           ClearKey    {BACKSPACE}
        TypeText            company     Qentinel
        SetConfig           ClearKey    {CONTROL + a}
        TypeText            company     Qentinel
        # using WebElement instance
        ${elem}=            GetWebElement  //input[@title\="Search"]
        TypeText            ${elem}     Text to search for

    Related keywords
    ----------------
    \`PressKey\`, \`TypeSecret\`, \`TypeTexts\`, \`WriteText\`
    """
    if isinstance(locator, WebElement):
        input_element = locator
    else:
        input_element = input_.get_input_elements_from_all_documents(
            locator, anchor, timeout=timeout, index=index, **kwargs)
    actions.write(input_element, str(input_text), timeout=timeout, **kwargs)
Exemplo n.º 8
0
def get_webelement(locator,
                   anchor='1',
                   element_type=None,
                   timeout=0,
                   **kwargs):
    r"""Get Webelement using any Paceword -stylish locator.

    Examples
    --------
    Using attributes or xpaths like with ClickElement etc. kw:s without specified
    element_type. If element_type is not specified end result is a type of list:

    .. code-block:: robotframework

        ${list of elems}    GetWebelement          click_me      tag=button
        ${list of elems}    GetWebelement          //*[@id\="click_me"]
        ${list of elems}    GetWebelement          xpath\=//*[@id\="click_me"]

    Get element using element_type attribute to locate element.
    Text elements works as ClickText, VerifyText, GetText etc.:

    .. code-block:: robotframework

        ${elem}      GetWebelement          Log In    element_type=text
        ${elem}      GetWebelement          Contact   element_type=text  anchor=Qentinel
        ${elem}      GetWebelement          Contact   parent=div

    Item, Input, Dropdown, Checkbox elements:

    .. code-block:: robotframework

        ${elem}      GetWebelement          Log In    element_type=item
        ${elem}      GetWebelement          Username  element_type=input
        ${elem}      GetWebelement          Country   element_type=dropdown
        ${elem}      GetWebelement          Gender    element_type=checkbox

    All flags are available for using (timeout, anchor, index, visibility, parent, child etc.).
    in same way as you are using those with Pacewords like ClickText/Item, TypeText, Dropdown etc.

    Parameters
    ----------
    locator : str
        Visible text, attribute value or Xpath expression with or without xpath= prefix.
        The equal sign "=" must be escaped with a "\\".
    anchor : int
        Used when element_type is defined. Default=1 (first match)
    element_type : string
        Define element type/preferred searching method
        (available types: text, input, checkbox, item, dropdown).
    timeout : int
        How long we wait element to appear. Default=10 sec
    kwargs :
        |  Accepted kwargs:
        |       Any available for picked searching method.
        |       See interacting with text, item, input etc. elements from
        |       documentation

    Related keywords
    ----------------
    \`ClickElement\`, \`HoverElement\`, \`TypeText\`
    """
    kwargs['index'] = kwargs.get('index', 1)
    kwargs['timeout'] = timeout
    if element_type:
        if element_type.lower() == 'text':
            return text.get_element_by_locator_text(locator, anchor, **kwargs)
        if element_type.lower() == 'item':
            return text.get_item_using_anchor(locator, anchor, **kwargs)
        if element_type.lower() == "dropdown":
            return dropdown.get_dd_elements_from_all_documents(
                locator, anchor, **kwargs)
        if element_type.lower() == "input":
            return input_.get_input_elements_from_all_documents(
                locator, anchor, **kwargs)
        if element_type.lower() == "checkbox":
            return checkbox.get_checkbox_elements_from_all_documents(
                locator, anchor, **kwargs)
    kwargs['element_kw'] = True
    if 'tag' in kwargs:
        web_elements = element.get_visible_elements_from_elements(
            element.get_elements_by_attributes(kwargs.get('tag'), locator,
                                               **kwargs))
    else:
        web_elements = element.get_webelements(locator)
    if web_elements:
        return web_elements
    raise QWebElementNotFoundError('No matching element found')