Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: expose browserVersion in the tests (#6090)

Andrey Lushnikovba5ba52e41e9
diff --git a/tests/config/androidEnv.ts b/tests/config/androidEnv.ts
index 726918eec7..ae82377656 100644
--- a/tests/config/androidEnv.ts
+++ b/tests/config/androidEnv.ts
@@ -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,
};
diff --git a/tests/config/browserEnv.ts b/tests/config/browserEnv.ts
index efe535d8a3..e8ceb0ea62 100644
--- a/tests/config/browserEnv.ts
+++ b/tests/config/browserEnv.ts
@@ -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,
};
diff --git a/tests/config/pageTest.ts b/tests/config/pageTest.ts
index 520cd76512..d4b1a610b4 100644
--- a/tests/config/pageTest.ts
+++ b/tests/config/pageTest.ts
@@ -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;
};