1

I struck in one problem in which I want to store Value returned from 1st keyword in variable during initial run and then using that variable in another keywords without running the 1st keyword again .

I tried below code but not able to resolve the issue.

Create Account Post Request
    ${response}=    call post request    ${headers2}    ${base_url}   ${base_url_account}    ${account_data}
    log    ${response}
    Should Be True     ${response.status_code} == 201
    ${account_id}    get value from json     ${response.json()}    id
    log    ${account_id}
    RETURN    ${account_id}

Get Network ID    --> [While running this keyword Create Account Post Request will run again which updates the account ID which I don't want]
    ${acc}=   Create Account Post Request  --> [During this It will run Create Account Post Request again which I don't want]
    log    ${acc}

My questions are :

  1. How to use account_ID in any keywords without running the first keyword again and again ?
  2. How to use return value from 1st keyword in any other keywords? [Condition, I don't want to run 1st keyword again to get the return value]

Below scenario is expected :

  1. 1st Keyword ran

  2. 1st Keyword return some value

  3. Store value in some variable

  4. Use returned value anywhere in the suite file, in any keyword within the suite, in any test case.

2 Answers 2

0
  • Possible solutions could be :
    1. Create a new keyword that calls all the other keywords, and then call that from Run keyword if. This might be the most readable solution, but need to write and document another keyword
    2. Use a combination of Run keyword if and Run keywords, like so:
    | | Run Keyword if | '${account_id}' == 'Something'
    | | ... | Run Keywords
    | | ... | Get Network ID | account_id=Something
    | | ... | AND | '${acc}' Should Be  |  acc=someID | some error code
    | | ... | ELSE
    | | ... | Create Account Post Request 

Another solution could be :

${acc} = Run keyword and return status
| | ... | Get Network ID | account_id=Something
| | ... | Run Keywords if  ${account_id} == 'Empty'
| | ... | Create Account Post Request
0
KW1
   ${data}   Set Variable    ${value}
   Return From Keyword    ${data}
KW2
    ${msg_returned}    Set Variable    KW1
    Set Global Variable    ${msg_returned}
KW3
    Log to console    ${msg_returned}

Your Answer

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

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