2020-09-18 21:54:00 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-09-26 20:59:27 +03:00
|
|
|
import { it, expect } from './fixtures';
|
2021-01-14 04:02:53 +03:00
|
|
|
import type * as trace from '../src/trace/traceTypes';
|
2020-09-18 21:54:00 +03:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
2021-01-28 11:38:36 +03:00
|
|
|
it('should record trace', (test, { browserName, platform }) => {
|
|
|
|
test.fixme();
|
|
|
|
}, async ({browser, testInfo, server}) => {
|
2021-01-21 06:16:23 +03:00
|
|
|
const traceDir = testInfo.outputPath('trace');
|
|
|
|
const context = await browser.newContext({ _traceDir: traceDir } as any);
|
2020-09-18 21:54:00 +03:00
|
|
|
const page = await context.newPage();
|
|
|
|
const url = server.PREFIX + '/snapshot/snapshot-with-css.html';
|
|
|
|
await page.goto(url);
|
2021-01-26 05:44:46 +03:00
|
|
|
await page.click('textarea');
|
2020-09-18 21:54:00 +03:00
|
|
|
await context.close();
|
2021-01-21 06:16:23 +03:00
|
|
|
const tracePath = path.join(traceDir, fs.readdirSync(traceDir).find(n => n.endsWith('.trace')));
|
2020-10-01 21:06:19 +03:00
|
|
|
const traceFileContent = await fs.promises.readFile(tracePath, 'utf8');
|
2020-09-18 21:54:00 +03:00
|
|
|
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();
|
2021-01-28 21:50:57 +03:00
|
|
|
expect(contextEvent.debugName).toBeUndefined();
|
2020-09-18 21:54:00 +03:00
|
|
|
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);
|
|
|
|
|
2021-01-26 22:06:05 +03:00
|
|
|
const resourceEvent = traceEvents.find(event => event.type === 'resource' && event.url.endsWith('/frames/style.css')) as trace.NetworkResourceTraceEvent;
|
|
|
|
expect(resourceEvent).toBeTruthy();
|
|
|
|
expect(resourceEvent.contextId).toBe(contextId);
|
|
|
|
expect(resourceEvent.pageId).toBe(pageId);
|
|
|
|
expect(resourceEvent.method).toBe('GET');
|
|
|
|
expect(resourceEvent.status).toBe(200);
|
|
|
|
expect(resourceEvent.requestHeaders).toBeTruthy();
|
|
|
|
expect(resourceEvent.requestHeaders.length).toBeGreaterThan(0);
|
|
|
|
expect(resourceEvent.requestSha1).toBe('none');
|
|
|
|
|
2021-01-26 05:44:46 +03:00
|
|
|
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;
|
2021-01-28 06:42:51 +03:00
|
|
|
expect(snapshotEvent).toBeTruthy();
|
2020-09-18 21:54:00 +03:00
|
|
|
});
|
2021-01-26 22:06:05 +03:00
|
|
|
|
2021-01-28 09:31:46 +03:00
|
|
|
it('should record trace with POST', (test, { browserName, platform }) => {
|
|
|
|
test.fixme();
|
|
|
|
}, async ({browser, testInfo, server}) => {
|
2021-01-26 22:06:05 +03:00
|
|
|
const traceDir = testInfo.outputPath('trace');
|
|
|
|
const context = await browser.newContext({ _traceDir: traceDir } as any);
|
|
|
|
const page = await context.newPage();
|
|
|
|
const url = server.PREFIX + '/trace-resources.html';
|
|
|
|
await page.goto(url);
|
|
|
|
await page.click('text=Download');
|
|
|
|
await page.waitForSelector(`#response-status:text("404")`);
|
|
|
|
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();
|
2021-01-28 21:50:57 +03:00
|
|
|
expect(contextEvent.debugName).toBeUndefined();
|
2021-01-26 22:06:05 +03:00
|
|
|
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 resourceEvent = traceEvents.find(event => event.type === 'resource' && event.url.endsWith('/file.json')) as trace.NetworkResourceTraceEvent;
|
|
|
|
expect(resourceEvent).toBeTruthy();
|
|
|
|
expect(resourceEvent.contextId).toBe(contextId);
|
|
|
|
expect(resourceEvent.pageId).toBe(pageId);
|
|
|
|
expect(resourceEvent.method).toBe('POST');
|
|
|
|
expect(resourceEvent.status).toBe(404);
|
|
|
|
expect(resourceEvent.requestHeaders).toBeTruthy();
|
|
|
|
expect(resourceEvent.requestHeaders.length).toBeGreaterThan(0);
|
|
|
|
expect(resourceEvent.requestSha1).toBeTruthy();
|
|
|
|
expect(resourceEvent.responseSha1).toBeTruthy();
|
|
|
|
|
|
|
|
expect(fs.existsSync(path.join(traceDir, 'resources', resourceEvent.requestSha1))).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(traceDir, 'resources', resourceEvent.responseSha1))).toBe(true);
|
|
|
|
});
|
2021-01-28 21:50:57 +03:00
|
|
|
|
|
|
|
it('should record trace with a debugName', (test, { browserName, platform }) => {
|
|
|
|
test.fixme();
|
|
|
|
}, async ({browser, testInfo, server}) => {
|
|
|
|
const traceDir = testInfo.outputPath('trace');
|
|
|
|
const debugName = 'Custom testcase name';
|
|
|
|
const context = await browser.newContext({ _traceDir: traceDir, _debugName: debugName } as any);
|
|
|
|
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();
|
|
|
|
expect(contextEvent.debugName).toBe(debugName);
|
|
|
|
});
|