Xcode doesn't open the simulator.
````
node_modules/.bin/mocha e2e --opts e2e/mocha.opts
detox-server info 13:04:21: server listening on localhost:54175...
detox info 1: Searching for device matching iPhone 7...
detox info 3: Uninstalling org.reactjs.native.example.WeorderNative...
detox info 3: org.reactjs.native.example.WeorderNative uninstalled
detox info 4: Installing /Users/josz/Projects/weorder-native/ios/build/Build/Products/Debug-iphonesimulator/WeorderNative.app...
detox info 4: /Users/josz/Projects/weorder-native/ios/build/Build/Products/Debug-iphonesimulator/WeorderNative.app installed
detox info 5: Terminating org.reactjs.native.example.WeorderNative...
detox info 5: org.reactjs.native.example.WeorderNative terminated
detox info 6: Launching org.reactjs.native.example.WeorderNative...
detox info 6: org.reactjs.native.example.WeorderNative launched. The stdout and stderr logs were recreated, you can watch them with:
tail -F $HOME/Library/Developer/CoreSimulator/Devices/5B047356-8220-46BF-9ABF-C5E5A3511725/data/tmp/detox.last_launch_app_log.{out,err}
Example
1) should have welcome screen
0 passing (9s)
1 failing
1) Example
should have welcome screen:
Error: Error: Cannot find UI Element.
Exception with Assertion: {
"Assertion Criteria" : "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('welcome')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('welcome')) && kindOfClass('RCTScrollView'))))))",
"Recovery Suggestion" : "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element."
}
Error Trace: [
{
"Description" : "Interaction cannot continue because the desired element was not found.",
"Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code" : "0",
"File Name" : "GREYElementInteraction.m",
"Function Name" : "-[GREYElementInteraction matchedElementsWithTimeout:error:]",
"Line" : "124"
}
]
at Client._callee8$ (node_modules/detox/lib/client/Client.js:57:19)
at tryCatch (node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as throw] (node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
at step (node_modules/detox/lib/client/Client.js:1:809)
at node_modules/detox/lib/client/Client.js:1:1008
``
Simulators open on a headless mode on Xcode 9. If you want to open a window for it, open Simulator.app from spotlight.
Gosh.... It's worked! Thank you, a lot. This is my first step in automated test, so sometimes I feel pretty lost.
It would be very helpful to mention this somewhere. I can add a Pull request but not sure where to best add this.
It seems that if the simulator is launched in headless mode not everything works correctly. At least we have been running into issues when running headless.
What doesn't work for you?
We run Detox test suite on Xcode 9 in headless mode on CI with no issues.
I did not dive in yet to find exactly what is the reason. But in headless I was not able to successfully finish our testsuite. It was not always the same tests that were failing but different ones. And they were actually timing out. When I opened the Simulator after 5 failed runs, the first run succeeded and the other ones from then on too when the Simulator is open.
I get the same issue as @pietropizzi. When I run in headless mode, my second test fails. When simulator is open, it works fine.
Output in headless mode
detox test --configuration ios.sim.debug
node_modules/.bin/mocha e2e --opts e2e/mocha.opts --configuration ios.sim.debug --grep :android: --invert
detox info 13:30:42: server listening on localhost:53451...
detox info 1: Searching for device matching iPhone 7...
detox info 5: Booting device 687BBC11-27AA-49F6-BE1C-A438F6CD7FA7
detox info 7: Uninstalling com.Test.TestRun...
detox info 7: com.Test.TestRun uninstalled
detox info 8: Installing /Users/me/proj/Test/Test-mobile/ios/build/Build/Products/Debug-iphonesimulator/TestDebug.app...
detox info 8: /Users/me/proj/Test/Test-mobile/ios/build/Build/Products/Debug-iphonesimulator/TestDebug.app installed
detox info 9: Terminating com.Test.TestRun...
detox info 9: com.Test.TestRun terminated
detox info 10: Launching com.Test.TestRun...
detox info 10: com.Test.TestRun launched. The stdout and stderr logs were recreated, you can watch them with:
tail -F $HOME/Library/Developer/CoreSimulator/Devices/687BBC11-27AA-49F6-BE1C-A438F6CD7FA7/data/tmp/detox.last_launch_app_log.{out,err}
Logged Out
✓ Should have splash screen (993ms)
1) Should have sign up button that when pressed brings up registration
detox info 11: Terminating com.Test.TestRun...
detox info 11: com.Test.TestRun terminated
1 passing (1m)
1 failing
1) Logged Out
Should have sign up button that when pressed brings up registration:
Error: Error: An assertion failed.
Exception with Assertion: {
"Assertion Criteria" : "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('logged_out/register')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('logged_out/register')) && kindOfClass('RCTScrollView'))))))"
}
Error Trace: [
{
"Description" : "Assertion with matcher [M] failed: UI element [E] failed to match the following matcher(s): [S]",
"Description Glossary" : {
"M" : "matcherForSufficientlyVisible(>=0.750000)",
"E" : "<RCTView:0x7fc0aed9e670; AX=N; AX.id='logged_out/register'; AX.label=' Add
Photo  Enter your first and last name Enter your email 🇺🇸 + 1 Enter your phone number Create Account By signing up, you agree to our Terms and Privacy Policy. '; AX.frame={{0, 0}, {375, 667}}; AX.activationPoint={187.5, 333.5}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {375, 667}}; opaque; alpha=1>",
"S" : "matcherForSufficientlyVisible(>=0.750000)"
},
"Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code" : "3",
"File Name" : "GREYAssertions.m",
"Function Name" : "+[GREYAssertions grey_createAssertionWithMatcher:]_block_invoke",
"Line" : "75"
}
]
at Client.execute (node_modules/detox/src/client/Client.js:72:13)
at <anonymous>
child_process.js:644
throw err;
^
Error: Command failed: node_modules/.bin/mocha e2e --opts e2e/mocha.opts --configuration ios.sim.debug --grep :android: --invert
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at runMocha (/Users/me/proj/Test/Test-mobile/node_modules/detox/local-cli/detox-test.js:105:6)
at run (/Users/me/proj/Test/Test-mobile/node_modules/detox/local-cli/detox-test.js:66:7)
at Object.<anonymous> (/Users/me/proj/Test/Test-mobile/node_modules/detox/local-cli/detox-test.js:56:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
error Command failed with exit code 1.
const {device, expect, element, by} = require('detox');
describe('Logged Out', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
//Always passes
it('Should have splash screen', async () => {
await expect(element(by.id('logged_out/splash'))).toBeVisible();
});
//Fails in headless mode:
it('Should have sign up button that when pressed brings up registration', async () => {
await element(by.id('signup-btn')).tap();
await expect(element(by.id('logged_out/register'))).toBeVisible();
});
it('Should have login button that when pressed brings up login', async () => {
await element(by.id('login-btn')).tap();
await expect(element(by.id('logged_out/login'))).toBeVisible();
});
});
Most helpful comment
Simulators open on a headless mode on Xcode 9. If you want to open a window for it, open
Simulator.appfrom spotlight.