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,
|
tracesDir: options.tracesDir,
|
||||||
};
|
};
|
||||||
const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
|
const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
|
||||||
app._context._options = params;
|
app._context._setOptions(params, options);
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
|
||||||
readonly _context: BrowserContext;
|
readonly _context: BrowserContext;
|
||||||
private _windows = new Set<Page>();
|
private _windows = new Set<Page>();
|
||||||
private _timeoutSettings = new TimeoutSettings();
|
private _timeoutSettings = new TimeoutSettings();
|
||||||
private _isClosed = false;
|
|
||||||
|
|
||||||
static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication {
|
static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication {
|
||||||
return (electronApplication as any)._object;
|
return (electronApplication as any)._object;
|
||||||
|
|
@ -79,7 +78,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
|
||||||
this._onPage(page);
|
this._onPage(page);
|
||||||
this._context.on(Events.BrowserContext.Page, page => this._onPage(page));
|
this._context.on(Events.BrowserContext.Page, page => this._onPage(page));
|
||||||
this._channel.on('close', () => {
|
this._channel.on('close', () => {
|
||||||
this._isClosed = true;
|
|
||||||
this.emit(Events.ElectronApplication.Close);
|
this.emit(Events.ElectronApplication.Close);
|
||||||
});
|
});
|
||||||
this._channel.on('console', event => this.emit(Events.ElectronApplication.Console, new ConsoleMessage(event)));
|
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() {
|
async close() {
|
||||||
if (this._isClosed)
|
await this._context.close().catch(() => {});
|
||||||
return;
|
|
||||||
await this._channel.close().catch(() => {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise<any> {
|
async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise<any> {
|
||||||
|
|
|
||||||
|
|
@ -2313,8 +2313,6 @@ scheme.ElectronApplicationUpdateSubscriptionParams = tObject({
|
||||||
enabled: tBoolean,
|
enabled: tBoolean,
|
||||||
});
|
});
|
||||||
scheme.ElectronApplicationUpdateSubscriptionResult = tOptional(tObject({}));
|
scheme.ElectronApplicationUpdateSubscriptionResult = tOptional(tObject({}));
|
||||||
scheme.ElectronApplicationCloseParams = tOptional(tObject({}));
|
|
||||||
scheme.ElectronApplicationCloseResult = tOptional(tObject({}));
|
|
||||||
scheme.AndroidInitializer = tOptional(tObject({}));
|
scheme.AndroidInitializer = tOptional(tObject({}));
|
||||||
scheme.AndroidDevicesParams = tObject({
|
scheme.AndroidDevicesParams = tObject({
|
||||||
host: tOptional(tString),
|
host: tOptional(tString),
|
||||||
|
|
|
||||||
|
|
@ -4124,7 +4124,6 @@ export interface ElectronApplicationChannel extends ElectronApplicationEventTarg
|
||||||
evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionResult>;
|
evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionResult>;
|
||||||
evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionHandleResult>;
|
evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionHandleResult>;
|
||||||
updateSubscription(params: ElectronApplicationUpdateSubscriptionParams, metadata?: CallMetadata): Promise<ElectronApplicationUpdateSubscriptionResult>;
|
updateSubscription(params: ElectronApplicationUpdateSubscriptionParams, metadata?: CallMetadata): Promise<ElectronApplicationUpdateSubscriptionResult>;
|
||||||
close(params?: ElectronApplicationCloseParams, metadata?: CallMetadata): Promise<ElectronApplicationCloseResult>;
|
|
||||||
}
|
}
|
||||||
export type ElectronApplicationCloseEvent = {};
|
export type ElectronApplicationCloseEvent = {};
|
||||||
export type ElectronApplicationConsoleEvent = {
|
export type ElectronApplicationConsoleEvent = {
|
||||||
|
|
@ -4176,9 +4175,6 @@ export type ElectronApplicationUpdateSubscriptionOptions = {
|
||||||
|
|
||||||
};
|
};
|
||||||
export type ElectronApplicationUpdateSubscriptionResult = void;
|
export type ElectronApplicationUpdateSubscriptionResult = void;
|
||||||
export type ElectronApplicationCloseParams = {};
|
|
||||||
export type ElectronApplicationCloseOptions = {};
|
|
||||||
export type ElectronApplicationCloseResult = void;
|
|
||||||
|
|
||||||
export interface ElectronApplicationEvents {
|
export interface ElectronApplicationEvents {
|
||||||
'close': ElectronApplicationCloseEvent;
|
'close': ElectronApplicationCloseEvent;
|
||||||
|
|
|
||||||
|
|
@ -3243,8 +3243,6 @@ ElectronApplication:
|
||||||
- console
|
- console
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
|
|
||||||
close:
|
|
||||||
|
|
||||||
events:
|
events:
|
||||||
close:
|
close:
|
||||||
console:
|
console:
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,18 @@ test('should record video', async ({ launchElectronApp }, testInfo) => {
|
||||||
expect(fs.statSync(videoPath).size).toBeGreaterThan(0);
|
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('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' });
|
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17765' });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue