Faram
Faram

Reputation: 555

Robot Framework: Parameterized GUI elements

in Katalon is a very nice way to parameterize the selectors for GUI elements, so that you can easily select very similar elements with the help arguments. I want to do something similar like that in Robot Framework.

EDIT: Better example, that is more easy to understand:

We have several GUI elements we have to interact with when testing. As the elements' selectors are very similar, we want to parameterize specific parts of it. In this case, we want to parametrize the $(selector) part of the selector:

*** Variables ***
$(overview.element}    //div[contains(@class, $(selector)')]

We want to be able to do that, so that we can avoid something like that

*** Variables ***
$(overview.home}    //div[contains(@class, home')]
$(overview.settings}    //div[contains(@class, settings')]
$(overview.overview}    //div[contains(@class, overview')]

We want to give that parameter within the test cases. Means: We can specify which element we want to select. Something like that:

    [Arguments]   ${selector}
Click    $(overview.element)(${selector})

Is that possible? And if yes: How?

Upvotes: 3

Views: 459

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385960

You can use the built-in keyword Replace variables to perform the substitution before using the locator. For this to work you'll have to escape the variable reference when defining ${overview.element}

Example:

*** Variables ***
${overview.element}    //div[contains(@class, \${selector}')]

*** Keywords ***
Example keyword
    [Arguments]  ${selector}
    ${locator}=  Replace variables  ${overview.element}
    log  locator is ${locator}

*** Test cases ***
Example
    example keyword  settings

When you run the above, the log should show this:

enter image description here

Upvotes: 1

Related Questions