mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
5033261d27
- Instead of capturing snapshots on demand, we now stream them from each frame every 100ms. - Certain actions can also force snapshots at particular moment using "checkpoints". - Trace viewer is able to show the page snapshot at a particular timestamp, or using a "checkpoint" snapshot. - Small optimization to not process stylesheets if CSSOM was not used. There still is a lot of room for improvement.
57 lines
2.6 KiB
TypeScript
57 lines
2.6 KiB
TypeScript
/**
|
|
* Copyright (c) Microsoft Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import { it, expect } from './fixtures';
|
|
import type * as trace from '../src/trace/traceTypes';
|
|
import * as path from 'path';
|
|
import * as fs from 'fs';
|
|
|
|
it('should record trace', test => test.fixme(), async ({browser, testInfo, server}) => {
|
|
const traceDir = testInfo.outputPath('trace');
|
|
const context = await browser.newContext({ _traceDir: traceDir } as any);
|
|
const page = await context.newPage();
|
|
const url = server.PREFIX + '/snapshot/snapshot-with-css.html';
|
|
await page.goto(url);
|
|
await page.click('textarea');
|
|
await context.close();
|
|
const tracePath = path.join(traceDir, fs.readdirSync(traceDir).find(n => n.endsWith('.trace')));
|
|
const traceFileContent = await fs.promises.readFile(tracePath, 'utf8');
|
|
const traceEvents = traceFileContent.split('\n').filter(line => !!line).map(line => JSON.parse(line)) as trace.TraceEvent[];
|
|
|
|
const contextEvent = traceEvents.find(event => event.type === 'context-created') as trace.ContextCreatedTraceEvent;
|
|
expect(contextEvent).toBeTruthy();
|
|
const contextId = contextEvent.contextId;
|
|
|
|
const pageEvent = traceEvents.find(event => event.type === 'page-created') as trace.PageCreatedTraceEvent;
|
|
expect(pageEvent).toBeTruthy();
|
|
expect(pageEvent.contextId).toBe(contextId);
|
|
const pageId = pageEvent.pageId;
|
|
|
|
const gotoEvent = traceEvents.find(event => event.type === 'action' && event.action === 'goto') as trace.ActionTraceEvent;
|
|
expect(gotoEvent).toBeTruthy();
|
|
expect(gotoEvent.contextId).toBe(contextId);
|
|
expect(gotoEvent.pageId).toBe(pageId);
|
|
expect(gotoEvent.value).toBe(url);
|
|
|
|
const clickEvent = traceEvents.find(event => event.type === 'action' && event.action === 'click') as trace.ActionTraceEvent;
|
|
expect(clickEvent).toBeTruthy();
|
|
expect(clickEvent.snapshots.length).toBe(2);
|
|
const snapshotId = clickEvent.snapshots[0].snapshotId;
|
|
const snapshotEvent = traceEvents.find(event => event.type === 'snapshot' && event.snapshotId === snapshotId) as trace.FrameSnapshotTraceEvent;
|
|
|
|
expect(fs.existsSync(path.join(traceDir, 'resources', snapshotEvent.sha1))).toBe(true);
|
|
});
|