test: expose browserVersion in the tests (#6090)
Drive-by: expose browser version in test report as well.
This commit is contained in:
parent
481034bd0d
commit
ba5ba52e41
|
|
@ -25,11 +25,18 @@ const playwright: typeof import('../../index') = require('../../index');
|
|||
|
||||
export class AndroidEnv implements Env<AndroidTestArgs> {
|
||||
protected _device?: AndroidDevice;
|
||||
protected _browserVersion: string;
|
||||
|
||||
async beforeAll(workerInfo: WorkerInfo) {
|
||||
this._device = (await playwright._android.devices())[0];
|
||||
await this._device.shell('am force-stop org.chromium.webview_shell');
|
||||
await this._device.shell('am force-stop com.android.chrome');
|
||||
this._browserVersion = (await this._device.shell('dumpsys package com.android.chrome'))
|
||||
.toString('utf8')
|
||||
.split('\n')
|
||||
.find(line => line.includes('versionName='))
|
||||
.trim()
|
||||
.split('=')[1];
|
||||
this._device.setDefaultTimeout(90000);
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +82,7 @@ export class AndroidPageEnv extends AndroidEnv implements Env<PageTestArgs> {
|
|||
const page = await this._context!.newPage();
|
||||
return {
|
||||
...result,
|
||||
browserVersion: this._browserVersion,
|
||||
androidDevice: undefined,
|
||||
page,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
|
|||
private _browser: Browser | undefined;
|
||||
private _contextOptions: BrowserContextOptions;
|
||||
private _contexts: BrowserContext[] = [];
|
||||
protected _browserVersion: string;
|
||||
|
||||
constructor(browserName: BrowserName, options: LaunchOptions & BrowserContextOptions & TestOptions) {
|
||||
super(browserName, options);
|
||||
|
|
@ -234,6 +235,7 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
|
|||
async beforeAll(workerInfo: WorkerInfo) {
|
||||
await super.beforeAll(workerInfo);
|
||||
this._browser = await this._browserType.launch(this._browserOptions);
|
||||
this._browserVersion = this._browser.version();
|
||||
}
|
||||
|
||||
async beforeEach(testInfo: TestInfo) {
|
||||
|
|
@ -245,6 +247,8 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
|
|||
...this._contextOptions,
|
||||
} as BrowserContextOptions;
|
||||
|
||||
testInfo.data.browserVersion = this._browserVersion;
|
||||
|
||||
const contextFactory = async (options: BrowserContextOptions = {}) => {
|
||||
const context = await this._browser.newContext({ ...contextOptions, ...options });
|
||||
this._contexts.push(context);
|
||||
|
|
@ -281,6 +285,7 @@ export class PageEnv extends BrowserEnv {
|
|||
const page = await context.newPage();
|
||||
return {
|
||||
...result,
|
||||
browserVersion: this._browserVersion,
|
||||
context,
|
||||
page,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ export type CommonTestArgs = {
|
|||
|
||||
// Page test does not guarantee an isolated context, just a new page (because Android).
|
||||
export type PageTestArgs = CommonTestArgs & {
|
||||
browserVersion: string;
|
||||
page: Page;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue