device
is globally available in every test file, it enables control over the current attached device (currently only simulators are supported).
device.launchApp()
device.relaunchApp()
Deprecateddevice.terminateApp()
device.reloadReactNative()
device.sendToHome()
device.installApp()
device.uninstallApp()
device.openURL(url)
device.sendUserNotification(params)
device.setOrientation(orientation)
device.setLocation(lat, lon)
device.setURLBlacklist([urls])
device.enableSynchronization()
device.disableSynchronization()
device.resetContentAndSettings()
device.getPlatform()
Launch the app defined in the current configuration
.
Options:
Terminate the app and launch it again.
If set to false
, the simulator will try to bring app from background, if the app isn't running, it will launch a new instance. default is false
await device.launchApp({newInstance: true});
Grant or deny runtime permissions for your application.
await device.launchApp({permissions: {calendar: 'YES'}});
Detox uses AppleSimUtils on iOS to support this functionality. Read about the different types of permissions and how to set them in AppleSimUtils' Readme. Check out Detox's own test suite
Mock opening the app from URL to test your app's deep link handling mechanism.
await device.launchApp({url: url});
await device.launchApp({url: url, newInstance: true});
This will launch a new instance of the app and handle the deep link.
await device.launchApp({url: url, newInstance: false});
This will launch the app from background and handle the deep link.
Read more in Mocking Open From URL section.
await device.launchApp({userNotification: notification});
await device.launchApp({userNotification: notification, newInstance: true});
This will launch a new instance of the app and handle the notification.
await device.launchApp({userNotification: notification, newInstance: false});
This will launch the app from background and handle the notification.
Read more in Mocking User Notifications section.
A flag that enables relaunching into a fresh installation of the app (it will uninstall and install the binary again), default is false
.
await device.launchApp({delete: true});
Detox can start the app with additional launch arguments
await device.launchApp({launchArgs: {arg1: 1, arg2: "2"}});
The added launchArgs
will be passed through the launch command to the device and be accessible via [[NSProcessInfo processInfo] arguments]
Deprecated Use device.launchApp(params)
instead. This method is now calling launchApp({newInstance: true})
for backwards compatibility, it will be removed in Detox 6.X.X.
Kill and relaunch the app defined in the current configuration
.
By default, terminateApp()
with no params will terminate the app file defined in the current configuration
.
To terminate another app, specify its bundle id
await device.terminateApp('other.bundle.id');
Send application to background by bringing com.apple.springboard
to the foreground.
Combining sendToHome()
with launchApp({newInstance: false})
will simulate app coming back from background.
Check out Detox's own test suite
await device.sendToHome();
await device.launchApp({newInstance: false});
// app returned from background, do stuff
Check out Detox's own test suite
If this is a react native app, reload react native JS bundle. This action is much faster than device.relaunchApp()
, and is recommended if you just need to reset your react native logic.
By default, installApp()
with no params will install the app file defined in the current configuration
.
To install another app, specify its path
await device.installApp('path/to/other/app');
By default, uninstallApp()
with no params will uninstall the app defined in the current configuration
.
To uninstall another app, specify its bundle id
await device.installApp('other.bundle.id');
Mock opening the app from URL. sourceApp
is an optional parameter to specify source application bundle id.
Read more in Mocking Open From URL section.
Check out Detox's own test suite
Mock handling of received user notification when app is in foreground.
Read more in Mocking User Notifications section.
Check out Detox's own test suite
Takes "portrait"
or "landscape"
and rotates the device to the given orientation.
Currently only available in the iOS Simulator.
Check out Detox's own test suite
Note:
setLocation
is dependent onfbsimctl
. iffbsimctl
is not installed, the command will fail, asking for it to be installed. Sets the simulator location to the given latitude and longitude.
await device.setLocation(32.0853, 34.7818);
Disable EarlGrey's network synchronization mechanism on preffered endpoints. Usful if you want to on skip over synchronizing on certain URLs.
await device.setURLBlacklist(['.*127.0.0.1.*']);
await device.setURLBlacklist(['.*my.ignored.endpoint.*']);
Enable EarlGrey's synchronization mechanism (enabled by default). This is being reset on every new instance of the app.
await device.enableSynchronization();
Disable EarlGrey's synchronization mechanism (enabled by default) This is being reset on every new instance of the app.
await device.disableSynchronization();
Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing previously set permissions.
await device.resetContentAndSettings();
Returns the current device, ios
or android
.
if (device.getPlatform() === 'ios') {
await expect(loopSwitch).toHaveValue('1');
}