Skip to content

Commit 69ea51a

Browse files
Merge pull request #2 from qavajs/fix-issues
Fixed issues and added build steps
2 parents 19c30de + 364353e commit 69ea51a

File tree

8 files changed

+257
-13
lines changed

8 files changed

+257
-13
lines changed

.github/workflows/npm-publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: Node.js Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: 16
18+
- run: npm ci
19+
20+
publish-npm:
21+
needs: build
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v2
26+
with:
27+
node-version: 16
28+
registry-url: https://registry.npmjs.org/
29+
- run: npm ci
30+
- run: npm run build
31+
- run: npm publish --access public
32+
env:
33+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.github/workflows/pull-request.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: 16
16+
- run: npm ci
17+
- run: npm run build

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# @qavajs/api-steps
22
This is a core package to get basic API cucumber steps.
3+
4+
```javascript
5+
const App = require('./page_object');
6+
module.exports = {
7+
default: {
8+
require: [
9+
'@qavajs/steps-config-loader',
10+
'@qavajs/steps-api'
11+
],
12+
browser: {
13+
timeout: {
14+
present: 10000,
15+
visible: 20000
16+
},
17+
capabilities: {
18+
browserName: 'chrome'
19+
}
20+
},
21+
pageObject: new App()
22+
}
23+
}
24+
```
25+
## Parameter Types
26+
27+
[types](docs/parameter_types.md)
28+
29+
## Steps
30+
[api action steps](docs/api_action_steps.md)
31+
32+
[api validation steps](docs/api_validation_steps.md)

docs/api_action_steps.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# API Action Steps
2+
3+
### I send {text} request to {landing-url}{headers} and save response as {text} ✅
4+
5+
Send request to the endpoint
6+
7+
| param | type | description |
8+
|:-----: |:------:|:---------------: |
9+
| method | string | request method |
10+
| url | string | endpoint url |
11+
| headers| Object | object with headers (optional) |
12+
| key | string | key that should be used for saving response |
13+
example:
14+
```gherkin
15+
When I send "GET" request to "$BASE_API_URL" with headers "$headers" and save response as "response"
16+
```
17+
---
18+
### I send {text} request to {landing-url}{headers} with qs {text} and save response as {text} ✅
19+
20+
Send request to the endpoint with query string
21+
22+
| param | type | description |
23+
|:-----: |:------:|:---------------: |
24+
| method | string | request method |
25+
| url | string | endpoint url |
26+
| headers| Object | object with headers (optional) |
27+
| params | string | query string parameters |
28+
| key | string | key that should be used for saving response |
29+
example:
30+
```gherkin
31+
When I send "GET" request to "https://www.some_service.com/some_endpoint" with qs "?category=HR&name=test" and save response as "response"
32+
```
33+
---
34+
### I send {text} request to {landing-url}{headers} with Body {json} and save response as {text} ✅
35+
36+
Send request with body
37+
38+
| param | type | description |
39+
|:-----: |:------:|:---------------: |
40+
| method | string | request method |
41+
| url | string | endpoint url |
42+
| headers | Object | object with headers (optional) |
43+
| requestBody | JSON | request body |
44+
| key | string | key that should be used for saving response |
45+
example:
46+
```gherkin
47+
When I send "POST" request to "$BASE_API_URL" with Body "test_data_file.json" and save response as "response"
48+
```
49+
---
50+
### I send {text} request to {landing-url}{headers} with qs {text} and Body {json} and save response as {text} ✅
51+
52+
Send request with body and query string
53+
54+
| param | type | description |
55+
|:-----: |:------:|:---------------: |
56+
| method | string | request method |
57+
| url | string | endpoint url |
58+
| headers | Object | object with headers (optional) |
59+
| params | string | query string parameters |
60+
| requestBody | JSON | request body |
61+
| key | string | key that should be used for saving response |
62+
example:
63+
```gherkin
64+
When I send "PUT" request to "https://www.some_service.com/some_endpoint/" with qs "?category=HR&name=test" and Body "test_data_file.json" and save response as "response"
65+
```
66+
---
67+
### I send {text} request and save response as {text} to {landing-url}{headers} with Body: ✅
68+
69+
Send request with body that given as part of Cucumber step
70+
71+
| param | type | description |
72+
|:-----: |:------:|:---------------: |
73+
| method | string | request method |
74+
| url | string | endpoint url |
75+
| headers | Object | object with headers (optional) |
76+
| requestBody | JSON | request body |
77+
| key | string | key that should be used for saving response |
78+
example:
79+
```gherkin
80+
When I send "POST" request and save response as "response" to "$BASE_API_URL" with Body:
81+
"""
82+
{
83+
"title": "Test Post Request with Body passed as string"
84+
}
85+
"""
86+
```

