From 5d796f32ead421203533b307080edd657459d23e Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 9 Aug 2022 00:31:12 -0700 Subject: [PATCH] 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 * :lipstick: Co-authored-by: Benjamin Pasero --- test/automation/src/application.ts | 1 + test/automation/src/code.ts | 4 ++++ test/automation/src/playwrightDriver.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/test/automation/src/application.ts b/test/automation/src/application.ts index f023881cc2a..9a755a14231 100644 --- a/test/automation/src/application.ts +++ b/test/automation/src/application.ts @@ -117,6 +117,7 @@ export class Application { private async checkWindowReady(code: Code): Promise { // 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 diff --git a/test/automation/src/code.ts b/test/automation/src/code.ts index f8dfe1db136..cc69a27bb88 100644 --- a/test/automation/src/code.ts +++ b/test/automation/src/code.ts @@ -135,6 +135,10 @@ export class Code { await this.driver.dispatchKeybinding(keybinding); } + async didFinishLoad(): Promise { + return this.driver.didFinishLoad(); + } + async exit(): Promise { return measureAndLog(new Promise((resolve, reject) => { const pid = this.mainProcess.pid!; diff --git a/test/automation/src/playwrightDriver.ts b/test/automation/src/playwrightDriver.ts index 61e219db4d5..4eef5d450ab 100644 --- a/test/automation/src/playwrightDriver.ts +++ b/test/automation/src/playwrightDriver.ts @@ -77,6 +77,20 @@ export class PlaywrightDriver { } } + async didFinishLoad(): Promise { + + // Web: via `load` state + if (this.options.web) { + return this.page.waitForLoadState('load'); + } + + // Desktop: via `window` event + return new Promise(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 { try { const persistPath = join(this.options.logsPath, `playwright-screenshot-${PlaywrightDriver.screenShotCounter++}-${name.replace(/\s+/g, '-')}.png`);