-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathshared.js
More file actions
146 lines (125 loc) · 4.94 KB
/
shared.js
File metadata and controls
146 lines (125 loc) · 4.94 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { device, element, waitFor, by, expect, log } from 'detox';
const NO_ERRORS_DETECTED_LABEL = 'No errors detected';
// Helper function to add delays for iOS animations (iOS default transition is ~300ms)
const iOSDelay = ms =>
device.getPlatform() === 'ios'
? new Promise(resolve => setTimeout(resolve, ms))
: Promise.resolve();
/**
* Waits for ToS dialog to appear and accepts it.
* The native dialog is shown by the test code and this function waits for it
* to become visible, then taps the accept button.
*/
export const agreeToTermsAndConditions = async () => {
// Determine which button text to look for based on platform
const acceptButtonText = device.getPlatform() === 'ios' ? 'OK' : 'GOT IT';
log.info(`Waiting for ToS dialog with "${acceptButtonText}" button...`);
// Wait for the accept button to appear
await waitFor(element(by.text(acceptButtonText)))
.toBeVisible()
.withTimeout(30000);
log.info(`Found ${acceptButtonText} button, tapping...`);
await element(by.text(acceptButtonText)).tap();
log.info('ToS accepted successfully');
};
export const waitForStepNumber = async number => {
await waitFor(element(by.id('test_status_label')))
.toHaveText(`Test status: Step #${number}`)
.withTimeout(10000);
};
export const waitForTestToFinish = async (timeInMs = 60000) => {
await expect(element(by.id('test_status_label'))).toExist();
await waitFor(element(by.id('test_status_label')))
.toHaveText(`Test status: Finished`)
.withTimeout(timeInMs);
};
export const expectSuccess = async () => {
await expect(element(by.id('test_result_label'))).toHaveText(
'Test result: Success'
);
};
export async function expectNoErrors() {
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
if (attributes.text !== NO_ERRORS_DETECTED_LABEL) {
log.error(attributes.text);
}
await expect(element(by.id('failure_message_label'))).toHaveText(
NO_ERRORS_DETECTED_LABEL
);
}
export const initializeIntegrationTestsPage = async () => {
await device.launchApp({
delete: true,
permissions: { location: 'always' },
// Workaround for RN 0.81+ new architecture - disable Detox synchronization
// See: https://github.com/wix/Detox/issues/4842
launchArgs: { detoxEnableSynchronization: 0 },
});
// Wait for the app to fully load since synchronization is disabled
await waitFor(element(by.id('integration_tests_button')))
.toBeVisible()
.withTimeout(30000);
await iOSDelay(350);
await element(by.id('integration_tests_button')).tap();
await iOSDelay(350);
};
export const selectTestByName = async name => {
await waitFor(element(by.id('tests_menu_button')))
.toBeVisible()
.withTimeout(10000);
await iOSDelay(350);
await element(by.id('tests_menu_button')).tap();
// Wait for the overlay scroll view to be visible
await waitFor(element(by.id('overlay_scroll_view')))
.toBeVisible()
.withTimeout(10000);
const scrollView = element(by.id('overlay_scroll_view'));
const targetElement = element(by.id(name));
// Detox scroll has some issues on iOS, therefore manual swipe scrolling below is used.
// Find and position element properly for tapping
let elementReady = false;
const maxScrollAttempts = 15;
for (let i = 0; i < maxScrollAttempts && !elementReady; i++) {
try {
await waitFor(targetElement).toBeVisible().withTimeout(500);
// Element is visible, check if it's in a tappable position.
const attributes = await targetElement.getAttributes();
const scrollViewAttrs = await scrollView.getAttributes();
const elementY = attributes.frame?.y || 0;
const scrollViewY = scrollViewAttrs.frame?.y || 0;
const scrollViewHeight = scrollViewAttrs.frame?.height || 1000;
const relativeY = elementY - scrollViewY;
// If element is too bottom on the view, scroll up a bit.
if (relativeY > scrollViewHeight * 0.8) {
await scrollView.swipe('up', 'slow', 0.25);
} else {
elementReady = true;
}
} catch {
// Element not visible yet, swipe up to scroll down
await scrollView.swipe('up', 'slow', 0.3);
}
}
if (!elementReady) {
// Final fallback - just wait for visibility
await waitFor(targetElement).toBeVisible().withTimeout(5000);
}
await iOSDelay(3000);
await targetElement.tap();
};