tlc-core-automation-framework-v3-wdio-v9
Version:
Background: - We are following multi-layer automation framework architecture using webdriver.io + cucumber + typescript This core framework has been implemented with generic utility functions and cucumber steps, which can be easily consumed by another fra
59 lines (53 loc) • 1.81 kB
text/typescript
import request from "supertest";
export class ApiHelpers {
public static async getApiRequest(
host: string,
resource: string,
contentType: string = "application/json",
acceptHeader: string = "application/json",
): Promise<request.Response> {
let response = await request(host)
.get(resource)
.set("Content-Type", contentType)
.set("Accept", acceptHeader)
return response;
}
public static async postApiRequest(
host: string, resource: string,
payLoad: object = {},
contentType: string = "application/json",
acceptHeader: string = "application/json"
): Promise<request.Response> {
let response = await request(host)
.post(resource)
.set("Content-Type", contentType)
.set("Accept", acceptHeader)
.send(payLoad)
return response;
}
public static async deleteApiRequest(
host: string,
resource: string,
contentType: string = "application/json",
acceptHeader: string = "application/json",
): Promise<request.Response> {
let response = await request(host)
.delete(resource)
.set("Content-Type", contentType)
.set("Accept", acceptHeader)
return response;
}
public static async putApiRequest(
host: string, resource: string,
payLoad: object = {},
contentType: string = "application/json",
acceptHeader: string = "application/json"
): Promise<request.Response> {
let response = await request(host)
.put(resource)
.set("Content-Type", contentType)
.set("Accept", acceptHeader)
.send(payLoad)
return response;
}
}