Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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/fetchPostsAndAlbums.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@UserPosts @prod
Feature: Fetch User Posts and Albums

Background:
* def userId = 1
* def testData = read('classpath:com/znsio/templates/userData.json')

@getPosts
Scenario: Get posts with specific User id
* def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": userId, expectedStatus: 200})
* karate.log('response : ',fetchPosts.response)
* match each fetchPosts.response[*].userId == userId
* match fetchPosts.response.userId == '#number'
* match fetchPosts.response.id == '#number'
* match fetchPosts.response.title == '#string'
* match fetchPosts.response.body == '#string'


@getPosts
Scenario: Get posts with user id that doesn't exist
* def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": 100, expectedStatus: 200})
* karate.log('response : ',fetchPosts.response)
* assert fetchPosts.response.arr == null

@getComments
Scenario: Get albums with specific User id
* def fetchAlbums = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getAlbums', {"userId": userId, expectedStatus: 200})
* karate.log('response : ',fetchAlbums.response)
* match each fetchAlbums.response[*].userId == userId
* match each fetchAlbums.response == testData.expectedAlbumResponse

@getComments
Scenario: Get albums with User id that doesn't exist
* def fetchAlbums = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getAlbums', {"userId": 100, expectedStatus: 200})
* karate.log('response : ',fetchAlbums.response)
* assert fetchAlbums.response.arr == null
36 changes: 36 additions & 0 deletions src/test/java/com/znsio/templates/fetchPostAndAlbums.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@template
Feature: Template for User Posts and Comments

Background:
* url env.jsonPlaceholderUrl

@t_getPost
Scenario: Get User posts
Given path '/posts/' + userId
When method GET
Then match responseStatus == expectedStatus
* print "response", response

@t_getAlbums
Scenario: Get User albums
Given path '/albums'
* param userId = userId
When method GET
Then match responseStatus == expectedStatus
* print "response",response

@t_createPost
Scenario: Create User posts
Given path '/posts'
* request {"userId": "#(userId)", "title": "#(title)", "body": "#(body)"}
When method POST
Then match responseStatus == expectedStatus
* print "response",response

@t_updatePost
Scenario: Create User posts
Given path '/posts/' + userId
* request {"title": "Kanishk Jain"}
When method PUT
Then match responseStatus == expectedStatus
* print "response",response
13 changes: 13 additions & 0 deletions src/test/java/com/znsio/templates/userData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"expectedPostsResponse": {
"userId": "#number",
"id": "#number",
"title": "#string",
"body": "#string"
},
"expectedAlbumResponse": {
"userId": "#number",
"id": "#number",
"title": "#string"
}
}
22 changes: 22 additions & 0 deletions src/test/java/com/znsio/workflow/CreateAndUpdatePost.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@prod
Feature: Create and Update User Posts

Background:
* def userId = generateRandomNumber(3)
* def title = generateAlphaNumericRandomString(5)
* def body = generateAlphaNumericRandomString(10)

@createPost
Scenario: Create a User post and then Update its title
* def createPost = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_createPost', {"userId": userId, "title": title, "body": body, expectedStatus: 201})
* karate.log('response : ',createPost.response)
* def id = createPost.response.userId
* def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": id, expectedStatus: 200})
* match fetchPosts.response.userId == userId
* match fetchPosts.response.title == title
* match fetchPosts.response.body == body
* def newTitle = generateAlphaNumericRandomString(5)
* def updatePost = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_updatePost', {"title": newTitle, expectedStatus: 201})
* karate.log('response : ',updatePost.response)
* def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": id, expectedStatus: 200})
* match fetchPosts.response.title == newTitle
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"
}
}
}