-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
1 changed file
with
6 additions
and
8 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 |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import { expect, test } from "@playwright/test"; | ||
const limit = 10; | ||
|
||
const pagesWithSimpleImages = [ | ||
{ url: "/demos/image_basic.html", description: "Basic page" }, | ||
{ url: "/demos/async.html", description: "Async initialization" } | ||
{ url: "/demos/async.html", description: "Async initialization" }, | ||
{ url: "/demos/async_multiple.html", description: "Async initialization - multiple instances" }, | ||
]; | ||
|
||
for (const { url, description } of pagesWithSimpleImages) { | ||
test(description, async ({ page }) => { | ||
await page.goto(url); | ||
const lazyLoadImages = await page.locator("img[data-src]"); | ||
const lazyImages = await page.locator(".lazy"); | ||
await page.waitForLoadState("load"); | ||
const imageCount = limit //was: await lazyLoadImages.count(); | ||
const imageCount = await lazyImages.count(); | ||
|
||
// Eventually scroll into view and check if it loads | ||
for (let i = 0; i < imageCount; i++) { | ||
const image = lazyLoadImages.nth(i); | ||
const image = lazyImages.nth(i); | ||
await image.scrollIntoViewIfNeeded(); | ||
|
||
// Check the src attribute | ||
const expectedSrc = await image.getAttribute("data-src"); | ||
await expect(image).toHaveAttribute("src", expectedSrc); | ||
} | ||
}); | ||
|
||
// You can also do it with test.describe() or with multiple tests as long the test name is unique. | ||
} | ||
} |