-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"email": "koushik1@letcode.in", | ||
"pass": "Pass123$" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Page } from "playwright"; | ||
|
||
export default class HeaderPage { | ||
|
||
private page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
|
||
// locators | ||
|
||
public get eleLoginBtn() { | ||
const loginBtn = this.page.$("text=Log in"); | ||
if (loginBtn != null) { | ||
return loginBtn; | ||
} else throw new Error("No Element") | ||
} | ||
|
||
public get eleSignOutBtn() { | ||
const signoutEle = this.page.$("text=Sign out"); | ||
if (signoutEle != null) { | ||
return signoutEle; | ||
} else throw new Error("No Element") | ||
} | ||
|
||
public async clickLoginLink() { | ||
await Promise.all([ | ||
this.page.waitForNavigation({ | ||
waitUntil: "domcontentloaded" | ||
}), | ||
this.page.click("text=Log in") | ||
]) | ||
// const ele = await this.eleLoginBtn; | ||
// await ele?.click(); | ||
} | ||
public async clickSignOutLink() { | ||
const ele = await this.eleSignOutBtn; | ||
await ele?.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Page } from "playwright"; | ||
|
||
export default class LoginPage { | ||
|
||
private page: Page; | ||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
eleEmailTextField = async () => await this.page.$("input[name='email']"); | ||
|
||
// public get eleEmailTextField() { | ||
// return this.page.$("input[name='email']") | ||
// // return elename; | ||
// } | ||
|
||
elePassTextField = async () => await this.page.$("input[name='password']"); | ||
|
||
public get eleLoginBtn() { | ||
return this.page.$("//button[text()='LOGIN']") | ||
// return elename; | ||
} | ||
|
||
public async enterUserName(name: string) { | ||
const ele = await this.eleEmailTextField(); | ||
if (ele != null) | ||
await ele.fill(name); | ||
else throw new Error("No element, hence failed") | ||
} | ||
public async enterUserPassword(pass: string) { | ||
const ele = await this.elePassTextField(); | ||
await ele?.fill(pass); | ||
} | ||
public async clickLoginBtn() { | ||
const ele = await this.eleLoginBtn; | ||
await ele?.click(); | ||
} | ||
|
||
public async login(username: string, pass: string) { | ||
await this.enterUserName(username); | ||
await this.enterUserPassword(pass); | ||
await this.clickLoginBtn(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Page } from "playwright"; | ||
|
||
export default class CommonFunctions { | ||
|
||
private page: Page; | ||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
toaster = async () => await this.page.waitForSelector("div[role='alertdialog']"); | ||
|
||
// public async verifToastMessage() { | ||
|
||
// } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import CommonFunctions from "../page/common.page"; | ||
import HeaderPage from "../page/Header.page"; | ||
import LoginPage from "../page/Login.page"; | ||
import * as data from "../data/login.cred.json"; | ||
import { expect, Page, test } from "@playwright/test"; | ||
|
||
test.describe("TC001", () => { | ||
// my pages | ||
let header: HeaderPage; | ||
let login: LoginPage; | ||
let common: CommonFunctions; | ||
// test.beforeAll(async () => { | ||
// header = new HeaderPage(page); | ||
// login = new LoginPage(page); | ||
// common = new CommonFunctions(page); | ||
// }) | ||
|
||
test("Login positive", async ({ page }) => { | ||
await page.goto("https://letcode.in") | ||
expect(page.url()).toBe("https://letcode.in/") | ||
await header.clickLoginLink(); | ||
expect(page.url()).toBe("https://letcode.in/signin") | ||
await login.enterUserName(data.email); | ||
await login.enterUserPassword(data.pass); | ||
await login.clickLoginBtn(); | ||
const toaster = await common.toaster(); | ||
expect(await toaster?.textContent()).toContain("Welcome"); | ||
await header.clickSignOutLink(); | ||
|
||
}); | ||
test("Login again", async ({ page }) => { | ||
await page.goto("https://letcode.in") | ||
await header.clickLoginLink(); | ||
await login.login("koushik350@gmail.com", data.pass); | ||
await page.waitForNavigation(); | ||
expect(page.url()).toBe("https://letcode.in/") | ||
}) | ||
}) |