mirror of
https://github.com/Microsoft/vscode
synced 2024-10-02 17:32:41 +00:00
smoke - bring back better solution for waiting that target has loaded (#175415)
This commit is contained in:
parent
7d084eeca8
commit
6dfe534cca
|
@ -22,11 +22,11 @@ export async function launch(options: LaunchOptions): Promise<{ serverProcess: C
|
|||
const { serverProcess, endpoint } = await launchServer(options);
|
||||
|
||||
// Launch browser
|
||||
const { browser, context, page } = await launchBrowser(options, endpoint);
|
||||
const { browser, context, page, pageLoadedPromise } = await launchBrowser(options, endpoint);
|
||||
|
||||
return {
|
||||
serverProcess,
|
||||
driver: new PlaywrightDriver(browser, context, page, serverProcess, options)
|
||||
driver: new PlaywrightDriver(browser, context, page, serverProcess, pageLoadedPromise, options)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -133,9 +133,12 @@ async function launchBrowser(options: LaunchOptions, endpoint: string) {
|
|||
`["logLevel","${options.verbose ? 'trace' : 'info'}"]`
|
||||
].join(',')}]`;
|
||||
|
||||
await measureAndLog(() => page.goto(`${endpoint}&${workspacePath.endsWith('.code-workspace') ? 'workspace' : 'folder'}=${URI.file(workspacePath!).path}&payload=${payloadParam}`), 'page.goto()', logger);
|
||||
const gotoPromise = measureAndLog(() => page.goto(`${endpoint}&${workspacePath.endsWith('.code-workspace') ? 'workspace' : 'folder'}=${URI.file(workspacePath!).path}&payload=${payloadParam}`), 'page.goto()', logger);
|
||||
const pageLoadedPromise = page.waitForLoadState('load');
|
||||
|
||||
return { browser, context, page };
|
||||
await gotoPromise;
|
||||
|
||||
return { browser, context, page, pageLoadedPromise };
|
||||
}
|
||||
|
||||
function waitForEndpoint(server: ChildProcess, logger: Logger): Promise<string> {
|
||||
|
|
|
@ -36,6 +36,7 @@ export class PlaywrightDriver {
|
|||
private readonly context: playwright.BrowserContext,
|
||||
private readonly page: playwright.Page,
|
||||
private readonly serverProcess: ChildProcess | undefined,
|
||||
private readonly whenLoaded: Promise<unknown>,
|
||||
private readonly options: LaunchOptions
|
||||
) {
|
||||
}
|
||||
|
@ -78,14 +79,7 @@ export class PlaywrightDriver {
|
|||
}
|
||||
|
||||
async didFinishLoad(): Promise<void> {
|
||||
|
||||
// Web: via `load` state
|
||||
if (this.options.web) {
|
||||
return this.page.waitForLoadState('load');
|
||||
}
|
||||
|
||||
// Desktop: already loaded when `electron.firstWindow()` returns
|
||||
return;
|
||||
await this.whenLoaded;
|
||||
}
|
||||
|
||||
private async takeScreenshot(name: string): Promise<void> {
|
||||
|
|
|
@ -17,12 +17,12 @@ export async function launch(options: LaunchOptions): Promise<{ electronProcess:
|
|||
args.push('--enable-smoke-test-driver');
|
||||
|
||||
// Launch electron via playwright
|
||||
const { electron, context, page } = await launchElectron({ electronPath, args, env }, options);
|
||||
const { electron, context, page, windowLoadedPromise } = await launchElectron({ electronPath, args, env }, options);
|
||||
const electronProcess = electron.process();
|
||||
|
||||
return {
|
||||
electronProcess,
|
||||
driver: new PlaywrightDriver(electron, context, page, undefined /* no server process */, options)
|
||||
driver: new PlaywrightDriver(electron, context, page, undefined /* no server process */, windowLoadedPromise, options)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,8 @@ async function launchElectron(configuration: IElectronConfiguration, options: La
|
|||
env: configuration.env as { [key: string]: string }
|
||||
}), 'playwright-electron#launch', logger);
|
||||
|
||||
const windowLoadedPromise = electron.waitForEvent('window');
|
||||
|
||||
const window = await measureAndLog(() => electron.firstWindow(), 'playwright-electron#firstWindow', logger);
|
||||
|
||||
const context = window.context();
|
||||
|
@ -72,5 +74,5 @@ async function launchElectron(configuration: IElectronConfiguration, options: La
|
|||
}
|
||||
});
|
||||
|
||||
return { electron, context, page: window };
|
||||
return { electron, context, page: window, windowLoadedPromise };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue