fix(android): respect recordHar option (#28046)

Fixes #28015.
This commit is contained in:
Dmitry Gozman 2023-11-09 08:36:05 -08:00 committed by GitHub
parent 7f10fe935a
commit 62b6af3a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -274,8 +274,10 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
async launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<BrowserContext> { async launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<BrowserContext> {
const contextOptions = await prepareBrowserContextParams(options); const contextOptions = await prepareBrowserContextParams(options);
const { context } = await this._channel.launchBrowser(contextOptions); const result = await this._channel.launchBrowser(contextOptions);
return BrowserContext.from(context) as BrowserContext; const context = BrowserContext.from(result.context) as BrowserContext;
context._setOptions(contextOptions, {});
return context;
} }
async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> { async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import fs from 'fs';
import { androidTest as test, expect } from './androidTest'; import { androidTest as test, expect } from './androidTest';
test.afterAll(async ({ androidDevice }) => { test.afterAll(async ({ androidDevice }) => {
@ -155,3 +156,19 @@ test('should be able to pass context options', async ({ androidDevice, httpsServ
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches)).toBe(false); expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches)).toBe(false);
await context.close(); 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');
});