From 268e02cff6c33d7a344795d004b943d2d99ab7be Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Tue, 20 Apr 2021 01:29:07 +0800 Subject: [PATCH] feat: test second window open --- features/openClose.feature | 2 +- features/stepDefinitions/electron.ts | 8 ++++---- features/supports/world.ts | 11 ++++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/features/openClose.feature b/features/openClose.feature index f13994cf..bfbd0b5e 100644 --- a/features/openClose.feature +++ b/features/openClose.feature @@ -12,4 +12,4 @@ Feature: Open Given the app is launched Then the element "#add-workspace-button" is on the page Then click on this element - Then "AddWorkspace" window show up \ No newline at end of file + Then "Add Workspace" window show up \ No newline at end of file diff --git a/features/stepDefinitions/electron.ts b/features/stepDefinitions/electron.ts index 64cb3295..cd725beb 100644 --- a/features/stepDefinitions/electron.ts +++ b/features/stepDefinitions/electron.ts @@ -31,9 +31,9 @@ Then('{string} window show up', { timeout: 120 * 1000 }, async function (this: T const handles = await this.app?.client?.getWindowHandles(); expect(handles).to.not.be.undefined; if (handles !== undefined) { - // DEBUG: console - console.log(`handles`, handles); - await this.app?.client?.switchToWindow(handles[0]); - await delay(1000); + await this.app?.client?.switchToWindow(handles[1]); + await this.waitReactReady(); + const currentTitle = await this.app?.client?.getTitle(); + expect(currentTitle).to.be.equal(windowName); } }); diff --git a/features/supports/world.ts b/features/supports/world.ts index ca633cf7..d69cc420 100644 --- a/features/supports/world.ts +++ b/features/supports/world.ts @@ -41,9 +41,7 @@ export class TiddlyGitWorld extends World { port: 9156, }); await this.app.start(); - while (undefined === (await this.getElement('#test'))) { - await delay(500); - } + await this.waitReactReady(); } public async getElement(selector: string): Promise { @@ -60,6 +58,13 @@ export class TiddlyGitWorld extends World { } } + /** + * We add `
` to each page in react render, so we can wait until it exists + */ + public async waitReactReady(): Promise { + await this?.app?.client?.waitUntil(async () => undefined !== (await this.getElement('#test'))); + } + public updateContext(context: Partial): void { this.context = this.context === undefined ? context : { ...this.context, ...context }; }