0

I am new to RF and I encountered the 'Variable not found' error. I was trying to pass a user-defined variable under a user-defined keyword.

The code is as below

Decimal selection

[Arguments]      ${decimalval}

${decimalval} =   Set variable If
...               '${decimalval}'=='0'       //md-option[@value='0dp']
...               '${decimalval}'=='1'       //md-option[@value='1dp']  
...               '${decimalval}'=='2'       //md-option[@value='2dp']            

[return]          ${decimalval} 

And once ${decimalval} is set with "//md-option[@value='#dp']" based on the condition, I try to use it under a user-defined keyword as below

Click Element       ${decimalval}

This is where the code fails and throws the variable not found error.

Any help would be greatly appreciated. Thanks.

2
  • 2
    Your keyword is setting the value and returning it. Is the code that is calling the keyword saving the return value? Please show an example test case that uses this keyword. Commented Mar 4, 2019 at 17:26
  • Hi Bryan, thanks very much. That helped! It is working now. Commented Mar 7, 2019 at 16:25

1 Answer 1

2

Like Bryan mentioned in the comments, you are returning a value from the keyword. So there should be a variable to hold the return value while calling the keyword.

*** Test cases ***
Locator test
    ${decimalValueLocator}    Decimal selection    ${decimalval}
    Log to console    ${decimalValueLocator}
    Click element     ${decimalValueLocator}

*** Keywords ***
Decimal selection

    [Arguments]      ${decimalval}

    ${decimalval} =   Set variable If
    ...               '${decimalval}'=='0'       //md-option[@value='0dp']
    ...               '${decimalval}'=='1'       //md-option[@value='1dp']  
    ...               '${decimalval}'=='2'       //md-option[@value='2dp']            

    [return]          ${decimalval} 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Sameem, thanks for explaining it in detail. That helped. It is working now!

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.