0

I am trying to utilize a global variable that I set by passing it in as an argument to a keyword but it is not working for some reason. Here's the code:

*** Variables ***
${ENV}              qa
${MOBILE}           0
${BROWSER}          Chrome
${DELAY}            0
${VALID USER}       username
${VALID PASSWORD}   123456
&{SERVER}           qa=https://${PREFIX}.qa.myapp.com
...                 staging=https://${PREFIX}.staging.myapp.com
...                 prod=https://${PREFIX}.myapp.com
${LOGIN URL}        ${SERVER.${ENV}}/
${WELCOME URL}      ${SERVER.${ENV}}/Profile


*** Keywords ***
Begin Web Test
    [Arguments]   ${pf}
    [Tags]      Critical
    Set Global Variable  ${PREFIX}   ${pf}
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Run Keyword If   ${MOBILE} == 1
    ...    Set Window Size    50  800
    ...    ELSE   Maximize Browser Window
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open
    Input Text    username    ${VALID USER}
    Input Text    password     ${VALID PASSWORD}
    Click Button  btn_login
    Location Should Be    ${WELCOME URL}
    Page Should Contain   Update Profile

When I run this I receive an error:

[ ERROR ] Error in file '/path/to/Common.robot': Setting variable '&{SERVER}' failed: Variable '${PREFIX}' not found.

Could someone explain why this doesn't work?

1 Answer 1

2

The variables in the *** Variables *** section are static, and only set once prior to the start of the first test. You cannot expect the variables to automatically update when you change the value of ${PREFIX}.

One solution would be to move the setting of the variables into a keyword that you can call either after defining the global variable, or by passing in the value of ${PREFIX}.

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

1 Comment

Thanks for the proposed solution, that worked like a charm.

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.