Skip to content

Commit 9edfdab

Browse files
committed
Multi wIndow Handling
1 parent a50673b commit 9edfdab

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

lib/WebActions.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import * as CryptoJS from 'crypto-js';
33
import type { Page } from 'playwright';
4-
import { expect } from '@playwright/test';
4+
import { BrowserContext, expect } from '@playwright/test';
55
import { Workbook } from 'exceljs';
66
import { testConfig } from '../testConfig';
77
import path from 'path';
@@ -126,6 +126,17 @@ export class WebActions {
126126
expect(textValue.trim()).toBe(text);
127127
}
128128

129+
130+
async verifyNewWindowUrl(context: BrowserContext, locator: string, urlText: string): Promise<void> {
131+
const [newWindow] = await Promise.all([
132+
context.waitForEvent("page"),
133+
await this.page.click(locator)
134+
])
135+
await newWindow.waitForLoadState("load");
136+
expect(newWindow.url()).toContain(urlText);
137+
await newWindow.close();
138+
}
139+
129140
async verifyElementContainsText(locator: string, text: string): Promise<void> {
130141
await this.waitForElementAttached(locator);
131142
await expect(this.page.locator(locator)).toContainText(text);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "npx playwright test",
8-
"test:single": "npx playwright test POST.test.ts --project=API",
8+
"test:single": "npx playwright test FollowUsMultipleWindow.test.ts --project=Chrome",
99
"test:parallel": "npx playwright test --grep @Smoke --project=Chrome",
1010
"test:serial": "npx playwright test --grep @Smoke --workers=1 --project=Chrome",
1111
"test:api": "npx playwright test --grep @API --workers=1 --project=Chrome",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export class MyAccountPageObjects {
22
MY_ACCOUNT_HDR_XPATH = `//h1[contains(text(),'My account')]`;
33
MY_ACCOUNT_LINKS_XPATH = `//span[contains(text(),'linkName')]`;
4+
MY_ACCOUNT_FOLLOW_FB_LINK_XPATH="//span[text()='Facebook']/..";
45
}

pageFactory/pageRepository/MyAccountPage.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MyAccountPageObjects } from "@objects/MyAccountPageObjects";
22
import { WebActions } from "@lib/WebActions";
3-
import type { Page } from 'playwright';
3+
import type { BrowserContext, Page } from 'playwright';
44

55
let webActions: WebActions;
66

@@ -21,4 +21,10 @@ export class MyAccountPage {
2121
async clickOnMyAccountLinks(linkName: string): Promise<void> {
2222
await webActions.clickElement(this.myAccountPageObjects.MY_ACCOUNT_LINKS_XPATH.replace(`linkName`, linkName));
2323
}
24+
25+
async verifyFollowUsFBWindow(context: BrowserContext, urlText: string): Promise<void> {
26+
await webActions.verifyNewWindowUrl(context, this.myAccountPageObjects.MY_ACCOUNT_FOLLOW_FB_LINK_XPATH, urlText);
27+
28+
}
29+
2430
}

playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const config: PlaywrightTestConfig = {
3939
baseURL: testConfig[process.env.ENV],
4040

4141
//Browser Mode
42-
headless: false,
42+
headless: true,
4343

4444
//Browser height and width
4545
viewport: { width: 1500, height: 730 },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import test from '@lib/BaseTest';
2+
3+
test(`@Smoke Verify Follow Us Facebook new window.`, async ({ context, loginPage, myAccountPage }) => {
4+
await loginPage.navigateToURL();
5+
await loginPage.loginToApplication();
6+
await myAccountPage.verifyMyAccountHeader();
7+
await myAccountPage.verifyFollowUsFBWindow(context, "facebook");
8+
});

0 commit comments

Comments
 (0)