diff --git a/test/smoke/src/areas/search/search.ts b/test/smoke/src/areas/search/search.ts index 9052aaca12660cec5ecdea14af5063e69f22b541..2a7bc3eed736858f7b0994dbcb469c3433dacfa8 100644 --- a/test/smoke/src/areas/search/search.ts +++ b/test/smoke/src/areas/search/search.ts @@ -23,23 +23,20 @@ export class Search extends Viewlet { } async searchFor(text: string): Promise { - await this.code.waitAndClick(INPUT); - await this.code.waitForActiveElement(INPUT); + await this.waitForInputFocus(INPUT); await this.code.waitForSetValue(INPUT, text); await this.submitSearch(); } async submitSearch(): Promise { - await this.code.waitAndClick(INPUT); - await this.code.waitForActiveElement(INPUT); + await this.waitForInputFocus(INPUT); await this.code.dispatchKeybinding('enter'); await this.code.waitForElement(`${VIEWLET} .messages[aria-hidden="false"]`); } async setFilesToIncludeText(text: string): Promise { - await this.code.waitAndClick(INCLUDE_INPUT); - await this.code.waitForActiveElement(INCLUDE_INPUT); + await this.waitForInputFocus(INCLUDE_INPUT); await this.code.waitForSetValue(INCLUDE_INPUT, text || ''); } @@ -76,4 +73,22 @@ export class Search extends Viewlet { async waitForResultText(text: string): Promise { await this.code.waitForTextContent(`${VIEWLET} .messages[aria-hidden="false"] .message>p`, text); } + + private async waitForInputFocus(selector: string): Promise { + let retries = 0; + + // other parts of code might steal focus away from input boxes :( + while (retries < 5) { + await this.code.waitAndClick(INPUT); + + try { + await this.code.waitForActiveElement(INPUT, 10); + break; + } catch (err) { + if (++retries > 5) { + throw err; + } + } + } + } }