Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@prod
Feature: Get user details
Background:
* def userid = 1

@jsonPlaceHolder
Scenario: Fetch all the posts
* def userResponse = karate.call('classpath:com/znsio/templates/fetchingUserDetailsJsonPlaceHolder.feature@t_getPost', {userId:userid}).listOfPosts

Choose a reason for hiding this comment

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

userResponse name is incorrect. Its not reflecting what it contains.

Choose a reason for hiding this comment

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

??

* print userResponse

Choose a reason for hiding this comment

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

Use karate.log()

Choose a reason for hiding this comment

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

??

* match userResponse.id == userid
* match userResponse.id == '#number'
* match userResponse.title == '#string'
* match userResponse.body == '#string'

@jsonPlaceHolder
Scenario: Fetch all the comments
* def userResponse = karate.call('classpath:com/znsio/templates/fetchingUserDetailsJsonPlaceHolder.feature@t_getComment', {userId:userid}).listOfComments
* print userResponse
* match userResponse.id == userid
* match userResponse.id == '#number'
* match userResponse.name == '#string'
* match userResponse.email == '#string'
* match userResponse.body == '#string'

Choose a reason for hiding this comment

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

For both Posts and Comments API tests are missing. Try out all valid and invalid scenarios to achieve good test coverage!.




Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Feature: Fetching user details

Choose a reason for hiding this comment

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

Feature description is not appropriate. It should reflect overall what is there in this template feature.


Background:
* print "base url "+env.baseUrl
Given url env.baseUrl

@t_getPost
Scenario: Get Posts for particular user id
Given path "/posts/"+userId
When method Get
Then status 200
* def listOfPosts = response

@t_getComment
Scenario: Get Comments for particular user id
Given path "/comments/"+userId
When method Get
Then status 200
* def listOfComments = response

@t_getPosts
Scenario: Get Posts for all the user
And path '/posts'
When method Get
Then status 200
* def posts = response

@t_getComments
Scenario: Get Comments for all the user
And path '/comments'
When method Get
Then status 200
* def comments = response

@t_CreatePost
Scenario: Create new post
And path '/posts'
And request {"title": '#(title)',"body": '#(body)',"userId": '#(userId)'}
When method Post
Then status 201
* def post = response

@t_EditPost
Scenario: Edit already created post
And path '/posts/'+id
And request input
When method Patch
Then status 200
* def edit = response

4 changes: 4 additions & 0 deletions src/test/java/com/znsio/userDetails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Practice1",
"body": "BYE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@prod
Feature: Edit the post

@createPost
Scenario Outline: Edit the post by creating it
Given json postedDetails = karate.call('classpath:com/znsio/templates/fetchingUserDetailsJsonPlaceHolder.feature@t_CreatePost', {title:'<title>',body:'<body>',userId:'<userId>'}).post
* print postedDetails
* match postedDetails.title == '<title>'
* match postedDetails.body == '<body>'
* match postedDetails.userId == '<userId>'
* def id = postedDetails.userId
* print "generated id is ", id

* def input = read('classpath:com/znsio/userDetails.json');
Given json editedDetails = karate.call('classpath:com/znsio/templates/fetchingUserDetailsJsonPlaceHolder.feature@t_EditPost', {input : input,id : id}).edit
* print editedDetails
* match editedDetails.title == input.title
* match editedDetails.body == input.body
* match editedDetails.title == '#string'
* match editedDetails.body == '#string'

Examples:
| title |body|userId|
| Practice| hello | 50|
2 changes: 1 addition & 1 deletion src/test/java/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"prod": {
"env": {
"baseUrl": "https://github.com",
"baseUrl": "https://jsonplaceholder.typicode.com",
"confEngineUrl": "https://confengine.com/api/v3",
"dummyRestAPIUrl": "https://jsonplaceholder.typicode.com",
"restCountryUrl": "https://restcountries.com/v3.1"
Expand Down