2021-04-20 06:25:57 +08:00
|
|
|
import { Page } from "playwright"
|
|
|
|
import { CODE_SERVER_ADDRESS } from "../../utils/constants"
|
|
|
|
// This is a Page Object Model
|
|
|
|
// We use these to simplify e2e test authoring
|
|
|
|
// See Playwright docs: https://playwright.dev/docs/pom/
|
|
|
|
export class CodeServer {
|
|
|
|
page: Page
|
2021-04-28 02:30:22 +08:00
|
|
|
editorSelector = "div.monaco-workbench"
|
2021-04-20 06:25:57 +08:00
|
|
|
|
|
|
|
constructor(page: Page) {
|
|
|
|
this.page = page
|
|
|
|
}
|
2021-04-21 03:41:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to CODE_SERVER_ADDRESS
|
|
|
|
*/
|
2021-04-20 06:25:57 +08:00
|
|
|
async navigate() {
|
|
|
|
await this.page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
2021-04-22 05:31:15 +08:00
|
|
|
}
|
2021-04-21 03:41:54 +08:00
|
|
|
|
2021-04-22 05:31:15 +08:00
|
|
|
/**
|
|
|
|
* Checks if the editor is visible
|
|
|
|
* and reloads until it is
|
|
|
|
*/
|
|
|
|
async reloadUntilEditorIsVisible() {
|
2021-04-22 04:22:11 +08:00
|
|
|
const editorIsVisible = await this.isEditorVisible()
|
2021-04-21 03:41:54 +08:00
|
|
|
let reloadCount = 0
|
|
|
|
|
|
|
|
// Occassionally code-server timeouts in Firefox
|
|
|
|
// we're not sure why
|
|
|
|
// but usually a reload or two fixes it
|
|
|
|
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
|
|
|
|
while (!editorIsVisible) {
|
2021-04-28 02:30:22 +08:00
|
|
|
// When a reload happens, we want to wait for all resources to be
|
|
|
|
// loaded completely. Hence why we use that instead of DOMContentLoaded
|
|
|
|
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
|
|
|
|
await this.page.waitForLoadState("load")
|
|
|
|
// Give it an extra second just in case it's feeling extra slow
|
|
|
|
await this.page.waitForTimeout(1000)
|
2021-04-21 03:41:54 +08:00
|
|
|
reloadCount += 1
|
2021-04-22 04:22:11 +08:00
|
|
|
if (await this.isEditorVisible()) {
|
|
|
|
console.log(` Editor became visible after ${reloadCount} reloads`)
|
2021-04-21 03:41:54 +08:00
|
|
|
break
|
|
|
|
}
|
2021-04-28 02:30:22 +08:00
|
|
|
await this.page.reload()
|
2021-04-21 03:41:54 +08:00
|
|
|
}
|
2021-04-20 06:25:57 +08:00
|
|
|
}
|
2021-04-21 03:41:54 +08:00
|
|
|
|
2021-04-20 06:25:57 +08:00
|
|
|
/**
|
2021-04-21 03:41:54 +08:00
|
|
|
* Checks if the editor is visible
|
2021-04-20 06:25:57 +08:00
|
|
|
*/
|
2021-04-21 03:41:54 +08:00
|
|
|
async isEditorVisible() {
|
|
|
|
// Make sure the editor actually loaded
|
2021-04-24 05:28:39 +08:00
|
|
|
// If it's not visible after 5 seconds, something is wrong
|
2021-04-21 03:41:54 +08:00
|
|
|
await this.page.waitForLoadState("networkidle")
|
2021-04-28 02:30:22 +08:00
|
|
|
return await this.page.isVisible(this.editorSelector)
|
2021-04-20 06:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-21 03:41:54 +08:00
|
|
|
* Focuses Integrated Terminal
|
2021-04-28 02:30:22 +08:00
|
|
|
* by using "Terminal: Focus Terminal"
|
|
|
|
* from the Command Palette
|
|
|
|
*
|
|
|
|
* This should focus the terminal no matter
|
|
|
|
* if it already has focus and/or is or isn't
|
|
|
|
* visible already.
|
2021-04-20 06:25:57 +08:00
|
|
|
*/
|
2021-04-21 03:41:54 +08:00
|
|
|
async focusTerminal() {
|
|
|
|
// Click [aria-label="Application Menu"] div[role="none"]
|
|
|
|
await this.page.click('[aria-label="Application Menu"] div[role="none"]')
|
2021-04-20 06:25:57 +08:00
|
|
|
|
2021-04-21 03:41:54 +08:00
|
|
|
// Click text=View
|
|
|
|
await this.page.hover("text=View")
|
|
|
|
await this.page.click("text=View")
|
2021-04-20 06:25:57 +08:00
|
|
|
|
2021-04-28 02:30:22 +08:00
|
|
|
// Click text=Command Palette
|
|
|
|
await this.page.hover("text=Command Palette")
|
|
|
|
await this.page.click("text=Command Palette")
|
|
|
|
|
|
|
|
// Type Terminal: Focus Terminal
|
|
|
|
await this.page.keyboard.type("Terminal: Focus Terminal")
|
|
|
|
|
|
|
|
// Click Terminal: Focus Terminal
|
|
|
|
await this.page.hover("text=Terminal: Focus Terminal")
|
|
|
|
await this.page.click("text=Terminal: Focus Terminal")
|
2021-04-22 05:31:15 +08:00
|
|
|
|
2021-04-28 02:30:22 +08:00
|
|
|
// Wait for terminal textarea to show up
|
|
|
|
await this.page.waitForSelector("textarea.xterm-helper-textarea")
|
2021-04-22 05:31:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to CODE_SERVER_ADDRESS
|
|
|
|
* and reloads until the editor is visible
|
|
|
|
*
|
|
|
|
* Helpful for running before tests
|
|
|
|
*/
|
|
|
|
async setup() {
|
|
|
|
await this.navigate()
|
|
|
|
await this.reloadUntilEditorIsVisible()
|
2021-04-20 06:25:57 +08:00
|
|
|
}
|
|
|
|
}
|