Skip to content

Commit 54740fe

Browse files
committed
Config&ApiFixes
1 parent f1575f4 commit 54740fe

10 files changed

Lines changed: 455 additions & 422 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,21 @@ $env:ENV="qa"; npm run test:serial
197197
ENV=qa npm run test:serial
198198
```
199199

200-
6. For executing API test cases, please provide "ENV" value as "qaApi" or "devApi" :
200+
6. For executing API test cases, please provide "ENV" value as "qaApi" or "devApi". ReqRes API tests also require `REQRES_API_KEY`, because ReqRes expects the `x-api-key` request header:
201201

202202
**Windows CMD:**
203203
```batch
204-
set ENV=qaApi && npm run test:api
204+
set "ENV=qaApi" && set "REQRES_API_KEY=your_reqres_key" && npm run test:api
205205
```
206206

207207
**Windows PowerShell:**
208208
```powershell
209-
$env:ENV="qaApi"; npm run test:api
209+
$env:ENV="qaApi"; $env:REQRES_API_KEY="your_reqres_key"; npm run test:api
210210
```
211211

212212
**Mac/Linux/WSL:**
213213
```bash
214-
ENV=qaApi npm run test:api
214+
ENV=qaApi REQRES_API_KEY=your_reqres_key npm run test:api
215215
```
216216

217217
7. For recording test scripts :

‎lib/APIActions.ts‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { APIResponse, expect } from '@playwright/test';
33

44
export class APIActions {
55

6+
getReqResHeaders(): Record<string, string> {
7+
const apiKey = process.env.REQRES_API_KEY;
8+
if (!apiKey) {
9+
throw new Error(`REQRES_API_KEY is required because ReqRes now expects an x-api-key header.`);
10+
}
11+
return { 'x-api-key': apiKey };
12+
}
13+
614
async verifyStatusCode(response: APIResponse): Promise<void> {
715
await expect(response, `200 Status code was not displayed.`).toBeOK();
816
}
@@ -23,19 +31,17 @@ export class APIActions {
2331
}
2432

2533
async verifyResponseHeader(expectedResponseHeaderParams: string, responsePart: Array<{ name: string, value: string }>, responseType: string): Promise<void> {
26-
let status = true;
27-
let fieldNames = `Parameter`;
28-
for (let responseKey of responsePart) {
29-
if (!(expectedResponseHeaderParams.includes(responseKey.name.trim()))) {
30-
status = false;
31-
fieldNames = fieldNames + ' ,' + responseKey.name;
32-
break;
33-
}
34-
}
35-
expect(status, `${fieldNames} was not present in ${responseType}`).toBe(true);
34+
const expectedHeaders = expectedResponseHeaderParams
35+
.split(`,`)
36+
.map(header => header.trim().toLowerCase())
37+
.filter(Boolean);
38+
const actualHeaders = new Set(responsePart.map(header => header.name.trim().toLowerCase()));
39+
const missingHeaders = expectedHeaders.filter(header => !actualHeaders.has(header));
40+
41+
expect(missingHeaders, `${missingHeaders.join(`, `)} was not present in ${responseType}`).toEqual([]);
3642
}
3743

3844
async readValuesFromTextFile(fileName: string): Promise<string> {
3945
return fs.readFileSync(`./utils/api/${fileName}.txt`, `utf8`);
4046
}
41-
}
47+
}

0 commit comments

Comments
 (0)