@@ -73,58 +73,24 @@ export async function pressKey(driver: WebDriver, key: keyof typeof Key): Promis
7373 await driver . actions ( ) . sendKeys ( key ) . perform ( )
7474}
7575
76- type OSType = 'windows' | 'mac'
77- type modifierKey = 'alt' | 'ctrl' | 'shift' | 'option' | 'command'
78-
79- const MODIFIERKEYS : Record < OSType , Record < modifierKey , string > > = {
80- windows : {
81- alt : Key . ALT ,
82- ctrl : Key . CONTROL ,
83- shift : Key . SHIFT ,
84- option : Key . ALT ,
85- command : Key . COMMAND ,
86- } ,
87- mac : {
88- alt : Key . ALT ,
89- ctrl : Key . CONTROL ,
90- shift : Key . SHIFT ,
91- option : Key . ALT ,
92- command : Key . COMMAND ,
93- } ,
94- }
95-
9676/**
9777 * Presses a keyboard shortcut with modifier keys
9878 * @param driver The WebDriver instance
99- * @param key The key to press
100- * @param modifier The modifier key(s)
101- * @param osType The operating system type
79+ * @param key The keys to press
80+ *
81+ * Examples:
82+ * Ctrl + C | await pressShortcut(driver, Key.CONTROL, 'c')
83+ * Ctrl + Shift + T | await pressShortcut(driver, Key.CONTROL, Key.SHIFT, 't')
10284 */
103- export async function pressShortcut (
104- driver : WebDriver ,
105- key : string ,
106- modifier : modifierKey | modifierKey [ ] ,
107- osType : OSType = 'windows'
108- ) : Promise < void > {
109- const actions = driver . actions ( { bridge : true } )
110-
111- try {
112- const modifiers = Array . isArray ( modifier ) ? modifier : modifier ? [ modifier ] : [ ]
113- for ( const mod of modifiers ) {
114- if ( ! ( mod in MODIFIERKEYS [ osType ] ) ) {
115- throw new Error ( `Invalid modifier key '${ mod } ' for ${ osType } ` )
116- }
117- actions . keyDown ( MODIFIERKEYS [ osType ] [ mod ] )
118- }
119- actions . sendKeys ( key )
120- for ( const mod of modifiers . reverse ( ) ) {
121- actions . keyUp ( MODIFIERKEYS [ osType ] [ mod ] )
122- }
123- await actions . perform ( )
124- } catch ( error ) {
125- console . error ( `Error performing keyboard shortcut: ${ error } ` )
126- throw error
85+ export async function pressShortcut ( driver : WebDriver , ...keys : ( keyof typeof Key ) [ ] ) : Promise < void > {
86+ const actions = driver . actions ( )
87+ for ( const key of keys ) {
88+ actions . keyDown ( key )
12789 }
90+ for ( const key of keys . reverse ( ) ) {
91+ actions . keyUp ( key )
92+ }
93+ await actions . perform ( )
12894}
12995
13096/**
@@ -205,6 +171,18 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor
205171 return textEditor
206172}
207173
174+ /**
175+ * Writes the given string in the textEditor in the next empty line
176+ * @param textEditor The TextEditor instance
177+ * @param text The text the user wants to type
178+ * @returns Promise<void>
179+ */
180+ export async function writeToTextEditor ( textEditor : TextEditor , text : string ) : Promise < void > {
181+ const currentLines = await textEditor . getNumberOfLines ( )
182+ const nextLine = currentLines + 1
183+ await textEditor . typeTextAt ( nextLine , 1 , text )
184+ }
185+
208186/**
209187 * Finds an item based on the text
210188 * @param items WebElement array to search
0 commit comments