2021-01-29 01:48:57 +07:00
|
|
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
|
|
|
|
|
|
|
describe("login", () => {
|
|
|
|
let browser: Browser
|
|
|
|
let page: Page
|
|
|
|
let context: BrowserContext
|
|
|
|
|
2021-02-03 03:58:51 +07:00
|
|
|
beforeAll(async (done) => {
|
2021-01-29 06:23:55 +07:00
|
|
|
browser = await chromium.launch()
|
2021-02-02 04:38:53 +07:00
|
|
|
// Create a new context with the saved storage state
|
|
|
|
const storageState = JSON.parse(process.env.STORAGE || "")
|
2021-02-03 03:58:51 +07:00
|
|
|
context = await browser.newContext({ storageState, recordVideo: { dir: "./test/videos/" } })
|
|
|
|
done()
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
|
2021-02-03 03:58:51 +07:00
|
|
|
afterAll(async (done) => {
|
2021-02-02 04:38:53 +07:00
|
|
|
// Remove password from local storage
|
|
|
|
await context.clearCookies()
|
|
|
|
|
2021-01-29 01:48:57 +07:00
|
|
|
await browser.close()
|
2021-01-29 06:23:55 +07:00
|
|
|
await context.close()
|
2021-02-03 03:58:51 +07:00
|
|
|
done()
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
|
2021-02-03 03:58:51 +07:00
|
|
|
beforeEach(async (done) => {
|
2021-01-29 01:48:57 +07:00
|
|
|
page = await context.newPage()
|
2021-02-03 03:58:51 +07:00
|
|
|
done()
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
|
2021-02-03 03:58:51 +07:00
|
|
|
it("should see a 'Go Home' button in the Application Menu that goes to /healthz", async (done) => {
|
2021-01-29 06:23:55 +07:00
|
|
|
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
|
|
|
|
let requestedGoHomeUrl = false
|
|
|
|
page.on("request", (request) => {
|
|
|
|
// This ensures that we did make a request to the GO_HOME_URL
|
|
|
|
// Most reliable way to test button
|
|
|
|
// because we don't care if the request has a response
|
|
|
|
// only that it was made
|
|
|
|
if (request.url() === GO_HOME_URL) {
|
|
|
|
requestedGoHomeUrl = true
|
2021-02-03 03:58:51 +07:00
|
|
|
expect(requestedGoHomeUrl).toBeTruthy()
|
|
|
|
|
|
|
|
// This ensures Jest knows we're done here.
|
|
|
|
done()
|
2021-01-29 06:23:55 +07:00
|
|
|
}
|
|
|
|
})
|
2021-02-03 03:58:51 +07:00
|
|
|
// Sometimes a dialog shows up when you navigate
|
|
|
|
// asking if you're sure you want to leave
|
|
|
|
// so we listen if it comes, we accept it
|
|
|
|
page.on("dialog", (dialog) => dialog.accept())
|
2021-02-02 04:38:53 +07:00
|
|
|
|
|
|
|
// waitUntil: "domcontentloaded"
|
2021-01-29 06:23:55 +07:00
|
|
|
// In case the page takes a long time to load
|
2021-02-02 04:38:53 +07:00
|
|
|
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
|
2021-02-03 03:58:51 +07:00
|
|
|
|
|
|
|
// For some odd reason, the login method used in globalSetup.ts
|
|
|
|
// I don't know if it's on playwright clearing our cookies by accident
|
|
|
|
// or if it's our cookies disappearing.
|
|
|
|
// This means we need an additional check to make sure we're logged in
|
|
|
|
// otherwise this test will hang and fail.
|
|
|
|
const currentPageURL = await page.url()
|
|
|
|
const isLoginPage = currentPageURL.includes("login")
|
|
|
|
if (isLoginPage) {
|
|
|
|
await page.fill(".password", process.env.PASSWORD || "password")
|
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
|
|
|
}
|
|
|
|
|
2021-01-29 06:23:55 +07:00
|
|
|
// Click the Application menu
|
2021-01-29 01:48:57 +07:00
|
|
|
await page.click(".menubar-menu-button[title='Application Menu']")
|
|
|
|
// See the Go Home button
|
2021-01-29 06:23:55 +07:00
|
|
|
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
|
2021-01-29 01:48:57 +07:00
|
|
|
expect(await page.isVisible(goHomeButton))
|
2021-02-03 03:58:51 +07:00
|
|
|
|
|
|
|
// Click it and navigate to /healthz
|
2021-01-29 06:23:55 +07:00
|
|
|
// NOTE: ran into issues of it failing intermittently
|
|
|
|
// without having button: "middle"
|
|
|
|
await page.click(goHomeButton, { button: "middle" })
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
})
|