Disc-Addict
Disc-Addict

Reputation: 148

simplify/implizit variable assignment in robotframework

consider the following robotframework code example:

*** Variables ***
${VAR_1}          any value
${VAR_2}          another value

*** Test Cases ***
For Example only
    ${VAR_1}=    Some Conversion    ${VAR_1}
    ${VAR_2}=    Some Conversion    ${VAR_2}
    A User Keyword    ${VAR_1}    ${VAR_2}

Desired Notation
    A User Keyword    Some Conversion    ${VAR_1}    Some Conversion    ${VAR_2}

*** Keywords ***
Some Conversion
    [Arguments]    ${value_to_convert}
    ${value_to_convert}=    Catenate    ${value_to_convert}    Foobar
    [Return]    ${value_to_convert}

A User Keyword
    [Arguments]    ${arg1}    ${arg2}
    Log    ${arg1}
    Log    ${arg2}

Question: is there a possibility to simplify the working testcase For Example only to the (non working) Desired Notation - or - can I somehow use the return value of a keyword to be passed as parameter without doing an explicit assignment before?

For clarification:

Upvotes: 0

Views: 66

Answers (2)

A. Kootstra
A. Kootstra

Reputation: 6961

The argument value assignment of a keyword can not be the return value of another keyword.

As highlighted by @Bryan Oakly it is possible to mimic the appearance with some clever usage of Run keyword, as you highlighted this will not work as the assignment may not always be using keywords or even keywords with the same number of arguments.

So, the best approach is what you've already been doing, assigning the value to a variable and then the variable to the keyword argument.

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 385960

Yes, it is possible. You can write your own keywords that call other keywords which are passed in as arguments

It would look something like this:

*** Keywords ***
A User Keyword
    [Arguments]  ${keyword1}  ${var1}  ${keyword2}  ${var2}
    ${var1}=  Run keyword  ${keyword1}  ${var1}
    ${var2}=  Run keyword  ${keyword2}  ${var2}
    log  ${var1}
    log  ${var2}

You would use this keyword exactly like in your example:

A User Keyword  Some Conversion  ${VAR_1}  Some Conversion  ${VAR_2}

Upvotes: 3

Related Questions