detox
If you have integrated with Detox in the past, you will need to clean your project before integrating with current Detox version.
- Under Frameworks, remove "Detox.framework" from your project.
- In your AppDelegate.m, remove any Detox code, such as calls to
detoxConditionalInit().
Detox uses Node.js for its operation. Node manages dependencies through a file called package.json. You can read more information in the official documentation.
- Install the latest version of
brewfrom here. - If you haven't already, install Node.js by running
brew update && brew install node. - If you do not have a
package.jsonfile in the root folder of your project, create one by runningecho "{}" > package.json.
By default, Xcode uses a randomized hidden path for outputting project build artifacts, called Derived Data. For ease of use, it is recommended to change the project build path to a more convenient path.
- With your project opened in Xcode, select menu
File►Project Settings.... Click on theAdvanced...button, selectCustomand from the drop-down menu, selectRelative to Workspace. - Build artifacts will now be created in a
Buildfolder next to yourxcodeprojproject.
- Add
detoxanddetox-serverto thedevDependenciessection ofpackage.json:- Run
npm install detox --save-dev. - Run
npm install detox-server --save-dev.
- Run
- Add to the
scriptssection ofpackage.json:
"scripts": {
"e2e": "./node_modules/.bin/mocha e2e --opts ./e2e/mocha.opts"
}- Add a
detoxsection topackage.json:
"detox": {
"session": {
"server": "ws://localhost:8099",
"sessionId": "YourProject"
},
"ios-simulator": {
"app": "ios/Build/Products/Debug_Detox-iphonesimulator/YourProject.app",
"device": "iPhone 7, iOS 10.1"
}
}Note: replace
YourProjectabove with your Product name from Xcode. Set theapppath to the correct build path of your.appproduct, relative to thepackage.jsonfile.
- The resulting
package.jsonshould look something like this.
- Make sure your Project schemes are shared. Open you project in Xcode, select menu
Product►Scheme►Manage Schemes..., and check theShared Schemecheckbox next to schemes that are part of the project. There is no need to do this for library schemes. Note the scheme you would like to use Detox with. - In your root folder, run
node_modules/detox/scripts/deploy_detox.rb <Path To>/YourProject.xcodeproj. - Notice the new scheme(s) added in your Xcode project. If you had a
YourProjectscheme before, now there is an analogousYourProject_Detoxscheme.
- Create an
e2efolder in your project root and open it. - Create
mocha.optsfile with this content. - Create
init.jsfile with this content. - Create your first test!
myFirstTest.spec.jswith content similar to this.
- Build your project with a newly created
_Detoxscheme- Building with Xcode
- Select the desired
_Detoxscheme - Build your project
- Select the desired
- Building from command-line
xcodebuild -scheme YourProject_Detox
- Building using React Native
react-native run-ios --scheme YourProject_Detox
- Building with Xcode
- If you have build problems, see troubleshooting.
Note: remember to update the path for
appin yourpackage.json.
- Follow these instructions.
You can add additional schemes to your project normally. After making changes to