Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(android): respect recordHar option (#28046)
Dmitry Gozman62b6af3a7f67
diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.tsindex 6c7a9e44ae..651bcbe3e9 100644--- a/packages/playwright-core/src/client/android.ts+++ b/packages/playwright-core/src/client/android.ts@@ -274,8 +274,10 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> iasync launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<BrowserContext> {const contextOptions = await prepareBrowserContextParams(options);- const { context } = await this._channel.launchBrowser(contextOptions);- return BrowserContext.from(context) as BrowserContext;+ const result = await this._channel.launchBrowser(contextOptions);+ const context = BrowserContext.from(result.context) as BrowserContext;+ context._setOptions(contextOptions, {});+ return context;}async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {diff --git a/tests/android/browser.spec.ts b/tests/android/browser.spec.tsindex 2590ef791b..d1b54206b9 100644--- a/tests/android/browser.spec.ts+++ b/tests/android/browser.spec.ts@@ -14,6 +14,7 @@* limitations under the License.*/+import fs from 'fs';import { androidTest as test, expect } from './androidTest';test.afterAll(async ({ androidDevice }) => {@@ -155,3 +156,19 @@ test('should be able to pass context options', async ({ androidDevice, httpsServexpect(await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches)).toBe(false);await context.close();});++test('should record har', async ({ androidDevice }) => {+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28015' });+ const harPath = test.info().outputPath('test.har');++ const context = await androidDevice.launchBrowser({+ recordHar: { path: harPath }+ });+ const [page] = context.pages();+ await page.goto('data:text/html,<title>Hello</title>');+ await page.waitForLoadState('domcontentloaded');+ await context.close();++ const log = JSON.parse(fs.readFileSync(harPath).toString())['log'];+ expect(log.pages[0].title).toBe('Hello');+});