1
1
import { chromium , Page , Browser , BrowserContext } from "playwright"
2
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
3
describe ( "login" , ( ) => {
8
4
let browser : Browser
9
5
let page : Page
10
6
let context : BrowserContext
11
7
12
8
beforeAll ( async ( ) => {
13
- browser = await chromium . launch ( { headless : false } )
9
+ browser = await chromium . launch ( )
14
10
context = await browser . newContext ( )
15
11
} )
16
12
17
13
afterAll ( async ( ) => {
18
14
await browser . close ( )
15
+ await context . close ( )
19
16
} )
20
17
21
18
beforeEach ( async ( ) => {
@@ -29,22 +26,40 @@ describe("login", () => {
29
26
} )
30
27
31
28
it ( "should see a 'Go Home' button in the Application Menu that goes to coder.com" , async ( ) => {
32
- await page . goto ( "http://localhost:8080" )
29
+ const GO_HOME_URL = `${ process . env . CODE_SERVER_ADDRESS } /healthz`
30
+ let requestedGoHomeUrl = false
31
+ page . on ( "request" , ( request ) => {
32
+ // This ensures that we did make a request to the GO_HOME_URL
33
+ // Most reliable way to test button
34
+ // because we don't care if the request has a response
35
+ // only that it was made
36
+ if ( request . url ( ) === GO_HOME_URL ) {
37
+ requestedGoHomeUrl = true
38
+ }
39
+ } )
40
+ // waitUntil: "networkidle"
41
+ // In case the page takes a long time to load
42
+ await page . goto ( process . env . CODE_SERVER_ADDRESS || "http://localhost:8080" , { waitUntil : "networkidle" } )
33
43
// Type in password
34
- await page . fill ( ".password" , PASSWORD )
44
+ await page . fill ( ".password" , process . env . PASSWORD || "password" )
35
45
// Click the submit button and login
36
46
await page . click ( ".submit" )
37
- // Click the Applicaiton menu
47
+ // Click the Application menu
38
48
await page . click ( ".menubar-menu-button[title='Application Menu']" )
39
49
// See the Go Home button
40
- const goHomeButton = ".home-bar [aria-label='Home'] li "
50
+ const goHomeButton = "a.action-menu-item span [aria-label='Go Home']"
41
51
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/")
52
+ // Click it and navigate to coder.com
53
+ // NOTE: ran into issues of it failing intermittently
54
+ // without having button: "middle"
55
+ await page . click ( goHomeButton , { button : "middle" } )
56
+
57
+ // If there are unsaved changes it will show a dialog
58
+ // asking if you're sure you want to leave
59
+ page . on ( "dialog" , ( dialog ) => dialog . accept ( ) )
60
+
61
+ // We make sure to wait on a request to the GO_HOME_URL
62
+ await page . waitForRequest ( GO_HOME_URL )
63
+ expect ( requestedGoHomeUrl ) . toBeTruthy ( )
49
64
} )
50
65
} )
0 commit comments