1

I am trying the below steps but it throws an error: '${dut1_lmepid_${i}}' no keyword found.

If I use anything like ${temp_var} in place of ${dut1_lmepid_${i}} it works fine though.

: For    ${i}    IN RANGE    1    2
\    ${var} =    Set Variable    dut1_lmepid_${i}
\    ${dut1_lmepid_${i}}=    Run Keyword    get-local-ac-id    me${i}
3
  • Please include the actual error in your question. Commented Jan 7, 2020 at 15:21
  • 1
    Why do you need to dynamically create new variable names? What's wrong with using {temp_var}? If you need to save all of the variables, have you considered using a dictionary or list instead of a bunch of generated variables? Commented Jan 7, 2020 at 15:24
  • Yes, I made use of list to store the values instead of creating dynamic variables. Commented Jan 10, 2020 at 6:56

2 Answers 2

2

It is possible to do this using a second step using the keyword Set Global Variable:

*** Test Cases ***
Test Item
    :For    ${i}    IN RANGE    1    5
    \    ${value} =    Run Keyword    get-local-ac-id    me ${i}
    \     Set Global Variable     ${dut1_lmepid_${i}}    ${value}
    No Operation

*** Keywords ***
get-local-ac-id
    [Arguments]    ${arg}
    [Return]    value ${arg}

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I think you cal also use Set Suite Variable and Set Test Variable in same way
Correct. The scope does not need to be Global, it can be Suite or Test level.
1

This is currently not possible with Robot. You can use "variables inside variables" to resolve the values of variables (see the documentation on this topic) but not to resolve/set the name of the variable itself.

Comments

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.