0

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:

  • Some Conversion would be far more complex and is implemented within a jrobotremotelibrary
  • Moving the assingments to A User Keyword is no useful solution, because there will be many keywords with different amount of parameters using the same functionality

2 Answers 2

3

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}
Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

A very hard decision which answer to accept. In my case yours would be the correct one (not possible in my intended way) - but the provided workaround from @Bryan Oakly may help more people stumbling accross the same problem. Thanks for clarification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.