Fix outdated selector. Add debug info.

This commit is contained in:
Teffen Ellis 2021-09-15 13:55:21 -04:00 committed by Teffen Ellis
parent c861a1d796
commit 7f2b1dcd22
2 changed files with 16 additions and 3 deletions

View File

@ -8,7 +8,7 @@ describe("browser", true, () => {
firefox: "Firefox", firefox: "Firefox",
webkit: "Safari", webkit: "Safari",
} }
const userAgent = await codeServerPage.page.evaluate("navigator.userAgent") const userAgent = await codeServerPage.page.evaluate(() => navigator.userAgent)
expect(userAgent).toContain(displayNames[browserName]) expect(userAgent).toContain(displayNames[browserName])
}) })

View File

@ -177,6 +177,8 @@ export class CodeServerPage {
* Reload until both checks pass * Reload until both checks pass
*/ */
async reloadUntilEditorIsReady() { async reloadUntilEditorIsReady() {
this.codeServer.logger.debug("Waiting for editor to be ready...")
const editorIsVisible = await this.isEditorVisible() const editorIsVisible = await this.isEditorVisible()
const editorIsConnected = await this.isConnected() const editorIsConnected = await this.isConnected()
let reloadCount = 0 let reloadCount = 0
@ -199,25 +201,36 @@ export class CodeServerPage {
} }
await this.page.reload() await this.page.reload()
} }
this.codeServer.logger.debug("Editor is ready!")
} }
/** /**
* Checks if the editor is visible * Checks if the editor is visible
*/ */
async isEditorVisible() { async isEditorVisible() {
this.codeServer.logger.debug("Waiting for editor to be visible...")
// Make sure the editor actually loaded // Make sure the editor actually loaded
await this.page.waitForSelector(this.editorSelector) await this.page.waitForSelector(this.editorSelector)
return await this.page.isVisible(this.editorSelector) const visible = await this.page.isVisible(this.editorSelector)
this.codeServer.logger.debug(`Editor is ${visible ? "not visible" : "visible"}!`)
return visible
} }
/** /**
* Checks if the editor is visible * Checks if the editor is visible
*/ */
async isConnected() { async isConnected() {
this.codeServer.logger.debug("Waiting for network idle...")
await this.page.waitForLoadState("networkidle") await this.page.waitForLoadState("networkidle")
const host = new URL(await this.codeServer.address()).host const host = new URL(await this.codeServer.address()).host
const hostSelector = `[title="Editing on ${host}"]` // NOTE: This seems to be pretty brittle between version changes.
const hostSelector = `[aria-label="remote ${host}"]`
this.codeServer.logger.debug(`Waiting selector: ${hostSelector}`)
await this.page.waitForSelector(hostSelector) await this.page.waitForSelector(hostSelector)
return await this.page.isVisible(hostSelector) return await this.page.isVisible(hostSelector)