Quick Start
info
Prerequisite: Setup CHKware to continue
A real business story
DummyJSON service a JSON response faker for API. Let's think of a business case based on the listed APIs.
Business scenario:
User should be able to add a post on DummyJSON service.
Test cases:
Suppose our webapp have a page to add a new post. This page also shows some user information. Let's imagine the API test workflow for this page.
- User is able to login. API response have a bearer access_token.
- User is able to get self or me URL to show user information on page.
- User is able to create a post using that bearer access_token.
Test implementation
To implement the above test cases we need to be able to fetch an API response. Fetch multiple different APIs in a flow. Let's do in with CHKware.
Prepare for the project.
- Create a directory in anywhere in your system and give it a meaningful name.
- Now open the console terminal where
chk
command is install. Follow setup steps if it hasn't been done already. - Go to the directory in console using
cd [DIRECTORY]
Login to get bearer access_token
- Create a file called
req-login.chk
. File name has no special significance. Openreq-login.chk
file, and add following:
---
version: default:http:0.7.2
request:
url: https://dummyjson.com/user/login
method: POST
body[json]:
username: emilys
password: emilyspass
expiresInMins: 30
expose:
- <% _response %>
Explanation
Get user's info with bearer access_token
- Create a file called
req-user-me.chk
. File name has no special significance. Openreq-user-me.chk
file, and add following:
---
version: default:http:0.7.2
variables:
AccessToken: ~
request:
url: https://dummyjson.com/user/me
method: GET
auth[bearer]:
token: <% AccessToken %>
expose:
- <% _response %>
Explanation
Create a post using bearer access_token
- Create a file called
req-post-create.chk
. File name has no special significance. Openreq-post-create.chk
file, and add following:
---
version: default:http:0.7.2
variables:
AccessToken: ~
request:
url: https://dummyjson.com/posts/add
method: POST
auth[bearer]:
token: <% AccessToken %>
body[json]:
title: "I am in love with someone."
userId: 5
expose:
- <% _response %>
Explanation
Create the test workflow
- Create a file called
wf-user-post-create.chk
. File name has no special significance. Openwf-user-post-create.chk
file, and add following:
---
version: default:workflow:0.8.0
tasks:
- name: Login with user's credential
uses: fetch
file: "./req-login.chk"
- name: Get user's me
uses: fetch
file: "./req-user-me.chk"
variables:
AccessToken: <% _steps.0._response.body.accessToken %>
- name: Create a post
uses: fetch
file: "./req-post-create.chk"
variables:
AccessToken: <% _steps.0._response.body.accessToken %>
expose:
- <% _steps %>
Explanation
Run the test workflow
To run the workflow write in the console and hit Enter:
$ chk workflow [PATH-TO-DIR]/wf-user-post-create.chk
Workflow:
Steps total: 3, failed: 0
------
+ [PASS] Task: Login with user's credential
>> POST https://dummyjson.com/user/login
------
+ [PASS] Task: Get user's me
>> GET https://dummyjson.com/user/me
------
+ [PASS] Task: Create a post
>> POST https://dummyjson.com/posts/add
Explanation
That's basically it. Now,
- These files can be commit to git.
- These files can be used by you or your teammate/s later to test the same workflow.
- This workflow also can be used in CI/CD for this test case automation.