Skip to content

Commit 5040612

Browse files
Added New Tab or Window folder and Added New Tab Script
1 parent 80d454c commit 5040612

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test('Verify New Browser Tab', async ({ browser }) => {
4+
// Create a new browser context and a page
5+
const context = await browser.newContext();
6+
const page = await context.newPage();
7+
8+
// Navigate to the "New Browser Tab" page
9+
const targetUrl = 'https://qa-practice.netlify.app/tab';
10+
await page.goto(targetUrl);
11+
12+
// Locate the button to open a new tab
13+
const newTabButtonSelector = '//a[text()="Press me - New Tab"]';
14+
const newTabButton = page.locator(newTabButtonSelector);
15+
16+
// Click the button and wait for the new tab to open
17+
const [newTab] = await Promise.all([
18+
context.waitForEvent('page'),
19+
newTabButton.click(),
20+
]);
21+
22+
// Ensure the new tab is fully loaded
23+
await newTab.waitForLoadState();
24+
25+
// Validate the URL of the new tab
26+
const expectedUrl = 'https://qa-practice.netlify.app/web-table';
27+
expect(newTab.url()).toContain(expectedUrl);
28+
29+
// Validate the title of the new tab
30+
const expectedTitle = 'QA Practice | Learn with RV';
31+
const pageTitle = await newTab.title();
32+
expect(pageTitle).toBe(expectedTitle);
33+
34+
// Validate specific content in the new tab
35+
const headingSelector = 'h2';
36+
const expectedHeadingText = 'Table Example';
37+
const headingText = await newTab.locator(headingSelector).textContent();
38+
expect(headingText).toBe(expectedHeadingText);
39+
40+
// Close the new tab and the main page
41+
await newTab.close();
42+
await page.close();
43+
});

0 commit comments

Comments
 (0)