@@ -5,6 +5,7 @@ import { CODE_SERVER_ADDRESS } from "../../utils/constants"
5
5
// See Playwright docs: https://playwright.dev/docs/pom/
6
6
export class CodeServer {
7
7
page : Page
8
+ editorSelector = "div.monaco-workbench"
8
9
9
10
constructor ( page : Page ) {
10
11
this . page = page
@@ -30,15 +31,18 @@ export class CodeServer {
30
31
// but usually a reload or two fixes it
31
32
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
32
33
while ( ! editorIsVisible ) {
34
+ // When a reload happens, we want to wait for all resources to be
35
+ // loaded completely. Hence why we use that instead of DOMContentLoaded
36
+ // Read more: https://thisthat.dev/dom-content-loaded-vs-load/
37
+ await this . page . waitForLoadState ( "load" )
38
+ // Give it an extra second just in case it's feeling extra slow
39
+ await this . page . waitForTimeout ( 1000 )
33
40
reloadCount += 1
34
41
if ( await this . isEditorVisible ( ) ) {
35
42
console . log ( ` Editor became visible after ${ reloadCount } reloads` )
36
43
break
37
44
}
38
- // When a reload happens, we want to wait for all resources to be
39
- // loaded completely. Hence why we use that instead of DOMContentLoaded
40
- // Read more: https://thisthat.dev/dom-content-loaded-vs-load/
41
- await this . page . reload ( { waitUntil : "load" } )
45
+ await this . page . reload ( )
42
46
}
43
47
}
44
48
@@ -49,47 +53,39 @@ export class CodeServer {
49
53
// Make sure the editor actually loaded
50
54
// If it's not visible after 5 seconds, something is wrong
51
55
await this . page . waitForLoadState ( "networkidle" )
52
- return await this . page . isVisible ( "div.monaco-workbench" , { timeout : 5000 } )
56
+ return await this . page . isVisible ( this . editorSelector )
53
57
}
54
58
55
59
/**
56
60
* Focuses Integrated Terminal
57
- * by going to the Application Menu
58
- * and clicking View > Terminal
61
+ * by using "Terminal: Focus Terminal"
62
+ * from the Command Palette
63
+ *
64
+ * This should focus the terminal no matter
65
+ * if it already has focus and/or is or isn't
66
+ * visible already.
59
67
*/
60
68
async focusTerminal ( ) {
61
- // If the terminal is already visible
62
- // then we can focus it by hitting the keyboard shortcut
63
- const isTerminalVisible = await this . page . isVisible ( "#terminal" )
64
- if ( isTerminalVisible ) {
65
- await this . page . keyboard . press ( `Control+Backquote` )
66
- // TODO fix this
67
- // Wait for terminal to receive focus
68
- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
69
- // Sometimes the terminal reloads
70
- // which is why we wait for it twice
71
- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
72
- return
73
- }
74
- // Open using the manu
75
69
// Click [aria-label="Application Menu"] div[role="none"]
76
70
await this . page . click ( '[aria-label="Application Menu"] div[role="none"]' )
77
71
78
72
// Click text=View
79
73
await this . page . hover ( "text=View" )
80
74
await this . page . click ( "text=View" )
81
75
82
- // Click text=Terminal
83
- await this . page . hover ( "text=Terminal" )
84
- await this . page . click ( "text=Terminal" )
76
+ // Click text=Command Palette
77
+ await this . page . hover ( "text=Command Palette" )
78
+ await this . page . click ( "text=Command Palette" )
79
+
80
+ // Type Terminal: Focus Terminal
81
+ await this . page . keyboard . type ( "Terminal: Focus Terminal" )
82
+
83
+ // Click Terminal: Focus Terminal
84
+ await this . page . hover ( "text=Terminal: Focus Terminal" )
85
+ await this . page . click ( "text=Terminal: Focus Terminal" )
85
86
86
- // Wait for terminal to receive focus
87
- // Sometimes the terminal reloads once or twice
88
- // which is why we wait for it to have the focus class
89
- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
90
- // Sometimes the terminal reloads
91
- // which is why we wait for it twice
92
- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
87
+ // Wait for terminal textarea to show up
88
+ await this . page . waitForSelector ( "textarea.xterm-helper-textarea" )
93
89
}
94
90
95
91
/**
0 commit comments