diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index d84d912d204c..114a52b5f7f1 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -292,10 +292,24 @@ export class CodeServerPage { async focusTerminal() { // We need to create a new terminal since multiple tests could be running at // once and they will step over each other if they use the same terminal. - await this.executeCommandViaMenus("Terminal: Create New Terminal") + const doFocus = async (): Promise => { + await this.executeCommandViaMenus("Terminal: Create New Terminal") + try { + await this.page.waitForLoadState("load") + await this.page.waitForSelector("textarea.xterm-helper-textarea:focus-within", { timeout: 5000 }) + return true + } catch (error) { + return false + } + } + + let attempts = 1 + while(!(await doFocus())) { + ++attempts + this.codeServer.logger.debug(`no terminal textarea, retrying (${attempts}/∞)`) + } - // Wait for terminal textarea to show up - await this.page.waitForSelector("textarea.xterm-helper-textarea") + this.codeServer.logger.debug(`opening terminal took ${attempts} ${plural(attempts, "attempt")}`) } /** @@ -423,7 +437,7 @@ export class CodeServerPage { let context = new Context() while (!(await Promise.race([openThenWaitClose(context), navigate(context)]))) { ++attempts - logger.debug("closed, retrying (${attempt}/∞)") + logger.debug(`closed, retrying (${attempts}/∞)`) context.cancel() context = new Context() } diff --git a/test/e2e/terminal.test.ts b/test/e2e/terminal.test.ts index 4bd3aa2762f3..175d51c29321 100644 --- a/test/e2e/terminal.test.ts +++ b/test/e2e/terminal.test.ts @@ -22,7 +22,6 @@ describe("Integrated Terminal", true, [], {}, () => { // Open terminal and type in value await codeServerPage.focusTerminal() - await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`printenv VSCODE_PROXY_URI > ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") @@ -34,13 +33,13 @@ describe("Integrated Terminal", true, [], {}, () => { const tmpFolderPath = await tmpdir(testName) const tmpFile = path.join(tmpFolderPath, "test-file") await fs.writeFile(tmpFile, "test") + const fileName = path.basename(tmpFile) await codeServerPage.focusTerminal() - await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`code-server ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") - await codeServerPage.waitForTab(path.basename(tmpFile)) + await codeServerPage.waitForTab(fileName) }) })