smoke(electron): wait for page navigation to commit before using driver (#157106)

* smoke(electron): wait for page navigation to commit before using driver

* chore: only use window event in Electron

* chore: implement load event for web

* 💄

Co-authored-by: Benjamin Pasero <benjamin.pasero@gmail.com>
This commit is contained in:
Robo 2022-08-09 00:31:12 -07:00 committed by GitHub
parent b41684837f
commit 5d796f32ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View file

@ -117,6 +117,7 @@ export class Application {
private async checkWindowReady(code: Code): Promise<void> {
// We need a rendered workbench
await measureAndLog(code.didFinishLoad(), 'Application#checkWindowReady: wait for navigation to be committed', this.logger);
await measureAndLog(code.waitForElement('.monaco-workbench'), 'Application#checkWindowReady: wait for .monaco-workbench element', this.logger);
// Remote but not web: wait for a remote connection state change

View file

@ -135,6 +135,10 @@ export class Code {
await this.driver.dispatchKeybinding(keybinding);
}
async didFinishLoad(): Promise<void> {
return this.driver.didFinishLoad();
}
async exit(): Promise<void> {
return measureAndLog(new Promise<void>((resolve, reject) => {
const pid = this.mainProcess.pid!;

View file

@ -77,6 +77,20 @@ export class PlaywrightDriver {
}
}
async didFinishLoad(): Promise<void> {
// Web: via `load` state
if (this.options.web) {
return this.page.waitForLoadState('load');
}
// Desktop: via `window` event
return new Promise<void>(resolve => {
// https://playwright.dev/docs/api/class-electronapplication#electron-application-event-window
(this.application as playwright.ElectronApplication).on('window', () => resolve());
});
}
private async takeScreenshot(name: string): Promise<void> {
try {
const persistPath = join(this.options.logsPath, `playwright-screenshot-${PlaywrightDriver.screenShotCounter++}-${name.replace(/\s+/g, '-')}.png`);