In headless mode, Playwright doesn't support navigation to PDF documents. However, you can still verify the URL of a PDF document opened in a new tab using alternative methods.
Switch to non-headless mode by passing the headless: false
flag when launching the browser. This allows you to see the browser UI and interact with it manually.
import { test, expect } from '@playwright/test';
test('Verify PDF URL in non-headless mode', async ({ browser }) => {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://ray.run/');
// Perform actions to open the PDF in a new tab
// ...
});
Use debugging tools like slowMo
to slow down execution and make it easier to follow what's happening on screen. Record scripts command line tools can be used to record user interactions and generate JavaScript code for testing purposes.
import { test, expect } from '@playwright/test';
test('Verify PDF URL with slowMo', async ({ browser }) => {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://ray.run/');
// Perform actions to open the PDF in a new tab
// ...
});
Indirectly verify the PDF URL by checking for specific elements or properties on the page using web assertions or other testing frameworks.
import { test, expect } from '@playwright/test';
test('Indirectly verify PDF URL', async ({ page }) => {
await page.goto('https://ray.run/');
// Perform actions to open the PDF in a new tab
// ...
// Check for specific elements or properties on the page
const pdfLink = await page.$('a[href$=".pdf"]');
expect(pdfLink).toBeTruthy();
});
In conclusion, while verifying PDF URLs in headless mode isn't straightforward, you can use these workarounds depending on your needs and circumstances.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].