2021-04-19 22:25:57 +00: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
|
|
|
|
|
|
|
|
constructor(page: Page) {
|
|
|
|
this.page = page
|
|
|
|
}
|
2021-04-20 19:41:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to CODE_SERVER_ADDRESS
|
|
|
|
*/
|
2021-04-19 22:25:57 +00:00
|
|
|
async navigate() {
|
|
|
|
await this.page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
2021-04-21 21:31:15 +00:00
|
|
|
}
|
2021-04-20 19:41:54 +00:00
|
|
|
|
2021-04-21 21:31:15 +00:00
|
|
|
/**
|
|
|
|
* Checks if the editor is visible
|
|
|
|
* and reloads until it is
|
|
|
|
*/
|
|
|
|
async reloadUntilEditorIsVisible() {
|
2021-04-21 20:22:11 +00:00
|
|
|
const editorIsVisible = await this.isEditorVisible()
|
2021-04-20 19:41:54 +00: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) {
|
|
|
|
reloadCount += 1
|
2021-04-21 20:22:11 +00:00
|
|
|
if (await this.isEditorVisible()) {
|
|
|
|
console.log(` Editor became visible after ${reloadCount} reloads`)
|
2021-04-20 19:41:54 +00:00
|
|
|
break
|
|
|
|
}
|
2021-04-21 20:22:11 +00: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.reload({ waitUntil: "load" })
|
2021-04-20 19:41:54 +00:00
|
|
|
}
|
2021-04-19 22:25:57 +00:00
|
|
|
}
|
2021-04-20 19:41:54 +00:00
|
|
|
|
2021-04-19 22:25:57 +00:00
|
|
|
/**
|
2021-04-20 19:41:54 +00:00
|
|
|
* Checks if the editor is visible
|
2021-04-19 22:25:57 +00:00
|
|
|
*/
|
2021-04-20 19:41:54 +00:00
|
|
|
async isEditorVisible() {
|
|
|
|
// Make sure the editor actually loaded
|
2021-04-23 21:28:39 +00:00
|
|
|
// If it's not visible after 5 seconds, something is wrong
|
2021-04-20 19:41:54 +00:00
|
|
|
await this.page.waitForLoadState("networkidle")
|
|
|
|
return await this.page.isVisible("div.monaco-workbench", { timeout: 5000 })
|
2021-04-19 22:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-20 19:41:54 +00:00
|
|
|
* Focuses Integrated Terminal
|
|
|
|
* by going to the Application Menu
|
|
|
|
* and clicking View > Terminal
|
2021-04-19 22:25:57 +00:00
|
|
|
*/
|
2021-04-20 19:41:54 +00:00
|
|
|
async focusTerminal() {
|
|
|
|
// If the terminal is already visible
|
|
|
|
// then we can focus it by hitting the keyboard shortcut
|
|
|
|
const isTerminalVisible = await this.page.isVisible("#terminal")
|
|
|
|
if (isTerminalVisible) {
|
2021-04-21 21:31:15 +00:00
|
|
|
await this.page.keyboard.press(`Control+Backquote`)
|
2021-04-26 23:49:49 +00:00
|
|
|
// TODO fix this
|
2021-04-21 21:31:15 +00:00
|
|
|
// Wait for terminal to receive focus
|
|
|
|
await this.page.waitForSelector("div.terminal.xterm.focus")
|
|
|
|
// Sometimes the terminal reloads
|
|
|
|
// which is why we wait for it twice
|
|
|
|
await this.page.waitForSelector("div.terminal.xterm.focus")
|
2021-04-20 19:41:54 +00:00
|
|
|
return
|
2021-04-19 22:25:57 +00:00
|
|
|
}
|
2021-04-20 19:41:54 +00:00
|
|
|
// Open using the manu
|
|
|
|
// Click [aria-label="Application Menu"] div[role="none"]
|
|
|
|
await this.page.click('[aria-label="Application Menu"] div[role="none"]')
|
2021-04-19 22:25:57 +00:00
|
|
|
|
2021-04-20 19:41:54 +00:00
|
|
|
// Click text=View
|
|
|
|
await this.page.hover("text=View")
|
|
|
|
await this.page.click("text=View")
|
2021-04-19 22:25:57 +00:00
|
|
|
|
2021-04-20 19:41:54 +00:00
|
|
|
// Click text=Terminal
|
|
|
|
await this.page.hover("text=Terminal")
|
|
|
|
await this.page.click("text=Terminal")
|
2021-04-21 21:31:15 +00:00
|
|
|
|
|
|
|
// Wait for terminal to receive focus
|
|
|
|
// Sometimes the terminal reloads once or twice
|
|
|
|
// which is why we wait for it to have the focus class
|
|
|
|
await this.page.waitForSelector("div.terminal.xterm.focus")
|
|
|
|
// Sometimes the terminal reloads
|
|
|
|
// which is why we wait for it twice
|
|
|
|
await this.page.waitForSelector("div.terminal.xterm.focus")
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-19 22:25:57 +00:00
|
|
|
}
|
|
|
|
}
|