@@ -81,25 +81,10 @@ export class CodeServer {
81
81
* visible already.
82
82
*/
83
83
async focusTerminal ( ) {
84
- // Click [aria-label="Application Menu"] div[role="none"]
85
- await this . page . click ( '[aria-label="Application Menu"] div[role="none"]' )
86
-
87
- // Click text=View
88
- await this . page . hover ( "text=View" )
89
- await this . page . click ( "text=View" )
90
-
91
- // Click text=Command Palette
92
- await this . page . hover ( "text=Command Palette" )
93
- await this . page . click ( "text=Command Palette" )
94
-
95
- // Type Terminal: Focus Terminal
96
- await this . page . keyboard . type ( "Terminal: Focus Terminal" )
97
-
98
- // Click Terminal: Focus Terminal
99
- await this . page . hover ( "text=Terminal: Focus Terminal" )
100
- await this . page . click ( "text=Terminal: Focus Terminal" )
84
+ // Execute the focus terminal command via the command palette.
85
+ await this . runCommandFromPalette ( "Terminal: Focus Terminal" )
101
86
102
- // Wait for terminal textarea to show up
87
+ // Wait for terminal textarea to show up.
103
88
await this . page . waitForSelector ( "textarea.xterm-helper-textarea" )
104
89
}
105
90
@@ -113,4 +98,32 @@ export class CodeServer {
113
98
await this . navigate ( )
114
99
await this . reloadUntilEditorIsReady ( )
115
100
}
101
+
102
+ /**
103
+ * Run a command via the command palette.
104
+ */
105
+ async runCommandFromPalette ( command : string ) {
106
+ await this . runCommandFromMenu ( [ "View" , "Command Palette" ] )
107
+
108
+ // Type the command we want.
109
+ await this . page . keyboard . type ( command )
110
+
111
+ // Click on the matching command.
112
+ await this . page . hover ( `text=${ command } ` )
113
+ await this . page . click ( `text=${ command } ` )
114
+ }
115
+
116
+ /**
117
+ * Run a command from the application menu.
118
+ */
119
+ async runCommandFromMenu ( menus : string [ ] ) {
120
+ // Open the application menu.
121
+ await this . page . click ( '[aria-label="Application Menu"] div[role="none"]' )
122
+
123
+ // Open each sub-menu in turn.
124
+ for ( const menu in menus ) {
125
+ await this . page . hover ( `text=${ menu } ` )
126
+ await this . page . click ( `text=${ menu } ` )
127
+ }
128
+ }
116
129
}
0 commit comments