Skip to content

Commit 09424f5

Browse files
committed
refactor(tests): export sendKeyAndWait and make it more flexible
Change the signature of sendKeyAndWait: - Export it, so it can be used directly by tests. - Allow multiple keys to be specified. - Make times parameter optional (default 1).
1 parent f92085b commit 09424f5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

test/webdriverio/test/test_setup.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ export async function tabNavigateToWorkspace(
416416
* @param browser The active WebdriverIO Browser object.
417417
*/
418418
export async function tabNavigateForward(browser: WebdriverIO.Browser) {
419-
await browser.keys(webdriverio.Key.Tab);
420-
await browser.pause(PAUSE_TIME);
419+
await sendKeyAndWait(browser, webdriverio.Key.Tab);
421420
}
422421

423422
/**
@@ -426,8 +425,7 @@ export async function tabNavigateForward(browser: WebdriverIO.Browser) {
426425
* @param browser The active WebdriverIO Browser object.
427426
*/
428427
export async function tabNavigateBackward(browser: WebdriverIO.Browser) {
429-
await browser.keys([webdriverio.Key.Shift, webdriverio.Key.Tab]);
430-
await browser.pause(PAUSE_TIME);
428+
await sendKeyAndWait(browser, [webdriverio.Key.Shift, webdriverio.Key.Tab]);
431429
}
432430

433431
/**
@@ -471,20 +469,20 @@ export async function keyDown(browser: WebdriverIO.Browser, times = 1) {
471469
}
472470

473471
/**
474-
* Sends the specified key for the specified number of times, waiting between
475-
* each key press to allow changes to keep up.
472+
* Sends the specified key(s) for the specified number of times,
473+
* waiting between each key press to allow changes to keep up.
476474
*
477475
* @param browser The active WebdriverIO Browser object.
478-
* @param key The WebdriverIO representative key value to press.
479-
* @param times The number of times to repeat the key press.
476+
* @param keys The WebdriverIO representative key value(s) to press.
477+
* @param times The number of times to repeat the key press (default 1).
480478
*/
481-
async function sendKeyAndWait(
479+
export async function sendKeyAndWait(
482480
browser: WebdriverIO.Browser,
483-
key: string,
484-
times: number,
481+
keys: string | string[],
482+
times = 1,
485483
) {
486484
for (let i = 0; i < times; i++) {
487-
await browser.keys(key);
485+
await browser.keys(keys);
488486
await browser.pause(PAUSE_TIME);
489487
}
490488
}

0 commit comments

Comments
 (0)