Skip to content

Commit

Permalink
📦 NEW: POM with test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ortoniKC committed Jun 15, 2021
1 parent 34113ac commit 658988a
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 148 deletions.
4 changes: 4 additions & 0 deletions data/login.cred.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"email": "koushik1@letcode.in",
"pass": "Pass123$"
}
42 changes: 42 additions & 0 deletions page/Header.page.ts
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();
}
}
44 changes: 44 additions & 0 deletions page/Login.page.ts
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();
}
}
15 changes: 15 additions & 0 deletions page/common.page.ts
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() {

// }
}
74 changes: 0 additions & 74 deletions results.json

This file was deleted.

129 changes: 55 additions & 74 deletions test-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
{
"outputDir": "Y:/video/playWright/test-runner/test-results",
"repeatEach": 1,
"retries": 2,
"retries": 0,
"name": "chromium",
"testDir": "Y:/video/playWright/test-runner",
"testIgnore": [],
"testMatch": [
"**/?(*.)+(spec|test).[jt]s"
"tc001.test.ts"
],
"timeout": 30000
}
Expand All @@ -36,92 +36,73 @@
"quiet": false,
"shard": null,
"updateSnapshots": "missing",
"workers": 4
"workers": 2
},
"suites": [
{
"title": "",
"file": "test/first.test.ts",
"file": "test/tc001.test.ts",
"line": 0,
"column": 0,
"specs": [
"specs": [],
"suites": [
{
"title": "open letcode and verify title",
"ok": true,
"tests": [
"title": "TC001",
"file": "test/tc001.test.ts",
"line": 7,
"column": 6,
"specs": [
{
"timeout": 30000,
"annotations": [],
"expectedStatus": "passed",
"projectName": "chromium",
"results": [
"title": "Login positive _ JIRA101",
"ok": true,
"tests": [
{
"workerIndex": 0,
"status": "passed",
"duration": 4075,
"stdout": [],
"stderr": [],
"retry": 0
"timeout": 30000,
"annotations": [],
"expectedStatus": "passed",
"projectName": "chromium",
"results": [
{
"workerIndex": 0,
"status": "passed",
"duration": 9783,
"stdout": [],
"stderr": [],
"retry": 0
}
]
}
]
}
],
"file": "test/first.test.ts",
"line": 2,
"column": 1
},
{
"title": "open letcode and login",
"ok": false,
"tests": [
],
"file": "test/tc001.test.ts",
"line": 23,
"column": 5
},
{
"timeout": 30000,
"annotations": [],
"expectedStatus": "passed",
"projectName": "chromium",
"results": [
"title": "Login again",
"ok": true,
"tests": [
{
"workerIndex": 0,
"status": "failed",
"duration": 6069,
"error": {
"message": "\u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m",
"stack": "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m\n at Y:\\video\\playWright\\test-runner\\test\\first.test.ts:22:24\n at runNextTicks (internal/process/task_queues.js:62:5)\n at processImmediate (internal/timers.js:429:9)\n at WorkerRunner._runTestWithBeforeHooks (Y:\\video\\playWright\\test-runner\\node_modules\\@playwright\\test\\lib\\test\\workerRunner.js:290:13)"
},
"stdout": [],
"stderr": [],
"retry": 0
},
{
"workerIndex": 1,
"status": "failed",
"duration": 7260,
"error": {
"message": "\u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m",
"stack": "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m\n at Y:\\video\\playWright\\test-runner\\test\\first.test.ts:22:24\n at runNextTicks (internal/process/task_queues.js:62:5)\n at processImmediate (internal/timers.js:429:9)\n at WorkerRunner._runTestWithBeforeHooks (Y:\\video\\playWright\\test-runner\\node_modules\\@playwright\\test\\lib\\test\\workerRunner.js:290:13)"
},
"stdout": [],
"stderr": [],
"retry": 1
},
{
"workerIndex": 2,
"status": "failed",
"duration": 7222,
"error": {
"message": "\u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m",
"stack": "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m\"https://letcode.in\"\u001b[39m\nReceived: \u001b[31m\"https://letcode.in\u001b[7m/\u001b[27m\"\u001b[39m\n at Y:\\video\\playWright\\test-runner\\test\\first.test.ts:22:24\n at runNextTicks (internal/process/task_queues.js:62:5)\n at processImmediate (internal/timers.js:429:9)\n at WorkerRunner._runTestWithBeforeHooks (Y:\\video\\playWright\\test-runner\\node_modules\\@playwright\\test\\lib\\test\\workerRunner.js:290:13)"
},
"stdout": [],
"stderr": [],
"retry": 2
"timeout": 30000,
"annotations": [],
"expectedStatus": "passed",
"projectName": "chromium",
"results": [
{
"workerIndex": 0,
"status": "passed",
"duration": 2217,
"stdout": [],
"stderr": [],
"retry": 0
}
]
}
]
],
"file": "test/tc001.test.ts",
"line": 35,
"column": 5
}
],
"file": "test/first.test.ts",
"line": 7,
"column": 1
]
}
]
}
Expand Down
38 changes: 38 additions & 0 deletions test/tc001.test.ts
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/")
})
})

0 comments on commit 658988a

Please sign in to comment.