You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/introduction/your-first-test.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -204,8 +204,8 @@ If you haven't changed the generated `e2e/starter.test.js`, you are likely to se
204
204
…
205
205
```
206
206
207
-
If you have created your own test, and it is failing, examine the error message, check out our [Investigating Failures](../guide/investigating-test-failure.mdx)
208
-
and [Debugging](debugging.mdx) guides, and run your tests again after you fix the issue.
207
+
If you have created your own test, and it is failing, examine the error message, check out our [Troubleshooting](../troubleshooting/running-tests.md)
The preferred matching technique is always matching based on test ID's.
4
+
5
+
React Native only supports the `testID` prop on the native built-in components. If you’ve created a custom composite component, you will have to support this prop yourself. You should probably propagate the `testID` prop to one of your rendered children (a built-in component):
6
+
7
+
```jsx
8
+
exportclassMyCompositeComponentextendsComponent {
9
+
render() {
10
+
return (
11
+
<TouchableOpacity testID={this.props.testID}>
12
+
<View>
13
+
<Text>Something something</Text>
14
+
</View>
15
+
</TouchableOpacity>
16
+
);
17
+
}
18
+
}
19
+
```
20
+
21
+
Now, adding `testID` to your composite component should work:
You can also investigate the app’s native view hierarchy, this might shed some light on how the app’s view hierarchy is laid out and therefore why an element matching doesn't work (perhaps a test ID should be used, or the matcher should be improved).
32
+
33
+
On iOS, one way this can be done is by using `xcode`. Do the following:
34
+
35
+
1. Start a debuggable app (not a release build) in your simulator
36
+
1. Open Xcode
37
+
1. Attach Xcode to your app’s process
38
+

Copy file name to clipboardExpand all lines: docs/troubleshooting/running-tests.md
+62-116
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,8 @@
1
1
# Dealing With Problems With Running Tests
2
2
3
-
This page is about issues related to executing your Detox tests, typically triggered when running `detox test` (and not `detox build`, for example).
4
-
5
-
## Trace Mode
3
+
<!-- markdownlint-disable MD024 -->
6
4
7
-
It’s a good idea to get as much information as possible about what’s going on. We can enable trace mode during tests by running our tests with:
8
-
9
-
```bash
10
-
detox test --loglevel trace
11
-
```
5
+
This page is about issues related to executing your Detox tests, typically triggered when running `detox test` (and not `detox build`, for example).
12
6
13
7
## No simulators found (iOS)
14
8
@@ -18,125 +12,104 @@ If you’re missing a simulator, make sure Xcode is installed and use it to down
18
12
19
13
Once the desired simulator is installed and returned by `xcrun simctl list`, double check its name in the list and make sure this name is found in the `detox` configuration entry in `package.json`. The reference for the configuration options is available [here](../config/devices.mdx).
20
14
21
-
## Tests execution hangs
15
+
## Detox starts but my test doesn't actually run
16
+
17
+
### Issue
22
18
23
-
**Issue:** A while after running Detox, you get a message about failure to connect to the running app, in the logs:
19
+
- A while after running Detox, things seem to hang and you get a message about a failure to connect to the running app, in Detox's logs:
24
20
25
21
```plain text
26
22
Detox can’t seem to connect to the test app(s)!
27
23
```
28
24
25
+
### Course of action
26
+
29
27
This can be a result of various reasons. It is generally up to you to debug and find the root cause. In any case, below are the common ones.
30
28
31
-
### If you do not see your app running on the device
29
+
####If you don't see your app running on the device
32
30
33
31
- You might have forgotten to run `device.launchApp()` in the beginning of your test.
34
32
- The app might have crashed before Detox has had a chance to connect to it. To get the crash details, you can run Detox tests with `--record-logs all` CLI option and then inspect the device logs in the artifacts' folder.
35
33
-**On Android**, there might be a problem with the native test code in the `DetoxTest.java` file. Revisit the [associated section](../introduction/project-setup.mdx#step-4-additional-android-configuration) in the setup guide.
36
34
-**On Android**, your `Network Security Config` may not be recognized. Revisit the [associated section](../introduction/project-setup.mdx#43-enabling-unencrypted-traffic-for-detox) in the setup guide.
37
35
38
-
### If you _do_ see your app running on the device
36
+
**If you _do_ see your app running on the device**
39
37
40
38
-**On Android with SDK≥28**, the app’s connection to the Detox test server is blocked due to clear-traffic blockage (as reported in issue [#1450](https://github.com/wix/Detox/issues/1450)).
41
39
The main step for getting this fixed is to revisit the [associated section](../introduction/project-setup.mdx#step-4-additional-android-configuration) in the setup guide, which discusses network-security. Alternatively, the `android:usesCleartextTraffic="true"` attribute can be configured in the `<application>` tag of the app’s `AndroidManifest.xml`, but **that is highly discouraged**.
42
40
- If you’ve applied the above suggestion but the app fails to connect to the Detox test server, nonetheless: Refer to the device’s logs, which should contain messages about failed connection attempts (get them using the `--record-logs all` argument)
43
41
- The app could be running without Detox native code injected. In this case, first, make sure you’re not trying to run in manual launch mode (where this behavior is valid). If so, examine the logs from the device (get them using the `--record-logs all` argument). If you see a crash related to Detox’s native code, you are welcome to report it on our GitHub tracker.
44
-
-If you are in fact debugging your native code integration with Detox, our [Debugging tutorial](../introduction/debugging.mdx) may prove helpful.
## The test runs but the app looks stuck / test times-out
47
45
48
-
**Issue:** Running tests immediately throws the following error:
46
+
### Issue
49
47
50
-
```js
51
-
beforeEach(async () => {
52
-
^
53
-
SyntaxError: Unexpected token (
54
-
at Object.exports.runInThisContext (vm.js:76:16)
55
-
at Module._compile (module.js:545:28)
56
-
at loader (/Users/builduser/buildAgent/work/34eee2d16ef6c34b/node_modules/babel-register/lib/node.js:144:5)
57
-
at Object.require.extensions.(anonymous function) [as .js] (/Users/builduser/buildAgent/work/34eee2d16ef6c34b/node_modules/babel-register/lib/node.js:154:7)
58
-
...
59
-
child_process.js:531
60
-
throw err;
61
-
```
48
+
-**The test runs and at some point the app gets stuck on the same screen / state until the end of the test** - for example, displaying a loader animation. This can be observed directly if Detox is run locally, or otherwise post-factum by checking Detox's [video recording artifact](https://wix.github.io/Detox/docs/config/artifacts/#enabling-artifacts):
49
+
50
+

51
+
52
+
- Detox logs might also show synchronization warnings, repeatedly. For example:
62
53
63
-
**Solution:** This error means that your version of Node does not support `async-await` syntax. You should do the following:
54
+
```plain text
55
+
19:07:20.140 detox[1907] i The app is busy with the following tasks:
56
+
• UI elements are busy:
57
+
- View animations pending: 2.
58
+
- Layers pending animations: 7.
59
+
- Layers needs layout: 147.
60
+
- View needs layout: 98.
61
+
- View needs display: 67.
62
+
- Layers needs display: 82.
63
+
• 1 enqueued native timers:
64
+
- Timer #1:
65
+
+ Fire date: none.
66
+
+ Time until fire: 0.000.
67
+
+ Repeat interval: 0.
68
+
+ Is recurring: YES.
69
+
• 1 network requests with URLs:
70
+
- URL #1: https://example.org/something?id=1337
71
+
```
64
72
65
-
1. Update Node to a version **8.3.0 or higher**.
73
+
- The test failure reason might be associated with time-outs, or you see time-outs in the _device_ (not Detox) log (available as a Detox [test artifact](https://wix.github.io/Detox/docs/config/artifacts/#enabling-artifacts)).
66
74
67
-
## Can’t Find My Component Even Though I Added a `testID` to Its Props
75
+
### Course of action
68
76
69
-
**Issue:** Detox fails to match a component even though it has a `testID`. Detox will throw the following error:
77
+
This might be related somehow to your test code, but **could definitely stem from a an app bug.** Take an in-depth look at the [synchronization troubleshooting guide](./synchronization.md).
## Detox can't find or interact with an element even though it's on the screen
90
80
91
-
**Solution:** React Native only supports the `testID` prop on the native built-in components. If you’ve created a custom composite component, you will have to support this prop yourself. You should probably propagate the `testID` prop to one of your rendered children (a built-in component):
92
-
93
-
```jsx
94
-
exportclassMyCompositeComponentextendsComponent {
95
-
render() {
96
-
return (
97
-
<TouchableOpacity testID={this.props.testID}>
98
-
<View>
99
-
<Text>Something something</Text>
100
-
</View>
101
-
</TouchableOpacity>
102
-
);
103
-
}
104
-
}
105
-
```
81
+
### Issue
106
82
107
-
Now, adding `testID` to your composite component should work:
1. The test runs, the app starts on the device and is maybe even being successfully navigated-through by the test, onto an inner screen; The app/screen opens properly and you know for sure that your element matcher is spot-on - **yet Detox says the element cannot be found (this can even happen intermittently, in a flaky test).**
86
+
2. The test runs, the app starts and displays a transient UI element (e.g. a Toast) for a limited amount of time and is then removed automatically. For example: A temporary "Success" cheering-effect that fades out to the screen below:
114
87
115
-
## Test Tries to Find My Component Before It’s Created
**Issue:** Due to a synchronization issue, the test tries to perform an expectation and fails because it runs the expectation too soon. Consider this example:
For the 1st option, you'd have to go deeper by exploring the [synchronization troubleshooting guide](./synchronization.md#last-resort-Switching-to-manual-synchronization).
123
93
124
-
In the test above, after tapping the Login button, the app performs several complex asynchronous operations until the Welcome message is displayed post-login. These can include querying a server, waiting for a response and then running an animated transition to the Welcome screen. Detox attempts to simplify your test code by synchronizing _automatically_ with these asynchronous operations. What happens if for some reason the automatic synchronization doesn’t work? As a result, Detox will not wait correctly until the Welcome screen appears and instead will continue immediately to the next line and try to run the expectation. Since the screen is not there yet, the test will fail.
94
+
For the 2nd option, if possible, start by revisiting your matching technique, as explained in the dedicated [matching troubleshooting guide](./element-matching.md). If that doesn't solve it, consider switching to using `waitFor()` --
125
95
126
-
**Solution:** When you suspect that automatic synchronization didn’t work, you have a fail-safe by synchronizing manually with `waitFor`. Using `waitFor` will poll until the expectation is met. This isn’t a recommended approach so please use it as a workaround and open and issue to resolve the synchronization issue.
96
+
#### Switching to the polling-based `waitFor()` API's
127
97
128
-
This is what the fixed test would look like:
98
+
you'd have to resort to Detox's fail-safe `waitFor()` family of API's, which poll your matching criteria within a specified time frame defined by you as a timeout. To take the screen above as an example, you'd have to change your test from:
If you suspect that the test is failing because Detox fails to synchronize the test steps with your app, take a look at this in-depth [synchronization troubleshooting tutorial](synchronization.md).
**On iOS**, you may run in a situation, when one of the interactions (tap, scroll, etc.) on an element fails with an error like:
142
115
@@ -160,48 +133,21 @@ If you are developing a React Native app, then the following applies. If, for in
160
133
161
134
If you see that your issue cannot be solved via testID replacement or a simple hierarchy rearrangement, then there’s a chance this is a bug in Detox. Make sure to provide your `ui.viewhierarchy` artifact, the generated `DETOX_VISIBILITY_*` pictures and a comprehensive description of the issue backed up with sound arguments.
162
135
163
-
## Debug View Hierarchy
164
-
165
-
**Issue:** I added the `testID` prop, but I still can’t find the view by id in my tests.
166
-
167
-
**Solution:** You can investigate the app’s native view hierarchy, this might shed some light on how the app’s view hierarchy is laid out.
168
-
169
-
Do the following:
170
-
171
-
1. Start a debuggable app (not a release build) in your simulator
172
-
1. Open Xcode
173
-
1. Attach Xcode to your app’s process
174
-

This is the hierarchy viewer, pointing to the native view just mentioned:
189
-
190
-

136
+
## Explore More Options
191
137
192
-
## Compare to a Working Setup
138
+
###Compare to a Working Setup
193
139
194
140
If you feel lost, try starting from a working example for sanity.
195
141
196
142
There are multiple working examples included in this repo, such as [demo-react-native](https://github.com/wix/Detox/tree/master/examples/demo-react-native).
197
143
198
144
First, install, build and make sure the tests are indeed passing. If they are, try comparing this setup with what you have.
199
145
200
-
## Take a Look at Past Issues
146
+
###Take a Look at Past Issues
201
147
202
148
Before opening a new issue, search the [list of issues](https://github.com/wix/detox/issues?utf8=%E2%9C%93\&q=is%3Aissue) on GitHub. There’s a good chance somebody faced the same problem you are having.
203
149
204
-
## How to Open a New Issue
150
+
###How to Open a New Issue
205
151
206
152
Before opening a new issue, please follow the entire troubleshooting guide and go over past issues.
0 commit comments