Skip to content

Commit f096a2f

Browse files
authored
e2e: faster selection test (#747)
## 📜 Description Improve speed of `scrollUpUntilElementIsBarelyVisible` + reduce its flakiness. ## 💡 Motivation and Context Before execution of this method was ~14s. Now it's 7s. Also a new version reduces flakiness. The approach is quite simple - knowing keyboard height, device screen height and element position we can easily calculate the necessary distance for scroll to place element straight above the keyboard. Using this approach we don't need to use infinite for-loop and we can scroll only one time 😎 It's not possible to get keyboard height using Detox, so I calculated these values myself (we kind of making a process of adding a new device a little bit more complicated, but e2e tests become more reliable, so I think it's okay to have these changes). ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### E2E - added `keyboardHeight` property to device preferences; - use math calculations to get a scroll distance until element is almost hidden by keyboard; ## 🤔 How Has This Been Tested? Tested manually and CI. ## 📸 Screenshots (if appropriate): <img width="861" alt="image" src="https://github.com/user-attachments/assets/00630515-b0d4-4156-b15c-ed01dbe96acd" /> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 59b07bc commit f096a2f

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

e2e/kit/helpers/actions/index.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import colors from "colors/safe";
2-
import { expect } from "detox";
32

43
import { waitForElementById } from "../awaitable";
54
import { getDevicePreference } from "../env/devicePreferences";
@@ -129,26 +128,30 @@ export const scrollDownUntilElementIsVisible = async (
129128
.scroll(100, "down", NaN, 0.5);
130129
};
131130

131+
type Frame = {
132+
x: number;
133+
y: number;
134+
width: number;
135+
height: number;
136+
};
137+
132138
export const scrollUpUntilElementIsBarelyVisible = async (
133139
scrollViewId: string,
134140
elementId: string,
141+
threshold = 10,
135142
): Promise<void> => {
136-
for (;;) {
137-
await element(by.id(scrollViewId)).scroll(50, "up", 0.01, 0.5);
138-
139-
try {
140-
// verify that we can interact with element
141-
if (device.getPlatform() === "ios") {
142-
await expect(element(by.id(elementId))).toBeVisible();
143-
} else {
144-
// on Android visible is always true
145-
await element(by.id(elementId)).tap({ x: 0, y: 25 });
146-
}
147-
} catch (e) {
148-
await element(by.id(scrollViewId)).scroll(35, "down", 0.01, 0.5);
149-
break;
150-
}
151-
}
143+
const preference = getDevicePreference();
144+
const { frame } = (await element(by.id(elementId)).getAttributes()) as {
145+
frame: Frame;
146+
};
147+
const distance =
148+
preference.height -
149+
preference.keyboard -
150+
frame.y -
151+
frame.height -
152+
threshold;
153+
154+
await element(by.id(scrollViewId)).scroll(distance, "up", 0.01, 0.5);
152155
};
153156

154157
export const closeKeyboard = async (textInputId: string) => {

e2e/kit/helpers/env/devicePreferences.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,44 @@ import parseDeviceName from "../../utils/parseDeviceName";
22

33
type Preference = {
44
emojiButtonCoordinates?: { x: number; y: number };
5+
keyboard: number;
56
width: number;
67
height: number;
78
};
89

910
const DEVICE_PREFERENCES: Record<string, Preference> = {
1011
"e2e_emulator_28": {
12+
keyboard: 980,
1113
emojiButtonCoordinates: undefined,
1214
width: 1080,
1315
height: 1920,
1416
},
1517
"e2e_emulator_31": {
18+
keyboard: 900,
1619
emojiButtonCoordinates: { x: 324, y: 1704 },
1720
width: 1080,
1821
height: 1920,
1922
},
2023
"iPhone 16 Pro": {
24+
keyboard: 291,
2125
emojiButtonCoordinates: { x: 40, y: 830 },
2226
width: 393,
2327
height: 852,
2428
},
2529
"iPhone 15 Pro": {
30+
keyboard: 291,
2631
emojiButtonCoordinates: { x: 40, y: 830 },
2732
width: 393,
2833
height: 852,
2934
},
3035
"iPhone 14 Pro": {
36+
keyboard: 291,
3137
emojiButtonCoordinates: { x: 40, y: 830 },
3238
width: 393,
3339
height: 852,
3440
},
3541
"iPhone 13 Pro": {
42+
keyboard: 286,
3643
emojiButtonCoordinates: { x: 40, y: 830 },
3744
width: 390,
3845
height: 844,

0 commit comments

Comments
 (0)