Comments (8)
@asinanovic Call test.info().attach()
to attach the trace file, and it should get into the report.
from playwright.
Tracing should work with webview2, can you share a repro where it fails?
from playwright.
I don't get any error message, it's just that snapshots and screencast are missing. I can only see a list of actions.
Below is my webView2Test.ts implementation:
import { test as base } from '@playwright/test';
import fs from 'fs';
import os from 'os';
import path from 'path';
import childProcess from 'child_process';
const EXECUTABLE_PATH = path.join(
__dirname,
'../../../../pathToMyWebView2.exe',
);
export const test = base.extend({
context: async ({ playwright }, use, testInfo) => {
const cdpPort = 10000 + testInfo.workerIndex;
// Make sure that the executable exists and is executable
fs.accessSync(EXECUTABLE_PATH, fs.constants.X_OK);
const userDataDir = path.join(
fs.realpathSync.native(os.tmpdir()),
`playwright-webview2-tests/user-data-dir-${testInfo.workerIndex}`,
);
const webView2Process = childProcess.spawn(EXECUTABLE_PATH, [], {
shell: true,
env: {
...process.env,
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS: `--remote-debugging-port=${cdpPort}`,
WEBVIEW2_USER_DATA_FOLDER: userDataDir,
}
});
await new Promise<void>(resolve => webView2Process.stdout.on('data', data => {
if (data.toString().includes('WebView2 initialized'))
resolve();
}));
const browser = await playwright.chromium.connectOverCDP(`http://127.0.0.1:${cdpPort}`);
await use(browser.contexts()[0]);
await browser.close();
childProcess.execSync(`taskkill /pid ${webView2Process.pid} /T /F`);
fs.rmdirSync(userDataDir, { recursive: true });
},
page: async ({ context }, use) => {
const page = context.pages()[0];
await use(page);
},
});
export { expect } from '@playwright/test';
... and below is playwright configuration:
import { defineConfig, devices } from '@playwright/test';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Timeout for each test in milliseconds */
timeout: 2 * 60 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
// trace: 'on-first-retry'
trace: 'on'
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
}
],
});
from playwright.
You can try manually record trace by calling start and stop and see if the traces contain the snapshots. We were not able to reproduce it with provided code. Could you share full repro including the app at pathToMyWebView2, so that we could run it locally?
from playwright.
I already tried to record manually, but I only called tracing.start
. 🙃 Now, after calling both, tracing.start
and tracing.stop
, it works just fine.
const browser = await playwright.chromium.connectOverCDP(`http://127.0.0.1:${cdpPort}`);
await browser.contexts()[0].tracing.start({ screenshots: true, snapshots: true })
await use(browser.contexts()[0]);
await browser.contexts()[0].tracing.stop({ path: 'trace.zip' });
await browser.close();
Though, I'm still wondering why it doesn't work when I set trace: 'on'
in the playwright.config file - any idea?
In addition, now I notice that for the snapshots, css is not loaded. If I inspect snapshots, I can see bunch of 'Failed to load resource (404)' errors while screencast shows images with css, as expected.
from playwright.
Though, I'm still wondering why it doesn't work when I set trace: 'on' in the playwright.config file - any idea?
This is expected as of today, since there is no integration between WebView2/connectOverCDP and the tracing/test-runner options like trace/video/screenshot. Calling tracing.stop is required as of today. This gives you also more control in order to when you want to start a new trace and when not, since based on the scenario you want to re-start the app or not, perform special cleanup logic etc.
In addition, now I notice that for the snapshots, css is not loaded. If I inspect snapshots, I can see bunch of 'Failed to load resource (404)' errors while screencast shows images with css, as expected.
We need a repro in order to look into this.
from playwright.
This is expected as of today, since there is no integration between WebView2/connectOverCDP and the tracing/test-runner options like trace/video/screenshot. Calling tracing.stop is required as of today. This gives you also more control in order to when you want to start a new trace and when not, since based on the scenario you want to re-start the app or not, perform special cleanup logic etc.
It would be valuable to mention this somewhere in trace documentation.
Final question - since for WebView2/connectOverCDP apps I have to start/stop the trace manually, is there a way for the trace to be part of the Playwright report? Currently, the trace is saved to the path we specify, but it would be valuable for it to be part of the generated report, so I have everything in one place when calling npx playwright show-report
.
from playwright.
Thanks!
from playwright.
Related Issues (20)
- [Bug]: DEBUG=pw:webserver no longer works (regression) HOT 2
- [Bug]: Locators do not auto-wait when resolved to multiple elements (Strict mode) HOT 4
- [Bug]: UI mode highlights all tests that import fixtures in red, despite running tests correctly; claims they shouldn't be imported HOT 1
- [Feature]: Support Ubuntu 24.04 HOT 1
- [Bug]: Viewing tests with -UI HOT 2
- Can't get more workers to run - Playwright HOT 3
- [Bug]: Since v1.43, "Error: Error: browserType.launch: Executable doesn't exist" HOT 2
- Can't get parallel running for multiple tests in same file - Playwright HOT 2
- [Bug]: Adding an assertion in a fixture does not trigger retries HOT 1
- [Bug]: No tests passing for a simple component (component testing) HOT 1
- [Feature]: Allow page to listen for custom events `page.on(CUSTOM_EVENT, () =>` HOT 5
- [Bug]: Unable to run playwright tests using github actions HOT 8
- [Bug]: Timing issues with dynamically generated tests. (Updated, originally thought this was a globbing issue) HOT 8
- [Question] Why is 'setDownloadBehavior' required for connect_over_cdp? Any workaround? HOT 3
- [Bug]: playwright tests do not show in test tab in vscode, no errors, cli works HOT 5
- [Bug]: invoke beforeall method with condition skip in loop will skip entire test instead of respective each loop tests HOT 5
- [Bug]: Arch Linux & your OS is not officially supported by Playwright HOT 1
- [Bug]: @tags added using new syntax as per v1.42 is not shown in UI mode HOT 2
- [Feature]: Set proxy in Page HOT 1
- [Bug]: Missing projects/tests when using multiple projects (folders) from 1.43.x HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.