Skip to content

Commit

Permalink
added api scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaybharti committed Feb 14, 2024
1 parent f169ad9 commit da26fb2
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 53 deletions.
104 changes: 55 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@types/mocha": "^10.0.6",
"@types/webdriverio": "^5.0.0",
"ajv": "^8.12.0",
"appium": "^2.4.1",
"dotenv": "^16.3.1",
"mocha": "^10.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/helper/api/apiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class ApiHelper {
try {
console.log(`Making GET request to endPoint: ${BASE_URL}${endPoint}`);
response = await this.apiContext.get(`${BASE_URL}${endPoint}`);

expect(
response.status(),
`API : ${BASE_URL}${endPoint} , Expected status : ${statusCode}, Actual status : ${response.status()}`
Expand Down
2 changes: 2 additions & 0 deletions src/helper/web/webHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,6 @@ export class WebHelper {
});
});
}


}
81 changes: 77 additions & 4 deletions src/tests/api/example/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, test } from "@playwright/test";
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 All @@ -8,6 +10,7 @@ test.beforeAll(async ({ request }) => {
//1. Hit /Auth Api and provide username/password as body
//2. fetch token value from JSON response
//3. save in token variable

const apiHelper = await new ApiHelper(request);
const responseMsg = await apiHelper.invokePostApi("/auth", {
username: "admin",
Expand All @@ -20,15 +23,85 @@ test.beforeAll(async ({ request }) => {
console.log(token);
});

test("Get List of booking and verify response", async ({ request }) => {
test("Get booking list and verify response -- No Authentication Required ", async ({
request,
}) => {
/* Test Flow
1. Hit API endpoint
2. Verify API status code
3. Verify JSON Schema
3. Verify JSON Response
4. Verify JSON Schema
*/
test.info().annotations.push({
type: "purpose",
description:
"This will make GET call to https://restful-booker.herokuapp.com/booking with no authentication",
});
const apiHelper = await new ApiHelper(request); //
const responseMsg = await apiHelper.invokeGetApi("/booking");
console.log(responseMsg);
console.log(JSON.stringify(responseMsg));
for (let index = 0; index < responseMsg.length; index++) {
test.info().annotations.push({
type: "value",
description: `BookingId : ${responseMsg[index].bookingid}`,
});
expect(responseMsg[index].bookingid).not.toBeNull();
}
});

test("Get Booking Details using BookingID --> 1914", async ({ request }) => {
/* Test Flow
1. Hit API endpoint
2. Verify API status code
3. Verify JSON Response
4. Verify JSON Schema
*/
test.info().annotations.push({
type: "purpose",
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));

expect(bookingDetails.firstname).toBe("John");
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(bookingDetails.additionalneeds).toBe("super bowls");
});

test("Get booking list, pass to booking/:id API and verify response -- No Authentication Required ", async ({
request,
}) => {
/* Test Flow
1. Hit API endpoint
2. Verify API status code
3. Verify JSON Response
4. Verify JSON Schema
*/
test.info().annotations.push({
type: "purpose",
description:
"This will make GET call to https://restful-booker.herokuapp.com/booking with no authentication",
});
const apiHelper = await new ApiHelper(request); //
const responseMsg = await apiHelper.invokeGetApi("/booking");
console.log(JSON.stringify(responseMsg));
for (let index = 0; index < responseMsg.length; index++) {
test.info().annotations.push({
type: "value",
description: `BookingId : ${responseMsg[index].bookingid}`,
});
expect(responseMsg[index].bookingid).not.toBeNull();
let bookingDetail = await apiHelper.invokeGetApi(
`/booking/${responseMsg[index].bookingid}`
);
console.log(JSON.stringify(bookingDetail));
}
});
//API used for writing test code - https://restful-booker.herokuapp.com/apidoc/index.html
48 changes: 48 additions & 0 deletions src/tests/web/orangeHrm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//test 1 -> Login successful - Verify welcome message on Dashboard
//test 2 - Message Invalid credentials
//test 3 -> Error message password can not be empty
//test 4 -> Error message username can not be empty
//test 5 -> Verify Access to HR Administration Panel
//Navigate to HR Administration panel (login as HR admin)
//test 6 -> Verify Employee addition (login as HR admin)
// Navigate to Employee Management section
// Add a new Employee with required details
// Save the employee record
//test 7 -> Verify Employee deletion (login as HR admin)
// Navigate to Employee Management section
//select an existing employee and initiate the deletion process
// confirm the deletion action
//test 8 -> Verify Leave Application Submission (login as Employee)
// Navigate to the leave section
// Apply for leave by providing required details
// submit the leave application
//test 9 -> Verify Leave Approval(login as HR admin)
// Navigate to leave Approval section
// Review pending leave application
// Approve or reject the leave
//test 10 -> Verify Time Tracking Record Creation
//Navigate to Time Tracking module
// Click on Add Time Record button
// Fill the details & Save the record
//test 11 -> Verify Time Tracking Record Deletion
//Navigate to Time Tracking module
// find an existing time tracking record
// Click on delete button
//confirm the deletion
//test 12 -> Validate attendance marking for an employee
//Navigate to attendance module
//Select an employee from the employee list
//Mark attendance for that employee for the current date
//test 13 -> Verify Job posting Creation (login as HR admin)
//Navigate to Recruitment section
//Create a new job posting
//test 14 -> Verify Application Submission(login as job applicant)
//Navigate to career section
//Apply for specific job posting by submitting the application

//test 15 -> Verify New Employee Onboarding(login as HR admin)
//Navigate to Onboarding section
//Initiate the onboarding process for a newly added employee
//test 16 -> Verify Training Program Creation (login as HR admin)
//Navigate to training section
//create a new training program with all details
9 changes: 9 additions & 0 deletions src/utils/generalPurpose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class GeneralPurpose {
async isValidDate(date: string) {
if (Date.parse(date)) {
return true;
} else {
return false;
}
}
}

0 comments on commit da26fb2

Please sign in to comment.