mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: side effects of context.storageState() (#6793)
This commit is contained in:
parent
58e74b477a
commit
7f0d817afd
@ -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);
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user