I am trying to pass the value of one variable from one Test Case in a script to Another Test Case in the same script? I have used ${grabv1} to reuse in the second Test Case. In my case, the value of ${grabv1} seem to be empty.
If anyone came across such situation please let me know.
Thanks in advance.
*** Variables ***
${API_Base_Endpoint} --------- link to the host ------
${Token} Bearer ADMIN
${Create} mutation{ create (realm: “test_realm”, owner: “test_owner”) { id token realm } }
${grabv1}
*** Test Cases ***
Revoke A User
create session API_Testing ${API_Base_Endpoint}
${headers}= create dictionary Authorization=${Token} Content-Type=application/graphql
${response}= post request API_Testing /graphql data=${Create} headers=${headers}
${contents}= to json ${response.content}
${grab_token}= get value from json ${contents} $.data.create.token
log to console ${grab_token}
${GRAB_TOKEN_STRING}= convert to string ${grab_token}
${GRAB_TOKEN_STRING}= remove string ${GRAB_TOKEN_STRING} [ ] ’
${grabv}= set variable “${GRAB_TOKEN_STRING}”
set global variable ${grabv1} ${grabv}
log to console ${grabv}
*** Variables ***
${API_Base_Endpoint1} ---------link to the host---------
${Token1} Bearer ADMIN
${grabv}
${Revoke0} mutation{ revoke (token: ${grabv1} , reason: “nono”) { id token reason } }
*** Test Cases ***
Revoke 01
create session API_Testing ${API_Base_Endpoint}
${headers1}= create dictionary Authorization=${Token} Content-Type=application/graphql
${response1}= post request API_Testing /graphql data=${Revoke0} headers=${headers1}
${contents_revoked}= to json ${response1.content}
log to console ${Revoke0}
log to console ${contents_revoked}
Actually I would need the value extracted from the first test case and use it in the second one in the same execution. How do I do that? I tried to do that in the past under same test case. I end up getting errors when passing the variable in the “request” of the second variable.
I am stuck at this point. can you please help me rewrite the script so that I understand and use in different scenarios.
“Getting a value from a request and store that value in a variable. Then use that value of the variable in another variable to send another request”
A test suite file should have only one Variables, Settings, Test Cases, Keywords, sections.
Then you can try the Set Suite Variable (valid for after setting the value). But I thinks that Set Global Variable should have also worked. You need to confirm in User Reference doc.
Hi,
I have created 1 test case according to what you said and used set global variable. Yet I get the following error: Revoke A User | FAIL | ValueError: too many values to unpack (expected 2)
*** Test Cases ***
Revoke A User
create session API_Testing ${API_Base_Endpoint}
${headers}= create dictionary Authorization=${Token} Content-Type=application/graphql
${response}= post request API_Testing /graphql data=${Create} headers=${headers}
${contents}= to json ${response.content}
${grab_token}= get value from json ${contents} $.data.create.token
log to console ${grab_token}
${GRAB_TOKEN_STRING}= convert to string ${grab_token}
${GRAB_TOKEN_STRING}= remove string ${GRAB_TOKEN_STRING} [ ] ’
${grabv}= set variable “${GRAB_TOKEN_STRING}”
set global variable ${GRABV1} ${grabv}
log to console ${GRABV1}
${Revoke0}= set variable mutation{ revoke (token: ${GRABV1} , reason: “nono”) { id token reason } }
${response1}= post request API_Testing /graphql data=${Revoke0} headers=${headers}
log to console ${Revoke0}
${contents_revoked}= to json ${response1.content}
log to console ${contents_revoked}