test: make a few tests headed/headless agnostic (#33268)

This commit is contained in:
Dmitry Gozman 2024-10-24 06:03:36 -07:00 committed by GitHub
parent 3641e5984f
commit 67471cb3c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 10 deletions

View file

@ -511,13 +511,13 @@ test('should support toHaveURL with baseURL from webServer', async ({ runInlineT
import { test, expect } from '@playwright/test';
test('pass', async ({ page }) => {
await page.goto('/foobar');
await expect(page).toHaveURL('/foobar');
await expect(page).toHaveURL('http://localhost:${port}/foobar');
await page.goto('/hello');
await expect(page).toHaveURL('/hello');
await expect(page).toHaveURL('http://localhost:${port}/hello');
});
test('fail', async ({ page }) => {
await page.goto('/foobar');
await page.goto('/hello');
await expect(page).toHaveURL('/kek', { timeout: 1000 });
});
`,

View file

@ -735,28 +735,34 @@ test('should not throw when attachment is missing', async ({ runInlineTest }, te
});
test('should not throw when screenshot on failure fails', async ({ runInlineTest, server }, testInfo) => {
server.setRoute('/download', (req, res) => {
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=file.txt');
res.end(`Hello world`);
});
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: { trace: 'on', screenshot: 'on' } };
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('has pdf page', async ({ page }) => {
test('has download page', async ({ page }) => {
await page.goto("${server.EMPTY_PAGE}");
await page.setContent('<a href="/empty.pdf" target="blank">open me!</a>');
await page.setContent('<a href="/download" target="blank">open me!</a>');
const downloadPromise = page.waitForEvent('download');
await page.click('a');
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe('empty.pdf');
expect(download.suggestedFilename()).toBe('file.txt');
});
`,
}, { workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const trace = await parseTrace(testInfo.outputPath('test-results', 'a-has-pdf-page', 'trace.zip'));
const trace = await parseTrace(testInfo.outputPath('test-results', 'a-has-download-page', 'trace.zip'));
const attachedScreenshots = trace.actionTree.filter(s => s.trim() === `attach "screenshot"`);
// One screenshot for the page, no screenshot for pdf page since it should have failed.
// One screenshot for the page, no screenshot for the download page since it should have failed.
expect(attachedScreenshots.length).toBe(1);
});

View file

@ -276,7 +276,7 @@ test('should restart webserver on reload', async ({ runUITest }) => {
'a.test.js': `
import { test, expect } from '@playwright/test';
test('should work', async ({ page }) => {
await page.goto('http://localhost:${port}');
await page.goto('http://localhost:${port}/hello');
});
`
}, { DEBUG: 'pw:webserver' });