Skip to content

Commit cd965e2

Browse files
committed
API Status code validation changes
1 parent 7b2c65d commit cd965e2

File tree

8 files changed

+542
-490
lines changed

8 files changed

+542
-490
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ allure-results/
44
allure-report/
55
html-report/
66
Downloads/
7+
html-report.zip/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bonus:
5353

5454
- Supports PostgresSQL using 'pg' module.
5555
- Supports Excel File Read/Write using 'excel-js' module.
56+
- Converts HTL Reports to Zip format which can shared across.
5657

5758
### Built With
5859

html-report.zip

-2.88 MB
Binary file not shown.

lib/APIActions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import fs from 'fs';
2-
import { expect } from '@playwright/test';
2+
import { APIResponse, expect } from '@playwright/test';
33

44
export class APIActions {
55

6-
async verifyStatusCode(actual: number, expected: number): Promise<void> {
6+
async verifyStatusCode(response:APIResponse): Promise<void> {
77
try {
8-
expect(actual).toBe(expected);
8+
await expect(response).toBeOK();
99
}
1010
catch (exception) {
11-
throw new Error(`${expected} status code was not displayed.`);
11+
throw new Error(`200 Status code was not displayed.`);
1212
}
1313
}
1414

package-lock.json

+525-475
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "npx playwright test",
8-
"test:single": "npx playwright test GET.test.ts --project=API",
8+
"test:single": "npx playwright test POST.test.ts --project=API",
99
"test:parallel": "npx playwright test --grep @Smoke --project=Chrome",
1010
"test:serial": "npx playwright test --grep @Smoke --workers=1 --project=Chrome",
1111
"test:api": "npx playwright test --grep @api --workers=1 --project=Chrome",
@@ -22,20 +22,20 @@
2222
"author": "Akshay Pai",
2323
"license": "MIT",
2424
"dependencies": {
25-
"@playwright/test": "^1.17.1",
25+
"@playwright/test": "^1.18.0",
2626
"@types/adm-zip": "^0.4.34",
27-
"@types/crypto-js": "^4.0.2",
28-
"@typescript-eslint/eslint-plugin": "^5.5.0",
29-
"@typescript-eslint/parser": "^5.5.0",
27+
"@types/crypto-js": "^4.1.0",
28+
"@typescript-eslint/eslint-plugin": "^5.10.0",
29+
"@typescript-eslint/parser": "^5.10.0",
3030
"adm-zip": "^0.5.9",
3131
"cross-env": "^7.0.3",
3232
"crypto-js": "^4.1.1",
33-
"eslint": "^8.4.0",
34-
"eslint-plugin-import": "^2.25.3",
33+
"eslint": "^8.7.0",
34+
"eslint-plugin-import": "^2.25.4",
3535
"exceljs": "^4.3.0",
3636
"experimental-allure-playwright": "0.0.3",
3737
"pg": "^8.7.1",
38-
"playwright": "^1.17.1",
39-
"typescript": "^4.5.2"
38+
"playwright": "^1.18.0",
39+
"typescript": "^4.5.5"
4040
}
4141
}

tests/api/GET.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const apiActions = new APIActions();
55

66
test(`@API getUsers`, async ({ request }) => {
77
const response = await request.get(`/api/users?per_page=1`);
8-
await apiActions.verifyStatusCode(response.status(), 200);
8+
await apiActions.verifyStatusCode(response);
99

1010
//* Body Response Params and Body Response Headers are stored in single text file separated by #
1111
const responseBodyParams = (await apiActions.readValuesFromTextFile(`getUsers`)).split(`#`)[0];

tests/api/POST.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test(`@API postUsers`, async ({ request }) => {
88
//* Body Response Params and Body Response Headers are stored in single text file separated by #
99
const requestBody = JSON.parse((await apiActions.readValuesFromTextFile('postUsers')).split(`#`)[0]);
1010
const response = await request.post(`/api/users`, { data: requestBody });
11-
await apiActions.verifyStatusCode(response.status(), 201);
11+
await apiActions.verifyStatusCode(response);
1212

1313
const responseBodyParams = (await apiActions.readValuesFromTextFile(`postUsers`)).split(`#`)[1];
1414
await apiActions.verifyResponseBody(responseBodyParams, await response.json(), `Response Body`);

0 commit comments

Comments
 (0)