feat: test second window open

This commit is contained in:
tiddlygit-test 2021-04-20 01:29:07 +08:00
parent 604942379f
commit 268e02cff6
3 changed files with 13 additions and 8 deletions

View file

@ -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
Then "Add Workspace" window show up

View file

@ -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);
}
});

View file

@ -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<WebdriverIO.Element | undefined> {
@ -60,6 +58,13 @@ export class TiddlyGitWorld extends World {
}
}
/**
* We add `<div id="test" />` to each page in react render, so we can wait until it exists
*/
public async waitReactReady(): Promise<void> {
await this?.app?.client?.waitUntil(async () => undefined !== (await this.getElement('#test')));
}
public updateContext(context: Partial<IContext>): void {
this.context = this.context === undefined ? context : { ...this.context, ...context };
}