Skip to content

Instantly share code, notes, and snippets.

@burcuakkayaa
Created February 2, 2023 11:00
Show Gist options
  • Save burcuakkayaa/1454ce0aadc9565d4df7ef304a83f0b8 to your computer and use it in GitHub Desktop.
Save burcuakkayaa/1454ce0aadc9565d4df7ef304a83f0b8 to your computer and use it in GitHub Desktop.
Feature: Create A new Pet
Background: The Request Body Configuration
# Set a configuration for the payload
* url baseUrl
* def requestPayload = read('classpath:payload/pet.json') #read the json file
* set requestPayload.id = Java.type('utils.TestDataCreator').getID() #get value from java class
* set requestPayload.category.id = Java.type('utils.TestDataCreator').getID() #get value from java class
* set requestPayload.category.name = Java.type('utils.TestDataCreator').getDogCategoryName() #get value from java class
* set requestPayload.name = Java.type('utils.TestDataCreator').getDogName() #get value from java class
* set requestPayload.photoUrls[0] = Java.type('utils.TestDataCreator').getFileName() #get value from java class
* set requestPayload.tags[0].name = requestPayload.name #get value from java class
* set requestPayload.status = Java.type('utils.TestDataCreator').getStatus()[0] #get value from java class
Scenario: Add a new pet to the store
Given header Content-Type = 'application/json'
And path '/v2/pet'
And request requestPayload
When method post
Then status 200
And match response.id == '#present'
And match $.name == requestPayload.name
And match $.category.name == requestPayload.category.name
And match $.status == requestPayload.status
# Find the pet by ID
Given header Content-Type = 'application/json'
And path '/v2/pet/' + response.id
When method get
Then status 200
And match $.id == requestPayload.id
And match $.category.id == requestPayload.category.id
And match $.category.name == requestPayload.category.name
And match $.name == requestPayload.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment