Skip to content

Commit d9b6475

Browse files
committed
expect validations with messsages
1 parent cd965e2 commit d9b6475

File tree

7 files changed

+281
-292
lines changed

7 files changed

+281
-292
lines changed

Diff for: html-report.zip

167 KB
Binary file not shown.

Diff for: lib/APIActions.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ import { APIResponse, expect } from '@playwright/test';
33

44
export class APIActions {
55

6-
async verifyStatusCode(response:APIResponse): Promise<void> {
7-
try {
8-
await expect(response).toBeOK();
9-
}
10-
catch (exception) {
11-
throw new Error(`200 Status code was not displayed.`);
12-
}
6+
async verifyStatusCode(response: APIResponse): Promise<void> {
7+
await expect(response, `200 Status code was not displayed.`).toBeOK();
138
}
149

1510
async verifyResponseBody(expectedResponseBodyParams: string, responsePart: JSON, responseType: string): Promise<void> {
@@ -24,12 +19,7 @@ export class APIActions {
2419
break;
2520
}
2621
}
27-
try {
28-
expect(status).toBe(true);
29-
}
30-
catch (exception) {
31-
throw new Error(`${fieldNames} was not present in ${responseType}`);
32-
}
22+
expect(status, `${fieldNames} was not present in ${responseType}`).toBe(true);
3323
}
3424

3525
async verifyResponseHeader(expectedResponseHeaderParams: string, responsePart: Array<{ name: string, value: string }>, responseType: string): Promise<void> {
@@ -42,12 +32,7 @@ export class APIActions {
4232
break;
4333
}
4434
}
45-
try {
46-
expect(status).toBe(true);
47-
}
48-
catch (exception) {
49-
throw new Error(`${fieldNames} was not present in ${responseType}`);
50-
}
35+
expect(status, `${fieldNames} was not present in ${responseType}`).toBe(true);
5136
}
5237

5338
async readValuesFromTextFile(fileName: string): Promise<string> {

Diff for: lib/WebActions.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,10 @@ export class WebActions {
149149
}
150150

151151
async expectToBeTrue(status: boolean, errorMessage: string): Promise<void> {
152-
try {
153-
expect(status).toBe(true);
154-
}
155-
catch (exception) {
156-
throw new Error(`${errorMessage}`);
157-
}
152+
expect(status, `${errorMessage}`).toBe(true);
158153
}
159154

160155
async expectToBeValue(expectedValue: string, actualValue: string, errorMessage: string): Promise<void> {
161-
try {
162-
expect(expectedValue.trim()).toBe(actualValue);
163-
}
164-
catch (exception) {
165-
throw new Error(`${errorMessage}`);
166-
}
156+
expect(expectedValue.trim(), `${errorMessage}`).toBe(actualValue);
167157
}
168158
}

0 commit comments

Comments
 (0)