test: make a few tests headed/headless agnostic (#33268)
This commit is contained in:
parent
3641e5984f
commit
67471cb3c5
|
|
@ -511,13 +511,13 @@ test('should support toHaveURL with baseURL from webServer', async ({ runInlineT
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
test('pass', async ({ page }) => {
|
test('pass', async ({ page }) => {
|
||||||
await page.goto('/foobar');
|
await page.goto('/hello');
|
||||||
await expect(page).toHaveURL('/foobar');
|
await expect(page).toHaveURL('/hello');
|
||||||
await expect(page).toHaveURL('http://localhost:${port}/foobar');
|
await expect(page).toHaveURL('http://localhost:${port}/hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fail', async ({ page }) => {
|
test('fail', async ({ page }) => {
|
||||||
await page.goto('/foobar');
|
await page.goto('/hello');
|
||||||
await expect(page).toHaveURL('/kek', { timeout: 1000 });
|
await expect(page).toHaveURL('/kek', { timeout: 1000 });
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
|
|
|
||||||
|
|
@ -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) => {
|
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({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = { use: { trace: 'on', screenshot: 'on' } };
|
module.exports = { use: { trace: 'on', screenshot: 'on' } };
|
||||||
`,
|
`,
|
||||||
'a.spec.ts': `
|
'a.spec.ts': `
|
||||||
import { test, expect } from '@playwright/test';
|
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.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');
|
const downloadPromise = page.waitForEvent('download');
|
||||||
await page.click('a');
|
await page.click('a');
|
||||||
const download = await downloadPromise;
|
const download = await downloadPromise;
|
||||||
expect(download.suggestedFilename()).toBe('empty.pdf');
|
expect(download.suggestedFilename()).toBe('file.txt');
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
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"`);
|
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);
|
expect(attachedScreenshots.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ test('should restart webserver on reload', async ({ runUITest }) => {
|
||||||
'a.test.js': `
|
'a.test.js': `
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
test('should work', async ({ page }) => {
|
test('should work', async ({ page }) => {
|
||||||
await page.goto('http://localhost:${port}');
|
await page.goto('http://localhost:${port}/hello');
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { DEBUG: 'pw:webserver' });
|
}, { DEBUG: 'pw:webserver' });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue