Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/test/java/com/znsio/api/userPostsAndAlbumsAPI.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@userPostsandAlbums @prod
# TARGET_ENVIRONMENT=prod TYPE=api TAG=@getUserPosts ./gradlew test

Feature: Fetch user details wrt jsonPlaceHolder api
Background:
* def jsonPostsData = read('classpath:com/znsio/templates/postsData.json')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these variable is not common throughout scenarios, initialise them in scenario level.

* def jsonAlbumsData = read('classpath:com/znsio/templates/albumsData.json')

@getUserPosts
Scenario Outline: Get posts for a specific user
Given def getUserPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts',{'user_Id' : <userId>,status:<status>})
Then karate.log("Response from GET request for posts : ", getUserPosts.response)
And match each getUserPosts.response[*].userId == <userId>
And match each getUserPosts.response[*] == jsonPostsData.postSchema
Examples:
| userId | status |
| 1 | 200 |
| 110 | 404 |
| | 404 |
| *^$#^& | 400 |
| null | 400 |

@getUserAlbums
Scenario Outline: Get albums for a specific user
Given def getUserAlbums = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserAlbums',{user_Id: <userId>,"status":<status>})
Then karate.log("Response from get request for albums :", getUserAlbums.response)
And match each getUserAlbums.response[*].userId == <userId>
And match each getUserAlbums.response[*] == jsonAlbumsData.albumSchema
Examples:
| userId | status |
| 1 | 200 |
| 110 | 404 |
| | 404 |
| *^$#^& | 404 |
| null | 400 |

9 changes: 9 additions & 0 deletions src/test/java/com/znsio/templates/albumsData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"albumSchema":
{
"userId": "#number",
"id": "#number",
"title": "#string"
}
}

33 changes: 33 additions & 0 deletions src/test/java/com/znsio/templates/postsData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"postSchema":
{
"userId": "#number",
"id": "#number",
"title": "#string",
"body": "#string"
},

"createdPostSchema":
{
"title": "#string",
"body": "#string",
"userId": "#number",
"id": "#number"
},

"Payload":
{
"title": "ABC_10",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use randomiser functions to generate data.

"body": "Sample blog",
"userId": 1
},

"Payload_patch":
{
"title": "Modified_title"
},

"id": 101,
"status":200
}

36 changes: 36 additions & 0 deletions src/test/java/com/znsio/templates/userTemplates.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@usertemplate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File name is incorrect. Please give suitable name for Template.

Feature: Template for JsonPlaceHolder api

Background:
* print "jsonPlaceHolder url " + env.jsonPlaceholderUrl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Karate.log() instead using print.

Given url env.jsonPlaceholderUrl

@t_getUserPosts
Scenario: Get all the posts for a given user
# * def query = {userId:'#(user_Id)'}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented lines.

Given path '/posts'
And params {userId:'#(user_Id)'}
When method GET
Then karate.log("Response status is ", responseStatus)
And match responseStatus == status

@t_getUserAlbums
Scenario: Get albums for a given user
Given path '/users/' + user_Id + '/albums'
When method GET
Then karate.log("Response status is ", responseStatus)
And match responseStatus == status

@t_createPost
Scenario: Create a post
Given path '/posts'
And request payload
When method POST
Then status 201

@t_updatePost
Scenario: Update a post
Given path '/posts'
And request payload
When method PATCH
Then status 200
21 changes: 21 additions & 0 deletions src/test/java/com/znsio/workflow/userPosts.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@prod @userWorkFlow
#TARGET_ENVIRONMENT=prod TYPE=workflow TAG=@userPost ./gradlew test

Feature: Create and Update post - JsonPlaceHolder API
Background:
* def jsonPostsData = read('classpath:com/znsio/templates/postsData.json')

@createAndUpdatePost
Scenario: Create a post and update title later
Given def createPost = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_createPost', {'payload': jsonPostsData.Payload})
Then karate.log('Created post response', createPost.response)
And match createPost.response.id == jsonPostsData.id
And match createPost.response.title == jsonPostsData.Payload.title
And match createPost.response == jsonPostsData.createdPostSchema
Given def getPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts', {'user_Id': createPost.response.userId,'status':jsonPostsData.status})
And match getPosts.response.length == '#notpresent'
Then def updatePost = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_updatePost', {'Id': jsonPostsData.id, 'payload': jsonPostsData.Payload_patch})
Then karate.log("Response for the updated post", updatePost.response)
Then match updatePost.response.title == Payload_patch.title
Given def getPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts',{'user_Id': createPost.response.userId,'status':jsonPostsData.status})
Then match getPosts.response.title == "#notpresent"
3 changes: 2 additions & 1 deletion src/test/java/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"baseUrl": "https://github.com",
"confEngineUrl": "https://confengine.com/api/v3",
"dummyRestAPIUrl": "https://jsonplaceholder.typicode.com",
"restCountryUrl": "https://restcountries.com/v3.1"
"restCountryUrl": "https://restcountries.com/v3.1",
"jsonPlaceholderUrl": "https://jsonplaceholder.typicode.com"
}
}
}