New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add Support for Image Existence Verification in Expect Statements #28234
Comments
What is |
Yes, I use locator for But I have a draft of my code here: test('Test image', async ({ page }) => {
await page.goto('http://127.0.0.1:5500/test_web/index.html');
const imgs = await page.locator("img").all();
imgs.forEach(img => {
expect(img).toBeVisible();
});
}); |
You can wait for the image to load first with await page.locator('img').evaluate(async (img: HTMLImageElement) => {
if (img.complete)
return;
await new Promise((resolve, reject) => {
img.onload = resolve;
img.onerror = reject;
});
}); Will that solve your problem? |
See also #6046 |
It's not because the image is large or takes a long time to load, but rather that the browser can't find the image due to an incorrect URL or the image has been deleted from the server, in short, |
You can use toHaveScreenshot on the image element to check that expected image was actually loaded. Also, if the load fails, |
Closing per the response above, feel free to open a new issue if it doesn't work. |
Feature Request
I would like to propose the addition of a new capability in Playwright that allows users to use "expect" statements to verify the existence of an image on a webpage.
Use Case
As a user, I often need to verify the presence of specific images on a webpage as part of my testing scenarios. Currently, Playwright provides robust support for text-based assertions, but lacks a dedicated mechanism for image existence verification.
Example
Additional Information
This feature would enhance the versatility of Playwright, enabling users to conduct more comprehensive testing, especially when dealing with dynamic content or complex user interfaces.
Benefits
The text was updated successfully, but these errors were encountered: