mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(electron): record har file (#30748)
Fixes https://github.com/microsoft/playwright/issues/30747
This commit is contained in:
parent
e728e90944
commit
64b4ac1732
@ -57,7 +57,7 @@ export class Electron extends ChannelOwner<channels.ElectronChannel> implements
|
||||
tracesDir: options.tracesDir,
|
||||
};
|
||||
const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
|
||||
app._context._options = params;
|
||||
app._context._setOptions(params, options);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@ -66,7 +66,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
|
||||
readonly _context: BrowserContext;
|
||||
private _windows = new Set<Page>();
|
||||
private _timeoutSettings = new TimeoutSettings();
|
||||
private _isClosed = false;
|
||||
|
||||
static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication {
|
||||
return (electronApplication as any)._object;
|
||||
@ -79,7 +78,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
|
||||
this._onPage(page);
|
||||
this._context.on(Events.BrowserContext.Page, page => this._onPage(page));
|
||||
this._channel.on('close', () => {
|
||||
this._isClosed = true;
|
||||
this.emit(Events.ElectronApplication.Close);
|
||||
});
|
||||
this._channel.on('console', event => this.emit(Events.ElectronApplication.Console, new ConsoleMessage(event)));
|
||||
@ -118,9 +116,7 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
|
||||
}
|
||||
|
||||
async close() {
|
||||
if (this._isClosed)
|
||||
return;
|
||||
await this._channel.close().catch(() => {});
|
||||
await this._context.close().catch(() => {});
|
||||
}
|
||||
|
||||
async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise<any> {
|
||||
|
||||
@ -2313,8 +2313,6 @@ scheme.ElectronApplicationUpdateSubscriptionParams = tObject({
|
||||
enabled: tBoolean,
|
||||
});
|
||||
scheme.ElectronApplicationUpdateSubscriptionResult = tOptional(tObject({}));
|
||||
scheme.ElectronApplicationCloseParams = tOptional(tObject({}));
|
||||
scheme.ElectronApplicationCloseResult = tOptional(tObject({}));
|
||||
scheme.AndroidInitializer = tOptional(tObject({}));
|
||||
scheme.AndroidDevicesParams = tObject({
|
||||
host: tOptional(tString),
|
||||
|
||||
@ -4124,7 +4124,6 @@ export interface ElectronApplicationChannel extends ElectronApplicationEventTarg
|
||||
evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionResult>;
|
||||
evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionHandleResult>;
|
||||
updateSubscription(params: ElectronApplicationUpdateSubscriptionParams, metadata?: CallMetadata): Promise<ElectronApplicationUpdateSubscriptionResult>;
|
||||
close(params?: ElectronApplicationCloseParams, metadata?: CallMetadata): Promise<ElectronApplicationCloseResult>;
|
||||
}
|
||||
export type ElectronApplicationCloseEvent = {};
|
||||
export type ElectronApplicationConsoleEvent = {
|
||||
@ -4176,9 +4175,6 @@ export type ElectronApplicationUpdateSubscriptionOptions = {
|
||||
|
||||
};
|
||||
export type ElectronApplicationUpdateSubscriptionResult = void;
|
||||
export type ElectronApplicationCloseParams = {};
|
||||
export type ElectronApplicationCloseOptions = {};
|
||||
export type ElectronApplicationCloseResult = void;
|
||||
|
||||
export interface ElectronApplicationEvents {
|
||||
'close': ElectronApplicationCloseEvent;
|
||||
|
||||
@ -3243,8 +3243,6 @@ ElectronApplication:
|
||||
- console
|
||||
enabled: boolean
|
||||
|
||||
close:
|
||||
|
||||
events:
|
||||
close:
|
||||
console:
|
||||
|
||||
@ -261,6 +261,18 @@ test('should record video', async ({ launchElectronApp }, testInfo) => {
|
||||
expect(fs.statSync(videoPath).size).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('should record har', async ({ launchElectronApp, server }, testInfo) => {
|
||||
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30747' });
|
||||
const app = await launchElectronApp('electron-window-app.js', [], {
|
||||
recordHar: { path: testInfo.outputPath('har.zip') }
|
||||
});
|
||||
const page = await app.firstWindow();
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await app.close();
|
||||
expect(fs.existsSync(testInfo.outputPath('har.zip'))).toBeTruthy();
|
||||
expect(fs.statSync(testInfo.outputPath('har.zip')).size).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('should be able to get the first window when with a delayed navigation', async ({ launchElectronApp }) => {
|
||||
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17765' });
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user