Skip to content

Commit 2868e5c

Browse files
committed
refactor: update password for login test
1 parent 47cbad2 commit 2868e5c

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

test/goHome.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { chromium, Page, Browser, BrowserContext } from "playwright"
2+
3+
// NOTE: this is hard-coded and passed as an environment variable
4+
// See the test job in ci.yml
5+
const PASSWORD = "e45432jklfdsab"
6+
7+
describe("login", () => {
8+
let browser: Browser
9+
let page: Page
10+
let context: BrowserContext
11+
12+
beforeAll(async () => {
13+
browser = await chromium.launch({ headless: false })
14+
context = await browser.newContext()
15+
})
16+
17+
afterAll(async () => {
18+
await browser.close()
19+
})
20+
21+
beforeEach(async () => {
22+
page = await context.newPage()
23+
})
24+
25+
afterEach(async () => {
26+
await page.close()
27+
// Remove password from local storage
28+
await context.clearCookies()
29+
})
30+
31+
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
32+
await page.goto("http://localhost:8080")
33+
// Type in password
34+
await page.fill(".password", PASSWORD)
35+
// Click the submit button and login
36+
await page.click(".submit")
37+
// Click the Applicaiton menu
38+
await page.click(".menubar-menu-button[title='Application Menu']")
39+
// See the Go Home button
40+
const goHomeButton = ".home-bar[aria-label='Home'] li"
41+
expect(await page.isVisible(goHomeButton))
42+
// Hover over element without clicking
43+
await page.hover(goHomeButton)
44+
// Click the top left corner of the element
45+
await page.click(goHomeButton)
46+
// Note: we have to click on <li> in the Go Home button for it to work
47+
// Land on coder.com
48+
// expect(await page.url()).toBe("https://coder.com/")
49+
})
50+
})

test/login.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { chromium, Page, Browser, BrowserContext } from "playwright"
22

3+
// NOTE: this is hard-coded and passed as an environment variable
4+
// See the test job in ci.yml
5+
const PASSWORD = "e45432jklfdsab"
6+
37
describe("login", () => {
48
let browser: Browser
59
let page: Page
@@ -20,6 +24,7 @@ describe("login", () => {
2024

2125
afterEach(async () => {
2226
await page.close()
27+
// Remove password from local storage
2328
await context.clearCookies()
2429
})
2530

@@ -31,15 +36,12 @@ describe("login", () => {
3136

3237
it("should be able to login with the password from config.yml", async () => {
3338
await page.goto("http://localhost:8080")
34-
// Get password
35-
const password = "helloworld"
3639
// Type in password
37-
await page.fill(".password", password)
40+
await page.fill(".password", PASSWORD)
3841
// Click the submit button and login
3942
await page.click(".submit")
4043
// See the editor
4144
const codeServerEditor = await page.isVisible(".monaco-workbench")
4245
expect(codeServerEditor).toBeTruthy()
43-
// Remove password from local storage
4446
})
4547
})

0 commit comments

Comments
 (0)