@@ -9,53 +9,66 @@ export class CodeServer {
9
9
constructor ( page : Page ) {
10
10
this . page = page
11
11
}
12
+
13
+ /**
14
+ * Navigates to CODE_SERVER_ADDRESS
15
+ */
12
16
async navigate ( ) {
13
17
await this . page . goto ( CODE_SERVER_ADDRESS , { waitUntil : "networkidle" } )
14
- // Make sure the editor actually loaded
15
- await this . page . isVisible ( "div.monaco-workbench" )
18
+
19
+ let editorIsVisible = await this . isEditorVisible ( )
20
+ let reloadCount = 0
21
+
22
+ // Occassionally code-server timeouts in Firefox
23
+ // we're not sure why
24
+ // but usually a reload or two fixes it
25
+ // TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
26
+ // TODO@jsjoeio sometimes it's 2 reloads, othertimes it's 9
27
+ // double-check this logic
28
+ while ( ! editorIsVisible ) {
29
+ reloadCount += 1
30
+ editorIsVisible = await this . isEditorVisible ( )
31
+ if ( editorIsVisible ) {
32
+ console . log ( `Editor became visible after ${ reloadCount } reloads` )
33
+ break
34
+ }
35
+ await this . page . reload ( { waitUntil : "networkidle" } )
36
+ }
16
37
}
38
+
17
39
/**
18
- * Opens the default folder /User if no arg passed
19
- * @param absolutePath Example: /Users/jp/.local/share/code-server/User/
20
- *
40
+ * Checks if the editor is visible
21
41
*/
22
- async openFolder ( absolutePath ?: string ) {
23
- // Check if no folder is opened
24
- const folderIsNotOpen = await this . page . isVisible ( "text=You have not yet opened" )
25
-
26
- if ( folderIsNotOpen ) {
27
- // Open the default folder
28
- await this . page . keyboard . press ( "Meta+O" )
29
- await this . page . keyboard . press ( "Enter" )
30
- await this . page . waitForLoadState ( "networkidle" )
31
- }
42
+ async isEditorVisible ( ) {
43
+ // Make sure the editor actually loaded
44
+ // If it's not visible after 2 seconds, something is wrong
45
+ await this . page . waitForLoadState ( "networkidle" )
46
+ return await this . page . isVisible ( "div.monaco-workbench" , { timeout : 5000 } )
32
47
}
33
48
34
49
/**
35
- * Toggles the integrated terminal if not already in view
36
- * and focuses it
50
+ * Focuses Integrated Terminal
51
+ * by going to the Application Menu
52
+ * and clicking View > Terminal
37
53
*/
38
- async viewTerminal ( ) {
39
- // Check if Terminal is already in view
40
- const isTerminalInView = await this . page . isVisible ( "#terminal" )
41
-
42
- if ( ! isTerminalInView ) {
43
- // Open using default keyboard shortcut
44
- await this . focusTerminal ( )
45
- await this . page . waitForSelector ( "#terminal" )
54
+ async focusTerminal ( ) {
55
+ // If the terminal is already visible
56
+ // then we can focus it by hitting the keyboard shortcut
57
+ const isTerminalVisible = await this . page . isVisible ( "#terminal" )
58
+ if ( isTerminalVisible ) {
59
+ await this . page . keyboard . press ( `Meta+Backquote` )
60
+ return
46
61
}
47
- }
62
+ // Open using the manu
63
+ // Click [aria-label="Application Menu"] div[role="none"]
64
+ await this . page . click ( '[aria-label="Application Menu"] div[role="none"]' )
48
65
49
- async focusTerminal ( ) {
50
- await this . page . keyboard . press ( "Control+Backquote ")
51
- }
66
+ // Click text=View
67
+ await this . page . hover ( "text=View ")
68
+ await this . page . click ( "text=View" )
52
69
53
- async quickOpen ( input : string ) {
54
- await this . page . keyboard . press ( "Meta+P" )
55
- await this . page . waitForSelector ( '[aria-describedby="quickInput_message"]' )
56
- await this . page . keyboard . type ( input )
57
- await this . page . waitForTimeout ( 2000 )
58
- await this . page . keyboard . press ( "Enter" )
59
- await this . page . waitForTimeout ( 2000 )
70
+ // Click text=Terminal
71
+ await this . page . hover ( "text=Terminal" )
72
+ await this . page . click ( "text=Terminal" )
60
73
}
61
74
}
0 commit comments