-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf01014
commit f18813b
Showing
10 changed files
with
1,054 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
id: version-7.X-APIRef.DetoxCLI | ||
title: Detox Command Line Tools (detox-cli) | ||
original_id: APIRef.DetoxCLI | ||
--- | ||
|
||
`detox-cli` lets you operate Detox from command line. | ||
|
||
## Installation | ||
Install `detox-cli` globally via npm: | ||
|
||
```sh | ||
npm install -g detox-cli | ||
``` | ||
|
||
## Usage | ||
```sh | ||
detox [options] [command] | ||
``` | ||
|
||
## Commands: | ||
| Command | Description | | ||
| --- | --- | | ||
| [test](#test) | Initiating your test suite | | ||
| [build](#build) | Run the command defined in `configuration.build` | | ||
| [run-server](#run-server) | Starts a standalone detox server | | ||
| [init](#init) | Create initial e2e tests folder | | ||
| clean-framework-cache | Delete all compiled framework binaries from ~/Library/Detox, they will be rebuilt on 'npm install' or when running 'build-framework-cache' | ||
| build-framework-cache | Build Detox.framework to ~/Library/Detox. The framework cache is specific for each combination of Xcode and Detox versions | ||
| [help](#help) | Display help for specific command | | ||
|
||
## Options: | ||
|
||
| Options | Description | | ||
| --- | --- | | ||
| -h<br>--help | Output usage information | | ||
|
||
## Commands | ||
|
||
### test | ||
Initiating your test suite | ||
|
||
`detox test [options]` | ||
|
||
|
||
|
||
| Option| Description | | ||
| --- | --- | | ||
| -h, --help | output usage information | | ||
| -o, --runner-config \<config\> | Test runner config file, defaults to 'e2e/mocha.opts' for mocha and 'e2e/config.json' for jest | | ||
| -l, --loglevel [value] | info, debug, verbose, silly, wss | | ||
| -c, -configuration \<device config\> | Select a device configuration from your defined configurations,if not supplied, and there's only one configuration, detox will default to it | | ||
| -r, --reuse | Reuse existing installed app (do not delete and re-tall) for a faster run. | | ||
| -u, --cleanup | Shutdown simulator when test is over, useful for CI ipts, to make sure detox exists cleanly with no residue | | ||
| -d, --debug-synchronization \<value\> | When an action/expectation takes a significant amount time use this option to print device synchronization status. The status will be printed if the ion takes more than [value]ms to complete | | ||
| -a, --artifacts-location \<path\> | Artifacts destination path (currently contains only logs). For more details, please check the [Artifacts doc](APIRef.Artifacts.md#artifacts) | | ||
|-p, --platform [ios/android] | Run platform specific tests. Runs tests with invert grep on `:platform:`, e.g test with substring `:ios:` in its name will not run when passing `--platform android` | ||
|                  || | ||
|
||
|
||
|
||
### build | ||
Run a command defined in 'configuration.build' | ||
|
||
`detox build <command> [options]` | ||
|
||
| Option | Description | | ||
| --- | --- | | ||
| -h, --help | output usage information | | ||
| -c, --configuration \<device config\> | Select a device configuration from your defined configurations,if not supplied, and there's only one configuration, detox will default to it | | ||
|                  || | ||
|
||
|
||
### run-server | ||
Start a standalone detox server | ||
|
||
`detox run-server [options]` | ||
|
||
| Option | Description | | ||
| --- | --- | | ||
| -h, --help | output usage information | | ||
|
||
|
||
### init | ||
Create initial e2e tests folder | ||
|
||
`detox init [options` | ||
|
||
| Option | Description | | ||
| --- | --- | | ||
| -h, --help | output usage information | | ||
| -r, --runner | Test runner (currently supports only `mocha`) | | ||
|
||
### help | ||
Display help for a command | ||
|
||
`detox help [command]` | ||
|
76 changes: 76 additions & 0 deletions
76
website/versioned_docs/version-7.X/APIRef.DetoxObjectAPI.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
id: version-7.X-APIRef.DetoxObjectAPI | ||
title: The `detox` Object | ||
original_id: APIRef.DetoxObjectAPI | ||
--- | ||
|
||
`detox` is globally available in every test file, though currently it is only used in the setup/init file. | ||
|
||
>NOTE: detox is test runner independent, and we encourge you to choose your own test runner, but for the sake of demonstration we will use `mocha`'s syntax. | ||
### Methods | ||
|
||
- [`detox.init()`](#detox.init) | ||
- [`detox.cleanup()`](#detox.cleanup) | ||
|
||
### `detox.init()` | ||
The setup phase happens inside `detox.init()`. This is the phase where detox reads its configuration, starts a server, loads its expection library and starts a simulator. | ||
|
||
##### (if you're using mocha) In your `init.js` add: | ||
|
||
```js | ||
const config = require('../package.json').detox; | ||
|
||
before(async () => { | ||
await detox.init(config); | ||
}); | ||
``` | ||
|
||
##### Explicit imports during initialization | ||
Detox exports `device `, `expect`, `element`, `by` and `waitFor` as globals by default, if you want to control their initialization manually, set init detox with `initGlobals` set to `false`. This is useful when during E2E tests you also need to run regular expectations in node. jest `Expect` for instance, will not be overriden by Detox when this option is used. | ||
|
||
```js | ||
before(async () => { | ||
await detox.init(config, {initGlobals: false}); | ||
}); | ||
``` | ||
|
||
Then import them manually: | ||
|
||
```js | ||
const {device, expect, element, by, waitFor} = require('detox'); | ||
``` | ||
|
||
Use [this example](../examples/demo-react-native/e2eExplicitRequire) for initial setup | ||
|
||
|
||
|
||
#### Controlling first app intialization | ||
By default `await detox.init(config);` will launch the installed app. If you wish to control when your app is launched, add `{launchApp: false}` param to your init. | ||
|
||
```js | ||
const config = require('../package.json').detox; | ||
|
||
before(async () => { | ||
await detox.init(config, {launchApp: false}); | ||
}); | ||
``` | ||
|
||
>NOTE: Detox 6.X.X introduced a **breaking change** , setting `launchApp` to `false` by default. In order to prevent any breaking changes to your tests when you upgrade (and if you still would like `init` to launch the app for you) do the following: | ||
```js | ||
before(async () => { | ||
await detox.init(config, {launchApp: true}); | ||
}); | ||
``` | ||
|
||
### `detox.cleanup()` | ||
The cleanup phase should happen after all the tests have finished. This is the phase where detox-server shuts down. The simulator will also shut itself down if `--cleanup` flag is added to `detox test` | ||
|
||
##### (if you're using mocha) In your `init.js` add: | ||
|
||
```js | ||
after(async () => { | ||
await detox.cleanup(); | ||
}); | ||
``` |
220 changes: 220 additions & 0 deletions
220
website/versioned_docs/version-7.X/APIRef.DeviceObjectAPI.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
--- | ||
id: version-7.X-APIRef.DeviceObjectAPI | ||
title: The `device` Object | ||
original_id: APIRef.DeviceObjectAPI | ||
--- | ||
|
||
`device` is globally available in every test file, it enables control over the current attached device (currently only simulators are supported). | ||
|
||
### Methods | ||
|
||
- [`device.launchApp()`](#devicelaunchappparams) | ||
- [`device.relaunchApp()` **Deprecated**](#devicerelaunchappparams) | ||
- [`device.terminateApp()`](#deviceterminateapp) | ||
- [`device.reloadReactNative()`](#devicereloadreactnative) | ||
- [`device.sendToHome()`](#devicesendtohome) | ||
- [`device.installApp()`](#deviceinstallapp) | ||
- [`device.uninstallApp()`](#deviceuninstallapp) | ||
- [`device.openURL(url)`](#deviceopenurlurl-sourceappoptional) | ||
- [`device.sendUserNotification(params)`](#devicesendusernotificationparams) | ||
- [`device.setOrientation(orientation)`](#devicesetorientationorientation) | ||
- [`device.setLocation(lat, lon)`](#devicesetlocationlat-lon) | ||
- [`device.setURLBlacklist([urls])`](#deviceseturlblacklisturls) | ||
- [`device.enableSynchronization()`](#deviceenablesynchronization) | ||
- [`device.disableSynchronization()`](#devicedisablesynchronization) | ||
- [`device.resetContentAndSettings()`](#deviceresetcontentandsettings) | ||
- [`device.getPlatform()`](#devicegetplatform) | ||
|
||
### `device.launchApp(params)` | ||
Launch the app defined in the current [`configuration`](APIRef.Configuration.md). | ||
|
||
**Options:** | ||
|
||
##### 1. Restart the app | ||
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` | ||
|
||
```js | ||
await device.launchApp({newInstance: true}); | ||
``` | ||
|
||
##### 2. Set runtime permissions | ||
Grant or deny runtime permissions for your application. | ||
|
||
```js | ||
await device.launchApp({permissions: {calendar: 'YES'}}); | ||
``` | ||
Detox uses [AppleSimUtils](https://github.com/wix/AppleSimulatorUtils) 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](../detox/test/e2e/l-permissions.js) | ||
|
||
##### 3. Launch from URL | ||
Mock opening the app from URL to test your app's deep link handling mechanism. | ||
|
||
```js | ||
await device.launchApp({url: url}); | ||
``` | ||
###### Mock opening from a URL when app is not running | ||
```js | ||
await device.launchApp({url: url, newInstance: true}); | ||
``` | ||
This will launch a new instance of the app and handle the deep link. | ||
|
||
###### Mock opening from a URL when app is in background | ||
|
||
```js | ||
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](APIRef.MockingOpenFromURL.md) section. | ||
|
||
##### 4. Launch from user notifications | ||
|
||
```js | ||
await device.launchApp({userNotification: notification}); | ||
``` | ||
|
||
###### Mock receiving a notifications when app is not running | ||
```js | ||
await device.launchApp({userNotification: notification, newInstance: true}); | ||
``` | ||
This will launch a new instance of the app and handle the notification. | ||
|
||
###### Mock receiving a notifications when app is in background | ||
|
||
```js | ||
await device.launchApp({userNotification: notification, newInstance: false}); | ||
``` | ||
This will launch the app from background and handle the notification. | ||
|
||
Read more in [Mocking User Notifications](APIRef.MockingUserNotifications.md) section. | ||
|
||
##### 5. Launch into a fresh installation | ||
A flag that enables relaunching into a fresh installation of the app (it will uninstall and install the binary again), default is `false`. | ||
|
||
```js | ||
await device.launchApp({delete: true}); | ||
``` | ||
|
||
##### 6. Additional launch arguments | ||
Detox can start the app with additional launch arguments | ||
|
||
```js | ||
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]` | ||
|
||
### `device.relaunchApp(params)` | ||
**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.<Br> | ||
Kill and relaunch the app defined in the current [`configuration`](APIRef.Configuration.md). | ||
|
||
### `device.terminateApp()` | ||
By default, `terminateApp()` with no params will terminate the app file defined in the current [`configuration`](APIRef.Configuration.md). | ||
|
||
To terminate another app, specify its bundle id | ||
|
||
```js | ||
await device.terminateApp('other.bundle.id'); | ||
``` | ||
|
||
### `device.sendToHome()` | ||
Send application to background by bringing `com.apple.springboard` to the foreground.<br> | ||
Combining `sendToHome()` with `launchApp({newInstance: false})` will simulate app coming back from background.<br> | ||
Check out Detox's [own test suite](../detox/test/e2e/f-simulator.js) | ||
|
||
```js | ||
await device.sendToHome(); | ||
await device.launchApp({newInstance: false}); | ||
// app returned from background, do stuff | ||
``` | ||
Check out Detox's [own test suite](../detox/test/e2e/f-device.js) | ||
|
||
### `device.reloadReactNative()` | ||
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. | ||
|
||
### `device.installApp()` | ||
By default, `installApp()` with no params will install the app file defined in the current [`configuration`](APIRef.Configuration.md). | ||
|
||
To install another app, specify its path | ||
|
||
```js | ||
await device.installApp('path/to/other/app'); | ||
``` | ||
|
||
### `device.uninstallApp()` | ||
By default, `uninstallApp()` with no params will uninstall the app defined in the current [`configuration`](APIRef.Configuration.md). | ||
|
||
To uninstall another app, specify its bundle id | ||
|
||
```js | ||
await device.installApp('other.bundle.id'); | ||
``` | ||
|
||
### `device.openURL({url, sourceApp[optional]})` | ||
Mock opening the app from URL. `sourceApp` is an optional parameter to specify source application bundle id.<br> | ||
Read more in [Mocking Open From URL](APIRef.MockingOpenFromURL.md) section.<br> | ||
Check out Detox's [own test suite](../detox/test/e2e/n-deep-links.js) | ||
|
||
### `device.sendUserNotification(params)` | ||
Mock handling of received user notification when app is in foreground.<br> | ||
Read more in [Mocking User Notifications](APIRef.MockingUserNotifications.md) section.<br> | ||
Check out Detox's [own test suite](../detox/test/e2e/k-user-notifications.js) | ||
|
||
### `device.setOrientation(orientation)` | ||
Takes `"portrait"` or `"landscape"` and rotates the device to the given orientation. | ||
Currently only available in the iOS Simulator.<br> | ||
Check out Detox's [own test suite](../detox/test/e2e/f-device.js) | ||
|
||
### `device.setLocation(lat, lon)` | ||
>Note: `setLocation` is dependent on `fbsimctl`. if `fbsimctl` is not installed, the command will fail, asking for it to be installed. | ||
Sets the simulator location to the given latitude and longitude. | ||
```js | ||
await device.setLocation(32.0853, 34.7818); | ||
``` | ||
|
||
### `device.setURLBlacklist([urls])` | ||
|
||
Disable [EarlGrey's network synchronization mechanism](https://github.com/google/EarlGrey/blob/master/docs/api.md#network) on preffered endpoints. Usful if you want to on skip over synchronizing on certain URLs. | ||
|
||
```js | ||
await device.setURLBlacklist(['.*127.0.0.1.*']); | ||
``` | ||
|
||
```js | ||
await device.setURLBlacklist(['.*my.ignored.endpoint.*']); | ||
``` | ||
|
||
### `device.enableSynchronization()` | ||
Enable [EarlGrey's synchronization mechanism](https://github.com/google/EarlGrey/blob/master/docs/api.md#synchronization | ||
) (enabled by default). **This is being reset on every new instance of the app.** | ||
```js | ||
await device.enableSynchronization(); | ||
``` | ||
|
||
|
||
### `device.disableSynchronization()` | ||
Disable [EarlGrey's synchronization mechanism](https://github.com/google/EarlGrey/blob/master/docs/api.md#synchronization | ||
) (enabled by default) **This is being reset on every new instance of the app.** | ||
|
||
```js | ||
await device.disableSynchronization(); | ||
``` | ||
|
||
|
||
### `device.resetContentAndSettings()` | ||
Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing | ||
previously set permissions. | ||
|
||
```js | ||
await device.resetContentAndSettings(); | ||
``` | ||
|
||
### `device.getPlatform()` | ||
Returns the current device, `ios` or `android`. | ||
|
||
```js | ||
if (device.getPlatform() === 'ios') { | ||
await expect(loopSwitch).toHaveValue('1'); | ||
} | ||
``` |
Oops, something went wrong.