Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: side effects of context.storageState() (#6793)
Yury Semikhatsky7f0d817afd00
diff --git a/tests/har.spec.ts b/tests/har.spec.tsindex 2ebc28b69a..78caaa7fff 100644--- a/tests/har.spec.ts+++ b/tests/har.spec.ts@@ -25,6 +25,7 @@ async function pageWithHar(contextFactory: (options?: BrowserContextOptions) =>const page = await context.newPage();return {page,+ context,getLog: async () => {await context.close();return JSON.parse(fs.readFileSync(harPath).toString())['log'];@@ -281,3 +282,22 @@ it('should have popup requests', async ({ contextFactory, server }, testInfo) =>expect(entries[1].request.url).toBe(server.PREFIX + '/one-style.css');expect(entries[1].response.status).toBe(200);});++it('should not contain internal pages', async ({ browserName, contextFactory, server }, testInfo) => {+ it.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');+ server.setRoute('/empty.html', (req, res) => {+ res.setHeader('Set-Cookie', 'name=value');+ res.end();+ });++ const { page, context, getLog } = await pageWithHar(contextFactory, testInfo);+ await page.goto(server.EMPTY_PAGE);++ const cookies = await context.cookies();+ expect(cookies.length).toBe(1);+ // Get storage state, this create internal page.+ await context.storageState();++ const log = await getLog();+ expect(log.pages.length).toBe(1);+});diff --git a/tests/tracing.spec.ts b/tests/tracing.spec.tsindex e49edf888f..47a2862e50 100644--- a/tests/tracing.spec.ts+++ b/tests/tracing.spec.ts@@ -63,6 +63,26 @@ test('should collect trace', async ({ context, page, server }, testInfo) => {expect(events.some(e => e.type === 'resource-snapshot')).toBeFalsy();});+test('should exclude internal pages', async ({ browserName, context, page, server }, testInfo) => {+ test.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');+ await page.goto(server.EMPTY_PAGE);++ await context.tracing.start({ name: 'test' });+ await context.storageState();+ await page.close();+ await context.tracing.stop();+ await context.tracing.export(testInfo.outputPath('trace.zip'));++ const trace = await parseTrace(testInfo.outputPath('trace.zip'));+ const pageIds = new Set();+ trace.events.forEach(e => {+ const pageId = e.metadata?.pageId;+ if (pageId)+ pageIds.add(pageId);+ });+ expect(pageIds.size).toBe(1);+});+test('should collect two traces', async ({ context, page, server }, testInfo) => {await context.tracing.start({ name: 'test1', screenshots: true, snapshots: true });await page.goto(server.EMPTY_PAGE);diff --git a/tests/video.spec.ts b/tests/video.spec.tsindex 26df9be1a3..22a967b5b5 100644--- a/tests/video.spec.ts+++ b/tests/video.spec.ts@@ -643,4 +643,32 @@ it.describe('screencast', () => {expect(videoPlayer.videoHeight).toBe(240);});+ it('should not create video for internal pages', async ({browser, browserName, contextOptions, server}, testInfo) => {+ it.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');+ server.setRoute('/empty.html', (req, res) => {+ res.setHeader('Set-Cookie', 'name=value');+ res.end();+ });++ const videoDir = testInfo.outputPath('');+ const context = await browser.newContext({+ ...contextOptions,+ recordVideo: {+ dir: videoDir+ }+ });++ const page = await context.newPage();+ await page.goto(server.EMPTY_PAGE);+ await new Promise(r => setTimeout(r, 1000));++ const cookies = await context.cookies();+ expect(cookies.length).toBe(1);+ await context.storageState();+ await context.close();++ const files = fs.readdirSync(videoDir);+ expect(files.length).toBe(1);+ });+});