Skip to content

Commit 2f2b5a8

Browse files
Added Scrolling.spec.js script
1 parent fdd4643 commit 2f2b5a8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test('Verify scrolling functionality to find specific text', async ({ page }) => {
4+
// Define constants for the test
5+
const targetUrl = 'https://qa-practice.netlify.app/scroll';
6+
const startingText = 'Starting...';
7+
const endingText = 'THE END';
8+
const scrollOffset = 500; // Scroll step in pixels
9+
const scrollDelay = 200; // Delay between scrolls in milliseconds
10+
11+
// Navigate to the target page
12+
await page.goto(targetUrl);
13+
14+
// Verify the visibility of the starting text
15+
const startingTextLocator = page.locator(`text=${startingText}`);
16+
await expect(startingTextLocator).toBeVisible();
17+
await expect(startingTextLocator).toHaveText(startingText);
18+
19+
// Scroll down incrementally until the ending text is visible
20+
const endingTextLocator = page.locator(`text=${endingText}`);
21+
while (!(await endingTextLocator.isVisible())) {
22+
// Scroll by the defined offset
23+
await page.evaluate((offset) => window.scrollBy(0, offset), scrollOffset);
24+
25+
// Delay between scrolls for smoother scrolling
26+
await page.waitForTimeout(scrollDelay);
27+
}
28+
29+
// Verify the visibility and content of the ending text
30+
await expect(endingTextLocator).toBeVisible();
31+
await expect(endingTextLocator).toHaveText(endingText);
32+
33+
// Close the page
34+
await page.close();
35+
});

0 commit comments

Comments
 (0)