Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edit grammar
Source Link
Lee Jensen
  • 2.3k
  • 1
  • 12
  • 24

How can iI store a value as global variable from an API response and pass it to another API as parameter in Cucumber feature file using REST assured

I am designing automation scripts onusing the Cucumber BDD framework for REST APIs using Rest assuredRestAssured. I have one apiAPI which generates the "Token" and then there is an another apiAPI for order createcreation which requires this "Token" in the authorisationauthorization parameter. Here is my feature file:

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now the response of the above API is as follows.:

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now iI need this "access_token" as in the "Create Order API" AuthorisationAuthorization parameter withewith Bearer. theThe "Create Order API" feature file is below.:

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can iI set "access_token" in "token" as a global variable from the feature file so that iI can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"

How can i store a value as global variable from an API response and pass it to another API as parameter in Cucumber feature file using REST assured

I am designing automation scripts on Cucumber BDD framework for REST APIs using Rest assured. I have one api which generates the "Token" and then there is an another api for order create which requires this "Token" in the authorisation parameter. Here is my feature file

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now response of above API is as follows.

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now i need this "access_token" as in the "Create Order API" Authorisation parameter withe Bearer. the "Create Order API" feature file is below.

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can i set "access_token" in "token" as global variable from the feature file so that i can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"

How can I store a value as global variable from an API response and pass it to another API as parameter in Cucumber feature file using REST assured

I am designing automation scripts using the Cucumber BDD framework for REST APIs using RestAssured. I have one API which generates the "Token" and then there is another API for order creation which requires this "Token" in the authorization parameter. Here is my feature file:

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now the response of the above API is as follows:

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now I need this "access_token" as in the "Create Order API" Authorization parameter with Bearer. The "Create Order API" feature file is below:

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can I set "access_token" in "token" as a global variable from the feature file so that I can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"
Bumped by Community user
Bumped by Community user
added 11 characters in body
Source Link
iAutomate
  • 359
  • 2
  • 6
  • 15

I am designing automation scripts on Cucumber BDD framework for REST APIs using Rest assured. I have one api which generates the "Token" and then there is an another api for order create which requires this "Token" in the authorisation parameter. Here is my feature file

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now response of above API is as follows.

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now i need this "access_token" inas in the "Create Order API" Authorisation parameter withe Bearer. the "Create Order API" feature file is below.

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can i set "access_token" in "token" as global variable from the feature file so that i can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"

I am designing automation scripts on Cucumber BDD framework for REST APIs using Rest assured. I have one api which generates the "Token" and then there is an another api for order create which requires this "Token" in the authorisation parameter. Here is my feature file

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now response of above API is as follows.

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now i need this "access_token" in the "Create Order API". the "Create Order API" feature file is below.

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can i set "access_token" as global variable from the feature file so that i can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"

I am designing automation scripts on Cucumber BDD framework for REST APIs using Rest assured. I have one api which generates the "Token" and then there is an another api for order create which requires this "Token" in the authorisation parameter. Here is my feature file

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now response of above API is as follows.

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now i need this "access_token" as in the "Create Order API" Authorisation parameter withe Bearer. the "Create Order API" feature file is below.

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can i set "access_token" in "token" as global variable from the feature file so that i can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"
Source Link
iAutomate
  • 359
  • 2
  • 6
  • 15

How can i store a value as global variable from an API response and pass it to another API as parameter in Cucumber feature file using REST assured

I am designing automation scripts on Cucumber BDD framework for REST APIs using Rest assured. I have one api which generates the "Token" and then there is an another api for order create which requires this "Token" in the authorisation parameter. Here is my feature file

Feature: Create Order API

  @Background:
  Scenario Outline: Generate Access token With Valid Details
    Given Query param for request
      | grant_type         |
      | client_credentials |
    Given Basic Auth keys for request "<userName>" and "<key>"
    When Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set global "access_token" in "token"
    And Perform "POST" request using
    Then status code is 200
    And  response contains "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now response of above API is as follows.

{
    "scope": "https://uri.pppaypal.com/services/invoicing https://uri.pppaypal.com/services/applications/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now i need this "access_token" in the "Create Order API". the "Create Order API" feature file is below.

 Scenario: Verify create order api using valid auth
    Given Generate request
    And Build request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content-Type     | Authorization                                                                                            |
      | application/json | Bearer <token> |
    When Perform "POST" request using "FILE_PATH_ORDER_JSON"
    Then status code is 201

How can i set "access_token" as global variable from the feature file so that i can use it anywhere in this feature file using the following step?

And Set global "access_token" in "token"