Skip to content

Commit

Permalink
added notes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaybharti committed Feb 20, 2024
1 parent 87acd8a commit 4d2d8df
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ To pick a locator, run the `codegen` command followed by URL, `npx playwright co

## Sample Test

### Unit/Integration Testing

### Sample Web Test

> Note: Refer to [sample-web-test](https://github.com/abhaybharti/playwright-framework-template/tree/master/src/tests/web/example)
Expand Down Expand Up @@ -185,6 +187,8 @@ This will start running script in debug mode & open PlayWright inspector

#### Run & Generate Report

## GitHub Actions - created workflow to run test

## Contributing

We love our contributors! Here's how you can contribute:
Expand Down
45 changes: 45 additions & 0 deletions src/helper/web/webHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,49 @@ export class WebHelper extends Helper {
});
});
}

async changeElementValue(): Promise<void> {}

async verifyValueFromUi(): Promise<void> {}

async getAttribute(locator: string, attributeName: string): Promise<string> {
const value = await this.webPage
.locator(locator)
.getAttribute(attributeName);
return value ?? "";
}

async getText(locator: string): Promise<string> {
const value = await this.webPage.locator(locator).textContent();
return value ?? "";
}

async press(key: string): Promise<void> {
await this.webPage.keyboard.press(key);
}

async addStep(stepDescription: string, stepFunction: any): Promise<any> {
return await test.step(stepDescription, stepFunction);
}

async attachScreenshot(
locator: string,
fileName: string,
testInfo: TestInfo
): Promise<void> {
const file = testInfo.outputPath(fileName);
const pathFile = path.dirname(file);
const pathAttachments = path.join(pathFile, "attachments");
const attachmentFile = path.join(pathAttachments, fileName);
const screenshot = await webPage
.locator(locator)
.isVisible()
.screenshot({ path: file });
await fs.promise.writeFile(file, screenshot);
if (!fs.existsSync(pathAttachments)) {
fs.mkdirSync(pathAttachments, { recursive: true });
}
await fs.promises.writeFile(attachmentFile, screenshot);
await testInfo.attach(fileName, { contentType: "image/png", path: file });
}
}
36 changes: 36 additions & 0 deletions src/tests/web/example/autoWait.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test, expect, Request, Response } from "@playwright/test";

//Different wait available in Playwright
// 1. waitForTimeout -- Thread.sleep()

// 2. waitForRequest
test("test waitForRequest demo", async ({ page }) => {
const request: Request = await page.waitForRequest(/ohrm_logo.png/);
console.log(request.url());
});
// 3. waitForResponse
test("test waitForResponse demo", async ({ page }) => {
const response: Response = await page.waitForResponse(/ohrm_logo.png/);
console.log(response.request().url());
});

// 4. waitForUrl
// 5. waitForLoadState
// 6. waitForSelector

test("test waitForSelector demo", async ({ page }) => {
//use below approach than using waitForSelector
await expect(page.getByAltText("OrangeHRM")).toBeVisible({ timeout: 3_000 });
});
// 7. waitForFunction
test("test waitForFunction demo", async ({ page }) => {
await page.waitForFunction(() => {
window.scrollBy(0, 600);
});
});

// 8. waitForEvent

test("test waitForEvent demo", async ({ page }) => {
await page.waitForEvent("domcontentloaded");
});
166 changes: 166 additions & 0 deletions src/utils/config/uiMap/sit/orangeHRM.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"App": {
"Login": {
"objType": "page",
"OrangeHRMLogo": {
"objType": "img",
"locatorType": "xpath",
"locatorValue": "//img[@alt='company-branding']"
},
"LoginInfo": {},
"UsernameText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[normalize-space()='Username']",
"label": "Username"
},
"Username": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//input[@placeholder='Username']",
"label": "",
"validTestData": "a,abcde",
"invalidTestData": ",abcdef,%%%%,$$$$",
"saveTestData": "admin,test",
"fieldErrorMessage": "Required,invalid error"
},
"PasswordText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[normalize-space()='Password']",
"label": "Password"
},
"Password": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//input[@placeholder='Password']",
"label": "",
"validTestData": "",
"invalidTestData": "",
"saveTestData": "",
"fieldErrorMessage": ""
},
"Login": {
"elementType": "button",
"locatorType": "xpath",
"locatorValue": "//button[normalize-space()='Login']",
"labelName": "Login"
},
"Forgotyourpassword": {
"elementType": "link",
"locatorType": "xpath",
"locatorValue": "//p[normalize-space()='Forgot your password?']",
"labelName": "Forgot your password?"
}
},
"Admin": {
"objType": "sidebar",
"locatorType": "xpath",
"locatorValue": "//a[@class='oxd-main-menu-item active']//span[1]",
"label": "Admin",
"UserManagement": {
"objType": "tab",
"locatorType": "xpath",
"locatorValue": "//span[normalize-space()='User Management']",
"label": "User Management",
"Users": {
"objType": "subtab",
"locatorType": "xpath",
"locatorValue": "//a[text()='Users']",
"SystemUsers": {
"objType": "section",
"locatorType": "xpath",
"locatorValue": "//*[text()='System Users']",
"UsernameText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[text()='Username']",
"label": "Username",
"Username": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//input[@class='oxd-input oxd-input--active']",
"label": "",
"validTestData": "",
"invalidTestData": "",
"saveTestData": "",
"fieldErrorMessage": "",
"UserRoleText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[text()='User Role']",
"label": "User Role",
"UserRole": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//div[@class='oxd-select-text-input']",
"label": "",
"validTestData": "",
"invalidTestData": "",
"saveTestData": "",
"fieldErrorMessage": "",
"EmployeeNameText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[text()='Employee Name']",
"label": "Employee Name",
"EmployeeName": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//input[@placeholder='Type for hints...']",
"label": "",
"validTestData": "",
"invalidTestData": "",
"saveTestData": "",
"fieldErrorMessage": "",
"StatusText": {
"objType": "text",
"locatorType": "xpath",
"locatorValue": "//label[text()='Status']",
"label": "User Role",
"Status": {
"objType": "input",
"locatorType": "xpath",
"locatorValue": "//div[@class='oxd-select-text-input']",
"label": "",
"validTestData": "",
"invalidTestData": "",
"saveTestData": "",
"fieldErrorMessage": "",
"Reset": {
"elementType": "button",
"locatorType": "xpath",
"locatorValue": "//button[text()=' Reset ']",
"labelName": "Reset",
"Search": {
"elementType": "button",
"locatorType": "xpath",
"locatorValue": "//button[text()=' Search ']",
"labelName": "Search",
"Add": {
"elementType": "button",
"locatorType": "xpath",
"locatorValue": "//button[text()=' Add ']",
"labelName": "Add",
"RecordsTable": {
"objType": "table/grid",
"locatorType": "xpath",
"locatorValue": "//div[@role='table']"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

0 comments on commit 4d2d8df

Please sign in to comment.