0

I would like to use value from keyword 1 to keyword 2. Tried searching on net but i could not able to solve it.

Verify that apps are listed
    wait until element is visible  ${AppMenuGrid}   ${Timeout}      "Apps NOT listed. Step execution failed"
    log     "Apps listed"
    ${APPSCOUNT} =   GET ELEMENT COUNT  ${AppMenuGrid}
    log     "Number of apps loaded are ${APPSCOUNT}"
    [Return]  ${APPSCOUNT}

Click on Refresh button
    wait until element is visible  ${Refresh}   ${Timeout}      "Refresh button is not visible"
    click element  ${Refresh}
    log     "click on refresh button successful"

Verify that same apps are listed
    wait until element is visible  ${AppMenuGrid}   ${Timeout}      "Apps list not refreshed. Step execution failed"
    log     "Apps list refreshed"
    ${APPSRECOUNT} =   GET ELEMENT COUNT  ${AppMenuGrid}
    ${Count} =  verify that apps are listed     ${APPSCOUNT}
    log     "Number of apps before refresh ${Count}"
    log     "Number of apps after refresh ${APPSRECOUNT}"
    run keyword if  "${APPSRECOUNT}" == "${Count}"      log     "Number of apps matching after refresh"
    ...         ELSE        fail        "All apps not loaded after refresh"

I want to use AppsCount value (ex .10) from keyword "Verify that apps are listed" into "Verify that same apps are listed" keyword. But in the 2nd keyword, APPSCOUNT value is always blank.

3 Answers 3

3

Change the keyword Verify that same apps are listed to accept arguments:

Verify that same apps are listed
    [Arguments]    ${expected appscount}
    # the rest of its code

And then, in the case where it's used, pass the value from the first keyword:

A case
    ${the count}=    Verify that apps are listed
    Verify that same apps are listed    ${the count}
0
1

I agree with Todor Minakov's approach, to share the value via return clauses. Here is another approach:

Robot Framework (as described in the User Guide) has notion of variable scope: Local (Keyword) level, Test case level, Test suite level and Global. By default, the variables defined in the keywords have local scope.

To share the value of the variable between two keywords, just add a test case scope to the variable, like this:

Verify that apps are listed
    wait until element is visible  ${AppMenuGrid}   ${Timeout}      "Apps NOT listed.   Step execution failed"
    log     "Apps listed"
    ${APPSCOUNT} =   GET ELEMENT COUNT  ${AppMenuGrid}
    Set Test Variable    ${APPSCOUNT}

Then, you can call ${APPSCOUNT} inside any other keyword in the same test case and it will have the stored value.

3
  • 3
    This will set implicit dependency between the keywords - one has to call Verify that apps are listed to have the variable set, otherwise the other kw will not work - referencing a variable that is not set. Depending on a state - and having an explicit or implicit procedure to create it, is not a good practice; even IMO - a maintenance nightmare. Apr 2, 2019 at 9:03
  • 1
    The use of "above" doesn't make sense. At the time that I write this, there are no answers above this answer. Apr 2, 2019 at 12:44
  • @BryanOakley Because at the time of writing of that answer, it was below the answer of Todor Minakov. But, you are right :)
    – Nomce
    Apr 2, 2019 at 12:45
0

i tried the following and it worked.

In the test case file, i added a variables with the same name ${APPSCOUNT} and set the variables to the keyword like below, Verify that apps are listed ${APPSCOUNT}

After this i can see value from keyword 1 in keyword 2. Is this the correct approach?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.