@@ -5,6 +5,7 @@ import { CODE_SERVER_ADDRESS } from "../../utils/constants"
55// See Playwright docs: https://playwright.dev/docs/pom/
66export class CodeServer {
77 page : Page
8+ editorSelector = "div.monaco-workbench"
89
910 constructor ( page : Page ) {
1011 this . page = page
@@ -30,15 +31,18 @@ export class CodeServer {
3031 // but usually a reload or two fixes it
3132 // TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
3233 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 )
3340 reloadCount += 1
3441 if ( await this . isEditorVisible ( ) ) {
3542 console . log ( ` Editor became visible after ${ reloadCount } reloads` )
3643 break
3744 }
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 ( )
4246 }
4347 }
4448
@@ -49,46 +53,39 @@ export class CodeServer {
4953 // Make sure the editor actually loaded
5054 // If it's not visible after 5 seconds, something is wrong
5155 await this . page . waitForLoadState ( "networkidle" )
52- return await this . page . isVisible ( "div.monaco-workbench" , { timeout : 5000 } )
56+ return await this . page . isVisible ( this . editorSelector )
5357 }
5458
5559 /**
5660 * 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.
5967 */
6068 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- // Wait for terminal to receive focus
67- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
68- // Sometimes the terminal reloads
69- // which is why we wait for it twice
70- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
71- return
72- }
73- // Open using the manu
7469 // Click [aria-label="Application Menu"] div[role="none"]
7570 await this . page . click ( '[aria-label="Application Menu"] div[role="none"]' )
7671
7772 // Click text=View
7873 await this . page . hover ( "text=View" )
7974 await this . page . click ( "text=View" )
8075
81- // Click text=Terminal
82- await this . page . hover ( "text=Terminal" )
83- 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" )
8486
85- // Wait for terminal to receive focus
86- // Sometimes the terminal reloads once or twice
87- // which is why we wait for it to have the focus class
88- await this . page . waitForSelector ( "div.terminal.xterm.focus" )
89- // Sometimes the terminal reloads
90- // which is why we wait for it twice
91- 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" )
9289 }
9390
9491 /**
0 commit comments