test: expose browserVersion in the tests (#6090)

Drive-by: expose browser version in test report as well.
This commit is contained in:
Andrey Lushnikov 2021-04-06 00:22:07 -05:00 committed by GitHub
parent 481034bd0d
commit ba5ba52e41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -25,11 +25,18 @@ const playwright: typeof import('../../index') = require('../../index');
export class AndroidEnv implements Env<AndroidTestArgs> { export class AndroidEnv implements Env<AndroidTestArgs> {
protected _device?: AndroidDevice; protected _device?: AndroidDevice;
protected _browserVersion: string;
async beforeAll(workerInfo: WorkerInfo) { async beforeAll(workerInfo: WorkerInfo) {
this._device = (await playwright._android.devices())[0]; 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 org.chromium.webview_shell');
await this._device.shell('am force-stop com.android.chrome'); 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); this._device.setDefaultTimeout(90000);
} }
@ -75,6 +82,7 @@ export class AndroidPageEnv extends AndroidEnv implements Env<PageTestArgs> {
const page = await this._context!.newPage(); const page = await this._context!.newPage();
return { return {
...result, ...result,
browserVersion: this._browserVersion,
androidDevice: undefined, androidDevice: undefined,
page, page,
}; };

View file

@ -225,6 +225,7 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
private _browser: Browser | undefined; private _browser: Browser | undefined;
private _contextOptions: BrowserContextOptions; private _contextOptions: BrowserContextOptions;
private _contexts: BrowserContext[] = []; private _contexts: BrowserContext[] = [];
protected _browserVersion: string;
constructor(browserName: BrowserName, options: LaunchOptions & BrowserContextOptions & TestOptions) { constructor(browserName: BrowserName, options: LaunchOptions & BrowserContextOptions & TestOptions) {
super(browserName, options); super(browserName, options);
@ -234,6 +235,7 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
async beforeAll(workerInfo: WorkerInfo) { async beforeAll(workerInfo: WorkerInfo) {
await super.beforeAll(workerInfo); await super.beforeAll(workerInfo);
this._browser = await this._browserType.launch(this._browserOptions); this._browser = await this._browserType.launch(this._browserOptions);
this._browserVersion = this._browser.version();
} }
async beforeEach(testInfo: TestInfo) { async beforeEach(testInfo: TestInfo) {
@ -245,6 +247,8 @@ export class BrowserEnv extends PlaywrightEnv implements Env<BrowserTestArgs> {
...this._contextOptions, ...this._contextOptions,
} as BrowserContextOptions; } as BrowserContextOptions;
testInfo.data.browserVersion = this._browserVersion;
const contextFactory = async (options: BrowserContextOptions = {}) => { const contextFactory = async (options: BrowserContextOptions = {}) => {
const context = await this._browser.newContext({ ...contextOptions, ...options }); const context = await this._browser.newContext({ ...contextOptions, ...options });
this._contexts.push(context); this._contexts.push(context);
@ -281,6 +285,7 @@ export class PageEnv extends BrowserEnv {
const page = await context.newPage(); const page = await context.newPage();
return { return {
...result, ...result,
browserVersion: this._browserVersion,
context, context,
page, page,
}; };

View file

@ -40,6 +40,7 @@ export type CommonTestArgs = {
// Page test does not guarantee an isolated context, just a new page (because Android). // Page test does not guarantee an isolated context, just a new page (because Android).
export type PageTestArgs = CommonTestArgs & { export type PageTestArgs = CommonTestArgs & {
browserVersion: string;
page: Page; page: Page;
}; };