I’m designing automation scripts utilizing the Cucumber BDD framework for REST APIs utilizing RestAssured. I’ve one API which generates the “Token” after which there’s one other API for order creation which requires this “Token” within the authorization parameter. Right here is my function file:
Characteristic: Create Order API
@Background:
State of affairs Define: Generate Entry token With Legitimate Particulars
Given Question param for request
| grant_type |
| client_credentials |
Given Primary Auth keys for request "" and ""
When Construct request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
# And Set world "access_token" in "token"
And Carry out "POST" request utilizing
Then standing code is 200
And response accommodates "scope"
Examples:
| userName | key |
| AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |
Now the response of the above API is as follows:
{
"scope": "https://uri.pppaypal.com/companies/invoicing https://uri.pppaypal.com/companies/purposes/webhooks",
"access_token": "ALs1szFnv2TJ19Zf3vq",
"token_type": "Bearer",
"app_id": "APP-284543T",
"expires_in": 311286,
"nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}
Now I would like this “access_token” as within the “Create Order API” Authorization parameter with Bearer. The “Create Order API” function file is beneath:
State of affairs: Confirm create order api utilizing legitimate auth
Given Generate request
And Construct request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
And Set header values as
| Content material-Kind | Authorization |
| utility/json | Bearer |
When Carry out "POST" request utilizing "FILE_PATH_ORDER_JSON"
Then standing code is 201
How can I set “access_token” in “token” as a world variable from the function file in order that I can use it wherever on this function file utilizing the next step?
And Set world "access_token" in "token"