docs/api_validation_steps.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Validation Steps
2+
3+
---
4+
### Response {text} Status Code {validation} {text} ✅
5+
6+
Verify response status code
7+
8+
| param | type | description |
9+
|:-----------:|:--------:|:--------------------------:|
10+
| response | Response | saved response |
11+
| validation | Function | function to wait condition |
12+
| statusCode | string | expected status code |
13+
example:
14+
```gherkin
15+
Then Response "$response" Status Code equals to "200"
16+
```
17+
18+
---
19+
### Response {text} contains: ✅
20+
21+
Verify that response contains needed properties
22+
23+
| param | type | description |
24+
|:-------------:|:---------:|:-----------------------------:|
25+
| property | Any | property from saved response |
26+
| dataTable | Object | data table with all properties|
27+
example:
28+
```gherkin
29+
Then Response "$response.payload.data.items" contains:
30+
| _id |
31+
| appId |
32+
| serviceCategory |
33+
```
34+
35+
---
36+
### Response {text} {validation} {text} ✅
37+
38+
Verifying that response model has necessary type
39+
40+
| param | type | description |
41+
|:-----------:|:--------:|:--------------------------:|
42+
| response | Response | saved response |
43+
| validation | Function | function to wait condition |
44+
| type | string | expected property type |
45+
46+
example:
47+
```gherkin
48+
Then Response "$response.payload.data.items" equals to "array"
49+
```
50+
---
51+
### Response {text} size {validation} {text} ✅
52+
53+
Verify that response array size is equal to|less than|greater than given number
54+
55+
| param | type | description |
56+
|:------------:|:--------:|:--------------------------:|
57+
| response | Response | saved response |
58+
| validation | Function | function to wait condition |
59+
| expectedValue| string | expected property size |
60+
61+
example:
62+
```gherkin
63+
Then Response "$response.payload.data.items" size to be above "0"
64+
```
65+
---
66+
### I verify response {text} {validation} {text} ✅
67+
68+
Execute any jsonPath query against response and verify result is equal to expected value
69+
70+
| param | type | description |
71+
|:------------:|:--------:|:--------------------------:|
72+
| response | Response | saved response |
73+
| validation | Function | function to wait condition |
74+
| expectedValue| string | expected property value |
75+
76+
example:
77+
```gherkin
78+
Then I verify response "$response.payload.data.items[0].title" equals to "TEST"
79+
```

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable import/no-unresolved */
2-
require('./lib/index.js');
32
require('./lib/apiActionSteps.js');
43
require('./lib/apiHelpers.js');
54
require('./lib/apiVerificationSteps.js');

src/apiHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fetch, { RequestInit, Response } from 'node-fetch';
55
*
66
* @param {String} url - url that should be requested
77
* @param {RequestInit} params - Object with all needed properties for request
8-
* @returns {Response} response - response object
8+
* @returns {Response} response - response object with payload variable as parsed JSON response body
99
*/
1010
async function sendHttpRequest(url: string, params: RequestInit): Promise<unknown> {
1111
const conf = {
@@ -15,7 +15,7 @@ async function sendHttpRequest(url: string, params: RequestInit): Promise<unknow
1515
...params,
1616
};
1717
const response: Response = await fetch(url, conf);
18-
return response.json();
18+
return { ...response, payload: await response.json() };
1919
}
2020

2121
export { sendHttpRequest };

src/apiVerificationSteps.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { expect } from 'chai';
55
* Comparing response status code with given
66
*
77
* @example
8-
* Response "$response" Status Code is equal "200"
8+
* Response "$response" Status Code equals to "200"
99
*
1010
* @param {String} statusCode should be valid status code
1111
*/
12-
Then('Response {text} Status Code is {validation} {text}', (response: any, validation: any, statusCode: string) => {
12+
Then('Response {text} Status Code {validation} {text}', (response: any, validation: any, statusCode: string) => {
1313
validation(response.status, parseInt(statusCode, 10));
1414
});
1515

1616
/**
1717
* Verifying that response contains all models
1818
*
1919
* @example
20-
* Response "$response.data.items" contains:
20+
* Response "$response.payload.data.items" contains:
2121
* | _id |
2222
* | appId |
2323
* | serviceCategory |
@@ -49,26 +49,26 @@ Then('Response {text} contains:', (property: any, dataTable: any) => {
4949
* Verifying that response model has necessary type
5050
*
5151
* @example
52-
* Response "$response.data.items" is an "array"
52+
* Response "$response.payload.data.items" equals to "array"
5353
*
5454
* @param {String} pathQuery json path
5555
* @param {String} type should be named as expected value type
5656
*/
57-
Then('Response {text} is {validation} {text}', (property: any, validation: any, type: string) => {
58-
validation(property, type);
57+
Then('Response {text} {validation} {text}', (property: any, validation: any, type: string) => {
58+
validation(typeof property, type);
5959
});
6060

6161
/**
6262
* Verify that array size is equal to|less than|greater than given number
6363
*
6464
* @example
65-
* Response "$response.data.items" size is "greater than" "0"
65+
* Response "$response.payload.data.items" size to be above "0"
6666
*
6767
* @param {String} responseElement json path
6868
* @param {String} action should be named as expected action (equal to|less than|greater)
6969
* @param {String} expectedValue Number for comparing with array size
7070
*/
71-
Then('Response {text} size is {validation} {text}', (property: any, validation: any, expectedValue: string) => {
71+
Then('Response {text} size {validation} {text}', (property: any, validation: any, expectedValue: string) => {
7272
const count = property.length;
7373
validation(count, expectedValue);
7474
});
@@ -77,11 +77,11 @@ Then('Response {text} size is {validation} {text}', (property: any, validation:
7777
* Execute any jsonPath query against response and verify result is equal to expected value
7878
*
7979
* @example
80-
* I verify response "$response.data.items[0].title" is equal to "TEST"
80+
* I verify response "$response.payload.data.items[0].title" equals to "TEST"
8181
*
8282
* @param {String} pathQuery jsonPath query
8383
* @param {String} expectedValue value for comparing with result of jsonPath query
8484
*/
85-
Then('I verify response {text} is {validation} {text}', async (property: any, validation: any, expectedValue: string) => {
85+
Then('I verify response {text} {validation} {text}', async (property: any, validation: any, expectedValue: string) => {
8686
validation(property, expectedValue);
8787
});

0 commit comments

Comments
 (0)