Skip to content

Commit

Permalink
use Gestures for waitAndTapByLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleewilcox committed Feb 28, 2024
1 parent 3dd1dc5 commit 3c59197
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions e2e/pages/Onboarding/DefaultNetworkView.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';
import NetworksView from '../Settings/NetworksView';
import TestHelpers from '../../helpers';
import {
CustomDefaultNetworkIDs,
CustomDefaultNetworkTexts,
Expand All @@ -19,10 +18,10 @@ class DefaultNetworkView {
await Gestures.waitAndTap(this.useThisNetworkButton);
await Gestures.waitAndTap(this.useThisNetworkButton);
} else {
await TestHelpers.waitAndTapByLabel(
await Gestures.waitAndTapByLabel(
CustomDefaultNetworkTexts.USE_THIS_NETWORK_BUTTON_TEXT,
);
await TestHelpers.waitAndTapByLabel(
await Gestures.waitAndTapByLabel(
CustomDefaultNetworkTexts.USE_THIS_NETWORK_BUTTON_TEXT,
);
}
Expand Down
18 changes: 18 additions & 0 deletions e2e/utils/Gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ class Gestures {
await element.atIndex(index).tap();
}

/**
* Waits for an element with a specific label to become visible within a given timeout, then taps on it.
* This function is particularly useful in automated UI testing where you need to interact with elements that may take some time to appear.
*
* @param {string} text The label of the element to wait for and tap.
* @param {number} [timeout=8000] The maximum amount of time (in milliseconds) to wait for the element to become visible. Defaults to 8000ms if not specified.
* @param {number} [index=0] The index of the element to tap if there are multiple elements with the same label. Defaults to 0 (the first element) if not specified.
* @returns {Promise<void>} A promise that resolves when the tap action has been completed.
* @static
* @async
*/
static async waitAndTapByLabel(text, timeout = 8000, index = 0) {
await waitFor(element(by.label(text)))
.toBeVisible()
.withTimeout(timeout);
await element(by.label(text)).atIndex(index).tap();
}

/**
* Wait for an element to be visible and then tap it.
*
Expand Down

0 comments on commit 3c59197

Please sign in to comment.