Skip to content

Commit e118e38

Browse files
committed
refactor: CodeServer methods to be mroe stable
1 parent 5816434 commit e118e38

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

test/e2e/models/CodeServer.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CODE_SERVER_ADDRESS } from "../../utils/constants"
55
// See Playwright docs: https://playwright.dev/docs/pom/
66
export class CodeServer {
77
page: Page
8+
editorSelector = "div.monaco-workbench"
89

910
constructor(page: Page) {
1011
this.page = page
@@ -30,15 +31,18 @@ export class CodeServer {
3031
// but usually a reload or two fixes it
3132
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
3233
while (!editorIsVisible) {
34+
// When a reload happens, we want to wait for all resources to be
35+
// loaded completely. Hence why we use that instead of DOMContentLoaded
36+
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
37+
await this.page.waitForLoadState("load")
38+
// Give it an extra second just in case it's feeling extra slow
39+
await this.page.waitForTimeout(1000)
3340
reloadCount += 1
3441
if (await this.isEditorVisible()) {
3542
console.log(` Editor became visible after ${reloadCount} reloads`)
3643
break
3744
}
38-
// When a reload happens, we want to wait for all resources to be
39-
// loaded completely. Hence why we use that instead of DOMContentLoaded
40-
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
41-
await this.page.reload({ waitUntil: "load" })
45+
await this.page.reload()
4246
}
4347
}
4448

@@ -49,7 +53,7 @@ export class CodeServer {
4953
// Make sure the editor actually loaded
5054
// If it's not visible after 5 seconds, something is wrong
5155
await this.page.waitForLoadState("networkidle")
52-
return await this.page.isVisible("div.monaco-workbench", { timeout: 5000 })
56+
return await this.page.isVisible(this.editorSelector)
5357
}
5458

5559
/**
@@ -63,7 +67,9 @@ export class CodeServer {
6367
const isTerminalVisible = await this.page.isVisible("#terminal")
6468
if (isTerminalVisible) {
6569
await this.page.keyboard.press(`Control+Backquote`)
66-
// TODO fix this
70+
71+
// Make sure everything is laoded
72+
await this.page.waitForLoadState("load")
6773
// Wait for terminal to receive focus
6874
await this.page.waitForSelector("div.terminal.xterm.focus")
6975
// Sometimes the terminal reloads

0 commit comments

Comments
 (0)