Skip to content

Commit

Permalink
added generic helper
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaybharti committed Feb 14, 2024
1 parent da26fb2 commit 87acd8a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/utils/generalPurpose.ts → src/helper/Helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class GeneralPurpose {
export class Helper {
async isValidDate(date: string) {
if (Date.parse(date)) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/helper/api/apiHelper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { request, expect, APIResponse } from "@playwright/test";
import { log } from "console";
import exp from "constants";
import { Helper } from "helper/Helper";
import { StringLiteral } from "typescript";

const BASE_URL = "https://restful-booker.herokuapp.com";
export class ApiHelper {
export class ApiHelper extends Helper {
private apiContext: any;

/**
Expand All @@ -14,6 +15,7 @@ export class ApiHelper {
* credentials, request headers, and other configuration settings.
*/
constructor(apiContext: any) {
super();
this.apiContext = apiContext;
// this.apiContext = apiContext({
// extraHTTPHeaders: {
Expand Down
6 changes: 3 additions & 3 deletions src/helper/web/webHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BrowserContext, Page, expect } from "@playwright/test";
import fs from "fs";
import { Helper } from "helper/Helper";

export class WebHelper {
export class WebHelper extends Helper {
readonly webPage: Page;
readonly browserContext: BrowserContext;

constructor(webPage: Page, browserContext: BrowserContext) {
super();
this.webPage = webPage;
this.browserContext = browserContext;
}
Expand Down Expand Up @@ -406,6 +408,4 @@ export class WebHelper {
});
});
}


}
9 changes: 5 additions & 4 deletions src/tests/api/example/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, test, APIRequestContext } from "@playwright/test";

import { ApiHelper } from "../../../helper/api/apiHelper";
import { GeneralPurpose } from "../../../utils/generalPurpose";

let token: string;
let bookingId: string;
Expand Down Expand Up @@ -61,7 +60,7 @@ test("Get Booking Details using BookingID --> 1914", async ({ request }) => {
description:
"This will make GET call to https://restful-booker.herokuapp.com/booking/:id and verify keys/values in response",
});
const gs = await new GeneralPurpose();

const apiHelper = await new ApiHelper(request); //
const bookingDetails = await apiHelper.invokeGetApi("/booking/1914");
console.log(JSON.stringify(bookingDetails));
Expand All @@ -70,8 +69,10 @@ test("Get Booking Details using BookingID --> 1914", async ({ request }) => {
expect(bookingDetails.lastname).toBe("Allen");
expect(bookingDetails.totalprice).toBe(111);
expect(bookingDetails.depositpaid).toBeTruthy();
expect(gs.isValidDate(bookingDetails.bookingdates.checkin)).toBe(true);
expect(gs.isValidDate(bookingDetails.bookingdates.checkout)).toBe(true);
expect(apiHelper.isValidDate(bookingDetails.bookingdates.checkin)).toBe(true);
expect(apiHelper.isValidDate(bookingDetails.bookingdates.checkout)).toBe(
true
);
expect(bookingDetails.additionalneeds).toBe("super bowls");
});

Expand Down
31 changes: 31 additions & 0 deletions src/utils/reader/jsonReader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { promisify } from "util";
import fs from "fs";

export class JsonReader {
private fileName: string;
private jsonData: any = "";
private readFile: any;

constructor(fileName: string) {
this.fileName = fileName;
this.readFile = promisify(fs.readFile);
this.jsonData = this.readJson();
}

async readJson() {
return await JSON.parse(this.readFile(this.fileName, "utf-8"));
}

//function to read a given path and return the data
async getParamData(jsonPath: string) {}

//function to return all element matching keyType & keyVal
async getTabName() {}
//

async getParamLabels(jsonHierarchy: string) {}

async getAllParamsInHierarchy(jsonHierarchy: string) {}

async getEndPointNames() {}
}

0 comments on commit 87acd8a

Please sign in to comment.