-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathe2e-utils.ts
More file actions
92 lines (77 loc) · 2.98 KB
/
e2e-utils.ts
File metadata and controls
92 lines (77 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { device, expect, element, by } from 'detox';
import { AndroidElementAttributes, IosElementAttributes } from 'detox/detox';
export const describeIfiOS =
device.getPlatform() === 'ios' ? describe : describe.skip;
export const describeIfAndroid =
device.getPlatform() === 'android' ? describe : describe.skip;
async function scrollUntilVisible(id: string, scrollViewId: string) {
await waitFor(element(by.id(id)))
.toBeVisible()
.whileElement(by.id(scrollViewId))
.scroll(600, 'down', Number.NaN, 0.85);
}
export async function selectIssueTestScreen(screenName: string) {
await scrollUntilVisible(
'root-screen-issue-tests',
'root-screen-examples-scrollview',
);
await element(by.id('root-screen-issue-tests')).tap();
await waitFor(element(by.id('issue-tests-scrollview'))).toBeVisible();
if (device.getPlatform() === 'android') {
await element(by.label('Search')).tap();
// This is the only way I was able to get the search box text input.
// I don't know why element(by.type('androidx.appcompat.widget.SearchView.SearchAutoComplete'))
// does not work even if it appears in view hierarchy returned by Detox in debug logging mode.
await element(by.text('')).replaceText(screenName);
} else if (device.getPlatform() === 'ios') {
await element(by.traits(['searchField'])).typeText(screenName);
}
await expect(element(by.id(`issue-tests-${screenName}`))).toBeVisible();
await element(by.id(`issue-tests-${screenName}`)).tap();
}
export async function selectSingleFeatureTestsScreen(
scenarioGroup: string,
screenKey: string,
) {
await scrollUntilVisible(
'root-screen-single-feature-tests',
'root-screen-examples-scrollview',
);
await element(by.id('root-screen-single-feature-tests')).tap();
await waitFor(element(by.id('single-feature-tests-scrollview')))
.toBeVisible()
.withTimeout(3000);
await scrollUntilVisible(
`single-feature-tests-${scenarioGroup}`,
'single-feature-tests-scrollview',
);
await element(by.id(`single-feature-tests-${scenarioGroup}`)).tap();
await waitFor(element(by.id(`${scenarioGroup}-scenarios-scrollview`)))
.toBeVisible()
.withTimeout(3000);
await scrollUntilVisible(
`${screenKey}`,
`${scenarioGroup}-scenarios-scrollview`,
);
await element(by.id(`${screenKey}`)).tap();
}
type ElementAttributes = IosElementAttributes | AndroidElementAttributes;
export async function getElementAttributes(
testLabel: string,
): Promise<ElementAttributes> {
const attrs = await element(by.label(testLabel)).getAttributes();
if ('elements' in attrs) {
throw new Error(
`Multiple elements (${attrs.elements.length}) found for label: "${testLabel}". `
);
}
return attrs as ElementAttributes;
}
export async function forceTapByLabeliOS(testLabel: string) {
const elementAttributes = await getElementAttributes(testLabel);
const { x, y, width, height } = elementAttributes.frame;
await device.tap({
x: x + width / 2,
y: y + height / 2,
});
}