### Install and Start Local Docs Server Source: https://github.com/wix/detox/blob/master/docs/contributing/documentation.md Navigate to the website directory and run these commands to install dependencies and start a local development server for the documentation. ```bash cd website npm install npm start ``` -------------------------------- ### Example Java Version Output Source: https://github.com/wix/detox/blob/master/docs/guide/android-dev-env.md An example of the expected output when checking the Java version, confirming a valid installation. ```text java version "17.x.x" ... ``` -------------------------------- ### Jest Configuration Example Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Example of a Jest configuration file, demonstrating how to set up global setup, teardown, and reporters. ```javascript module.exports = async function () { return { globalSetup: '/path/to/globalSetup.js', globalTeardown: '/path/to/globalTeardown.js', reporters: ['/path/to/reporter.js'], /* ... jest config ... */ }; }; ``` -------------------------------- ### Custom Global Setup Wrapper Source: https://github.com/wix/detox/blob/master/docs/guide/migration.md Example of how to wrap a custom globalSetup function with Detox's globalSetup to ensure both are executed. ```javascript module.exports = async () => { await require('detox/runners/jest/index').globalSetup(); await yourGlobalSetupFunction(); }; ``` -------------------------------- ### Jest Global Setup Handler Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Example of a Jest global setup handler. This function is executed in the main process before tests begin. ```javascript module.exports = async function () { // ... global setup code ... }; ``` -------------------------------- ### Run Detox Start with Default Configuration Source: https://github.com/wix/detox/blob/master/docs/cli/start.md Use this command when you have only one configuration defined in your Detox setup. Detox will automatically use it. ```bash detox start ``` -------------------------------- ### detox start Source: https://github.com/wix/detox/blob/master/docs/cli/start.md The `detox start` command initiates the `start` command of the app(s) from the specified configuration. It allows for customization through various options. ```APIDOC ## detox start ### Description Runs the [`start` command](../config/apps.mdx#properties) of the app (or apps) from the specified [configuration](../config/overview.mdx#config-structure). ### Method CLI Command ### Endpoint N/A (CLI Command) ### Parameters #### Query Parameters - **-C, --config-path** (string) - Optional - Specify Detox config file path. If not supplied, Detox searches for .detoxrc[.js] or "detox" section in package.json. - **-c, --configuration** (string) - Optional - Select a local configuration from your defined configurations to extract the app "start" scripts from it. If not supplied, and there’s only one configuration, Detox will default to it. - **-f, --force** - Optional - Ignore errors from the "start" scripts and continue. - **--help** - Optional - Show help ### Request Example ```bash detox start detox start --configuration yourConfiguration detox start -c yourConfiguration detox start -c yourConfiguration -- --port 8082 detox start -c yourConfiguration --force ``` ### Response #### Success Response (0) - **stdout** (string) - Output from the app start scripts. - **stderr** (string) - Error output from the app start scripts. #### Response Example (Output will vary based on app and configuration) ``` -------------------------------- ### Module Exports Example Source: https://github.com/wix/detox/blob/master/docs/guide/migration.md Example of exporting the new driver and allocation classes. ```javascript module.exports = { DeviceAllocationDriverClass: PuppeteerDeviceAllocation, EnvironmentValidatorClass: PuppeteerEnvironmentValidator, ArtifactPluginsProviderClass: PuppeteerArtifactPluginsProvider, RuntimeDriverClass: PuppeteerRuntimeDriver }; ``` -------------------------------- ### Install Dummy Package with npm Source: https://github.com/wix/detox/blob/master/docs/demo.mdx Use this command to install the 'dummy_package' with npm. It saves the package as a dependency. ```bash npm install "dummy_package" --save ``` -------------------------------- ### Travis CI Configuration for Detox Source: https://github.com/wix/detox/blob/master/docs/introduction/preparing-for-ci.md This is a sample `.travis.yml` file for setting up Detox on Travis CI. It includes environment setup, dependency installation, and Detox build/test commands. ```yaml language: objective-c osx_image: xcode8.3 branches: only: - master env: global: - NODE_VERSION=stable install: - brew tap wix/brew - brew install applesimutils - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash - export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - nvm install $NODE_VERSION - nvm use $NODE_VERSION - nvm alias default $NODE_VERSION - npm install react-native-cli --global - npm install detox-cli --global script: - detox build --configuration ios.sim.release - detox test --configuration ios.sim.release --cleanup ``` -------------------------------- ### Detox YAML Configuration Example Source: https://github.com/wix/detox/blob/master/docs/demo.mdx A YAML snippet demonstrating Detox actions, such as installing examples and managing dependencies. Comments in YAML can provide additional context or explanations for configuration settings. ```yaml actions: - dummy install example - push_dummytext: "*" - dummy install example --save global # Lorem ipsum dolor sit amet, consectetur SampleCo is using ($DUMMY/lorem-text) ``` -------------------------------- ### Detox Configuration Example Source: https://github.com/wix/detox/blob/master/docs/architecture/artifacts.md Example configuration for Detox artifacts, including root directory, path builder, and plugin settings. ```javascript module.exports = { artifacts: { rootDir: 'artifacts', pathBuilder: undefined, // or custom path builder plugins: { screenshot: { enabled: true, shouldTakeAutomaticSnapshots: true, keepOnlyFailedTestsArtifacts: true, }, video: { enabled: true, keepOnlyFailedTestsArtifacts: true, }, log: { enabled: true, keepOnlyFailedTestsArtifacts: false, }, instruments: { enabled: false, }, uiHierarchy: { enabled: true, keepOnlyFailedTestsArtifacts: true, }, }, }, }; ``` -------------------------------- ### iOS Simulator Device Query Example Source: https://github.com/wix/detox/blob/master/docs/config/devices.mdx Example of a device query for an iOS simulator using 'byType'. ```json { "byType": "iPhone 11 Pro" } ``` -------------------------------- ### device.installApp() Source: https://github.com/wix/detox/blob/master/docs/api/device.md Installs the currently configured app or a specified app using its file path. ```APIDOC ## `device.installApp()` ### Description Installs the currently configured app. If a file path is provided, it installs the specified app. ### Method `installApp(appPath?: string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript await device.installApp('path/to/other/app'); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Logging Examples Source: https://github.com/wix/detox/blob/master/docs/api/logger.mdx Examples demonstrating how to use the Detox Logger API for different logging scenarios. ```javascript const { log } = require('detox'); // Logging a simple info message log.info('Some message'); // Logging an error with metadata log.error({ err: new Error('Test') }, 'An error message'); // Starting and ending a duration event log.info.begin({ data: { email: 'tester@example.com' } }, 'Login Flow'); // ... perform login actions ... log.info.end(); // Using complete to wrap an async function await log.info.complete('Login Flow', async () => { // ... perform login actions ... }); // Logging with event category log.info({ cat: 'login,login-email' }, 'Starting e-mail login flow...'); // Logging concurrent events with IDs await Promise.all([ await detox.log.complete({ id: 1 }, 'Do this', async () => { /* ... */ }), await detox.log.complete({ id: 2 }, 'Do that', async () => { /* ... */ }), ]); ``` -------------------------------- ### Custom Global Setup Function Source: https://github.com/wix/detox/blob/master/docs/config/testRunner.mdx Extend the Detox global setup by wrapping the default `detox/runners/jest` global setup function with your own setup logic. ```javascript module.exports = async () => { await require('detox/runners/jest').globalSetup(); await yourGlobalSetupFunction(); }; ``` -------------------------------- ### Report Test Suite Start Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Reports that a test suite execution has begun. Requires an installed worker. Use this for hooks like beforeAll or the first test in a suite. ```javascript await onRunDescribeStart({ name: 'Suite name' }); ``` -------------------------------- ### Run Detox Start with Specific Configuration Source: https://github.com/wix/detox/blob/master/docs/cli/start.md Specify a particular configuration to use for starting the app. This is useful when you have multiple configurations defined. You can use either the long or short alias for the --configuration option. ```bash # long alias: detox start --configuration yourConfiguration # short alias: detox start -c yourConfiguration ``` -------------------------------- ### Example: Handle URL Successfully on Launch - Detox Source: https://github.com/wix/detox/blob/master/docs/guide/mocking-open-with-url.md This example demonstrates a test case for handling a deep link successfully upon app launch. It asserts that a specific UI element becomes visible after the app is launched with a URL. ```javascript describe('launch app from URL', () => { it('should handle URL successfully', async () => { await device.launchApp({ newInstance: true, url: 'scheme://some.url', sourceApp: 'com.apple.mobilesafari' }); await expect(element(by.text('a label'))).toBeVisible(); }); }); ``` -------------------------------- ### Install xcpretty for Xcodebuild Formatting Source: https://github.com/wix/detox/blob/master/docs/contributing/code/setting-up-the-dev-environment.md Install xcpretty, a formatter for xcodebuild output, using RubyGems. This improves the readability of build logs. ```bash gem install xcpretty ``` -------------------------------- ### Android Emulator Device Query Example Source: https://github.com/wix/detox/blob/master/docs/config/devices.mdx Example of a device query for an Android emulator using 'avdName'. ```json { "avdName": "Pixel_2_API_29" } ``` -------------------------------- ### Install Detox Source: https://github.com/wix/detox/blob/master/docs/introduction/partials/_project-setup-bootstrap-rn.mdx Installs Detox as a development dependency in your project. ```bash npm install detox --save-dev ``` -------------------------------- ### Install Emulator Component Source: https://github.com/wix/detox/blob/master/docs/guide/android-dev-env.md Upgrades the emulator executable to the latest version. This is a preliminary step before installing emulator images. ```shell $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install emulator ``` -------------------------------- ### Install TypeScript and Initialize tsconfig.json Source: https://github.com/wix/detox/blob/master/docs/guide/typescript.md Install TypeScript as a development dependency and generate a default tsconfig.json file. This is a prerequisite for using TypeScript in your project. ```bash npm install --save-dev typescript tsc --init ``` -------------------------------- ### Start React Native Packager Source: https://github.com/wix/detox/blob/master/examples/demo-react-native-detox-instruments/README.md Before running tests for the debug build, start the React Native packager using this command. ```sh npm run start ``` -------------------------------- ### Install a specific app Source: https://github.com/wix/detox/blob/master/docs/api/device.md Use `installApp` with a file path to install an application other than the one currently configured. This allows for testing with different app versions or external applications. ```javascript await device.installApp('path/to/other/app'); ``` -------------------------------- ### Detox Test Command Example Source: https://github.com/wix/detox/blob/master/docs/cli/test.md Example of using detox test with a configuration and a showConfig flag, which is then translated to environment variables for the test runner. ```bash detox test -c ios.debug --showConfig ``` -------------------------------- ### Run Detox Start and Forward Arguments Source: https://github.com/wix/detox/blob/master/docs/cli/start.md Forward additional arguments to the app's 'start' script. Use '--' to separate Detox arguments from arguments intended for the script. ```bash detox start -c yourConfiguration -- --port 8082 ``` -------------------------------- ### Install Watchman using Homebrew Source: https://github.com/wix/detox/blob/master/docs/contributing/code/setting-up-the-dev-environment.md Install Watchman, a file watching service developed by Facebook, using Homebrew. This tool is essential for monitoring filesystem changes. ```bash brew install watchman ``` -------------------------------- ### Jest Environment Setup for Detox Source: https://github.com/wix/detox/blob/master/ARCHITECTURE.md Illustrates the structure of the Jest test runner integration, including environment setup and global hooks. ```text runners/ ├── jest/ │ ├── testEnvironment/ # Jest environment setup │ ├── reporters/ # Custom reporters │ ├── globalSetup.js │ └── globalTeardown.js ├── jest-circus/ # Circus event handling └── mocha/ # Mocha adapter ``` -------------------------------- ### Run Detox Server Source: https://github.com/wix/detox/blob/master/docs/cli/overview.md Starts a standalone Detox server. ```bash detox run-server ``` -------------------------------- ### Install Monorepo Dependencies with Yarn Source: https://github.com/wix/detox/blob/master/docs/contributing/code/setting-up-the-dev-environment.md Install all project dependencies for the monorepo using Yarn. This command should be run after cloning the repository. ```bash yarn install ``` -------------------------------- ### Install Detox CLI Globally Source: https://github.com/wix/detox/blob/master/docs/cli/overview.md Install the Detox CLI globally using npm. This command makes the detox command available system-wide. ```bash npm install detox-cli --global ``` -------------------------------- ### Custom logger.options Example Source: https://github.com/wix/detox/blob/master/docs/config/logger.mdx This example demonstrates how to correctly set custom functions for `logger.options`, such as `showDate`. Custom functions must not use closures as they are re-evaluated in child worker processes. ```javascript const dontDoThis = date => date.toISOString(); module.exports = { logger: { level: 'debug', options: { // showDate: (date) => dontDoThis(date), // highlight-next-line showDate: (date) => date.toISOString(), /* do this instead */ }, }, // ... }; ``` -------------------------------- ### Start Detox Server Source: https://github.com/wix/detox/blob/master/docs/cli/run-server.md Starts a standalone Detox server. Useful for contributing to the native codebase. Options include specifying the port and log level. ```bash detox run-server [options] ``` -------------------------------- ### delete Source: https://github.com/wix/detox/blob/master/docs/api/device.md Uninstalls and then reinstalls the application before launching. This method is slower than `resetAppState` but guarantees a completely fresh installation. ```APIDOC ## `delete`—Delete and Reinstall Application Before Launching Uninstalls the app and then reinstalls it before launching. Slower than `resetAppState`, but guarantees a completely fresh install of the app and all its data. ```js await device.launchApp({delete: true}); ``` ``` -------------------------------- ### Detox Synchronization Warnings Example Source: https://github.com/wix/detox/blob/master/docs/troubleshooting/running-tests.md Example log output indicating that the app is busy with various tasks, such as animations or network requests. This can lead to test timeouts if not resolved. ```plaintext 19:07:20.140 detox[1907] i The app is busy with the following tasks: • UI elements are busy: - View animations pending: 2. - Layers pending animations: 7. - Layers needs layout: 147. - View needs layout: 98. - View needs display: 67. - Layers needs display: 82. • 1 enqueued native timers: - Timer #1: + Fire date: none. + Time until fire: 0.000. + Repeat interval: 0. + Is recurring: YES. • 1 network requests with URLs: - URL #1: https://example.org/something?id=1337 ``` -------------------------------- ### Install Jest for React Native Source: https://github.com/wix/detox/blob/master/docs/introduction/partials/_project-setup-bootstrap-rn.mdx Installs the latest supported Jest version. Use this command to ensure compatibility and avoid outdated versions that might be restricted by package lock files. ```bash npm install "jest@^29" --save-dev ``` -------------------------------- ### Report Test Start Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Reports that a specific test is starting execution. Requires an installed worker. Use the 'invocations' property when a test is being re-run. ```javascript await onTestStart({ title: 'should do something expected', fullName: 'Suite name should do something expected', invocations: 1, status: 'running', }); ``` -------------------------------- ### Detox Event-Driven Architecture Example Source: https://github.com/wix/detox/blob/master/ARCHITECTURE.md Demonstrates the use of event emitters in ArtifactsManager and RuntimeDevice for loose coupling. ```javascript deviceEmitter.on('bootDevice', this.onBootDevice.bind(this)); deviceEmitter.on('launchApp', this.onLaunchApp.bind(this)); ``` -------------------------------- ### Initialize Detox and Launch App with BeforeAll Hook Source: https://github.com/wix/detox/blob/master/docs/guide/cucumber-js-integration.md Use the `BeforeAll` hook to initialize Detox and launch the application. Ensure the timeout is sufficient for app startup. ```javascript BeforeAll({ timeout: 120 * 1000 }, async () => { await detox.init() await device.launchApp() }) ``` -------------------------------- ### Example of a module to be mocked Source: https://github.com/wix/detox/blob/master/docs/guide/mocking.md This is the original module that will be replaced by its mock version during tests. Ensure it's imported by other parts of your application. ```javascript // src/config.js export const SERVER_URL = 'https://production.mycompany.name/api'; export const FETCH_TIMEOUT = 60000; ``` -------------------------------- ### Initialize Detox Project Source: https://github.com/wix/detox/blob/master/docs/cli/init.md Run this command in your project's root directory to create template files for Detox configuration and a starter test suite. This includes `.detoxrc.js`, `e2e/jest.config.js`, and `e2e/starter.test.js`. ```bash detox init ``` -------------------------------- ### Initialize package.json Source: https://github.com/wix/detox/blob/master/docs/introduction/partials/_project-setup-bootstrap-other.mdx Run this command in your project's root directory to create a package.json file if one does not already exist. This file manages project dependencies and scripts. ```bash npm init -y ``` -------------------------------- ### Test Failure Output Example Source: https://github.com/wix/detox/blob/master/docs/introduction/your-first-test.mdx This output shows a common test failure where an element is not found. Examine the error message and consult the troubleshooting and debugging guides for resolution. ```text FAIL e2e/starter.test.js (25.916 s) Example ✕ should have welcome screen (662 ms) ✕ should show hello screen after tap (236 ms) ✕ should show world screen after tap (236 ms) ● Example › should have welcome screen Test Failed: No elements found for “MATCHER(id == “welcome”)" HINT: To print view hierarchy on failed actions/matches, use log-level verbose or higher. 9 | 10 | it('should have welcome screen', async () => { > 11 | await expect(element(by.id('welcome'))).toBeVisible(); | ^ 12 | }); 13 | 14 | it('should show hello screen after tap', async () => { at Object.toBeVisible (e2e/starter.test.js:11:45) ``` -------------------------------- ### Basic Detox Configuration Structure Source: https://github.com/wix/detox/blob/master/docs/config/overview.mdx Defines the fundamental structure of a Detox configuration file, including sections for devices, apps, and configurations. Use this as a starting point for your Detox setup. ```javascript /* @type {Detox.DetoxConfig} */ module.exports = { // highlight-next-line devices: { device1: { /* ... */ }, device2: { /* ... */ }, }, // highlight-next-line apps: { app1: { /* ... */ }, app2: { /* ... */ }, }, // highlight-next-line configurations: { 'device1+app1': { device: 'device1', app: 'app1', }, /* ... */ }, }; ``` -------------------------------- ### Configure Jest Setup Timeout Source: https://github.com/wix/detox/blob/master/docs/config/testRunner.mdx Set the maximum time allowed for Detox to boot the device and install apps before the test suite is considered failed. The default is 120000ms (2 minutes). ```plain text FAIL e2e/starter.test.js ● Test suite failed to run Exceeded timeout of 120000ms while setting up Detox environment ``` -------------------------------- ### Android Network Security Config for Detox Source: https://github.com/wix/detox/blob/master/docs/troubleshooting/running-tests.md This section in the setup guide discusses enabling unencrypted traffic for Detox on Android. It's crucial for SDK versions 28 and above to ensure the app can connect to the Detox test server. ```plaintext DetoxTest.java ``` -------------------------------- ### List Available Simulators with simctl Source: https://github.com/wix/detox/blob/master/docs/troubleshooting/running-tests.md Use this command to list all installed simulator images on your machine. Ensure the simulator name matches your Detox configuration. ```bash xcrun simctl list ``` -------------------------------- ### Run Detox Build with Default Configuration Source: https://github.com/wix/detox/blob/master/docs/cli/build.md Use this command when you have only one app configuration defined. Detox will automatically use it. ```bash detox build ``` -------------------------------- ### Install applesimutils via Homebrew Source: https://github.com/wix/detox/blob/master/docs/introduction/environment-setup.md Install the applesimutils tool, which is required by Detox to work with iOS simulators. This is the recommended installation method for macOS users. ```bash brew tap wix/brew brew install applesimutils ``` -------------------------------- ### init Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Initializes the Detox context. This method handles configuration resolution, logger and IPC server startup, and worker installation if applicable. ```APIDOC ## init([options]) [Promise] ### Description This is the phase where: * a primary Detox context resolves its configuration, starts the logger, IPC server, and more; * a secondary Detox context connects to IPC server and registers itself; * if `workerId` is not null, installs the worker; Accepts an optional parameter, `options` object with the following properties, _all optional_ as well: * `cwd` (string) – current working directory, used to resolve Detox config. * `argv` (key-value map) – **Internal!**. CLI arguments parsed by Detox CLI. * `testRunnerArgv` (key-value map) – CLI arguments to be forwarded to the test runner. * `override` (Partial) – ad-hoc adjustments to deep merge with the file-based config. * `global` – reference to a custom [global][node globals] scope, usually needed when your test runner [uses sandboxing][node vm]. This prevents creating issues when a Detox context cannot be accessed from within the sandboxed environment. * `workerId` – (string | null) a unique ID, e.g. `worker-1`, `worker-2`. Giving `null` disables installing the worker. ### Method POST ### Endpoint /init ``` -------------------------------- ### Uninstall Detox CLI Globally Source: https://github.com/wix/detox/blob/master/docs/guide/uninstalling.md Removes the globally installed Detox CLI wrapper. This command should be run if you installed Detox CLI using `npm install detox-cli --global`. ```bash npm uninstall detox-cli --global ``` -------------------------------- ### Delete and Reinstall App Before Launch Source: https://github.com/wix/detox/blob/master/docs/api/device.md Uninstalls and then reinstalls the app before launching, ensuring a completely fresh state. This is slower than `resetAppState`. ```javascript await device.launchApp({delete: true}); ``` -------------------------------- ### Launch App with New Instance in beforeEach Source: https://github.com/wix/detox/blob/master/docs/introduction/your-first-test.mdx Launches a fresh instance of the application before each test. This ensures a clean state for every test, improving stability. ```javascript beforeEach(async () => { await device.launchApp({ newInstance: true }); }); ``` -------------------------------- ### Detox Initialization Output Source: https://github.com/wix/detox/blob/master/docs/introduction/project-setup.mdx This is the typical output observed after running the `detox init` command, indicating the creation of configuration and test files. ```plain text Created a file at path: .detoxrc.js Created a file at path: e2e/jest.config.js Created a file at path: e2e/starter.test.js ``` -------------------------------- ### Connect to Server and Login Source: https://github.com/wix/detox/blob/master/docs/architecture/client-server.md Establishes a connection to the Detox server and logs into a session. Ensure the client is initialized before calling. ```javascript await client.connect(); ``` -------------------------------- ### Install iOS Pods for Detox Source: https://github.com/wix/detox/blob/master/examples/demo-react-native/README.md Installs the necessary pods for Detox on iOS. This command should be run from the detox directory. ```sh cd detox npm run podInstall:ios ``` -------------------------------- ### Start Metro bundler with custom source extensions Source: https://github.com/wix/detox/blob/master/docs/guide/mocking.md Run the Metro bundler with the `--sourceExts` flag to include your custom mock extension. This tells Metro to prefer files with your mock extension when resolving modules. ```bash npx react-native start --sourceExts mock.js,js,json,ts,tsx ``` -------------------------------- ### DetoxServer Constructor and Open Method Source: https://github.com/wix/detox/blob/master/docs/architecture/client-server.md Initializes the DetoxServer with a port and a flag for standalone mode, and starts listening for incoming WebSocket connections. ```javascript class DetoxServer { constructor({ port, standalone }) { this._sessionManager = new DetoxSessionManager(); this._wss = new WebSocket.Server({ port }); } async open() { // Start listening } _onConnection(ws, req) { this._sessionManager.registerConnection(ws, req.socket); } } ``` -------------------------------- ### device.appLaunchArgs Source: https://github.com/wix/detox/blob/master/docs/api/device.md Provides access to modify and retrieve launch arguments predefined by the user. Supports transient and shared arguments for multi-app environments. ```APIDOC ## device.appLaunchArgs ### Description Access the launch-arguments predefined by the user in preliminary, static scopes such as the Detox [configuration file](../config/apps.mdx) and [command-line arguments](../cli/test.md). This access allows, through dedicated methods, for both value-querying and modification: ```js // Modify some of the predefined arguments: device.appLaunchArgs.modify({ mockServerPort: 1234, }); // Retrieve the arguments: device.appLaunchArgs.get(); // ==> { mockServerPort: 1234 } // Reset (i.e. remove all arguments): device.appLaunchArgs.reset(); ``` In multi-app environments, you might want to persist your values between `device.selectApp(name)` calls: ```js device.appLaunchArgs.modify({ transientArg: 'value' }); device.appLaunchArgs.shared.modify({ permanentMockServerPort: 1234, }; device.appLaunchArgs.get(); // ==> { permanentMockServerPort: 1234, transientArg: 'value' } device.appLaunchArgs.shared.get(); // ==> { permanentMockServerPort: 1234 } await device.selectApp('anotherApp'); device.appLaunchArgs.get(); // ==> { permanentMockServerPort: 1234 } device.appLaunchArgs.reset(); device.appLaunchArgs.get(); // ==> { permanentMockServerPort: 1234 } device.appLaunchArgs.shared.reset(); device.appLaunchArgs.get(); // ==> {} device.appLaunchArgs.shared.get(); // ==> {} ``` This is the most flexible way of editing the launch arguments. Refer to the [launch arguments guide](../guide/launch-args.md) for complete details. ``` -------------------------------- ### Android Force ADB Install Configuration Source: https://github.com/wix/detox/blob/master/docs/config/devices.mdx Configuration to force ADB installation for Android devices. Defaults to false. ```json { "forceAdbInstall": true } ``` -------------------------------- ### Install Detox Worker Source: https://github.com/wix/detox/blob/master/docs/api/internals.mdx Loads Detox's expectation library and boots a device. Use this when overriding init with workerId: null. Accepts optional global scope or worker ID. ```javascript await installWorker({ global: customGlobal, workerId: 'worker-1' }); ``` -------------------------------- ### Configure Emulator Quick-Boot via Command-Line Source: https://github.com/wix/detox/blob/master/docs/guide/android-dev-env.md Modify the AVD's config.ini file to enable quick-boot functionality. Ensure fastboot.forceFastBoot is set to 'yes' and fastboot.forceColdBoot is set to 'no'. ```ini fastboot.chosenSnapshotFile= fastboot.forceChosenSnapshotBoot=no fastboot.forceColdBoot=no fastboot.forceFastBoot=yes ``` -------------------------------- ### Full WebView Interaction Example Source: https://github.com/wix/detox/blob/master/docs/guide/testing-webviews.md A complete test case demonstrating login interaction within a WebView. It includes asserting initial state, filling form fields, tapping a button, and verifying the final state. ```javascript it('should login successfully', async () => { // Assert the welcome message is not visible before login await expect(web.element(by.web.id('welcome_message'))).not.toExist(); // Fill username and password await web.element(by.web.id('username')).typeText('John Doe'); await web.element(by.web.id('password')).typeText('123456789'); // Press the login button await web.element(by.web.id('login')).tap(); // Assert the login was successful await expect(web.element(by.web.id('welcome_message'))).toHaveText('Welcome, John Doe!'); }); ``` -------------------------------- ### Run Detox Build with Specific Configuration Source: https://github.com/wix/detox/blob/master/docs/cli/build.md Specify a particular app configuration to build when multiple configurations are available. Replace 'yourConfiguration' with the actual name of your configuration. ```bash detox build --configuration yourConfiguration ``` -------------------------------- ### Clone Detox Repository and Initialize Submodules Source: https://github.com/wix/detox/blob/master/docs/contributing/code/setting-up-the-dev-environment.md Clone the Detox repository and initialize its submodules to get the complete project structure. Navigate into the cloned directory afterwards. ```bash git clone git@github.com:wix/Detox.git cd Detox git submodule update --init --recursive ``` -------------------------------- ### Attached Android Device Query Example Source: https://github.com/wix/detox/blob/master/docs/config/devices.mdx Example of a device query for an attached Android device using 'adbName' with a regex pattern. ```json { "adbName": "" } ``` -------------------------------- ### Start Metro Server for Debug Mode Source: https://github.com/wix/detox/blob/master/examples/demo-react-native/README.md Starts the Metro server, which is required for running the project in debug mode. This bundles JavaScript code on-the-fly. ```sh npm start ``` -------------------------------- ### Add Manual Launch Configuration to Detox Config Source: https://github.com/wix/detox/blob/master/docs/introduction/debugging.mdx Configure the 'behavior' section to 'launchApp': 'manual' for manual app launching. Optional parameters like 'session', 'testRunner', and 'artifacts' can be added for enhanced debugging and control. ```json { … "configurations": { "": { … "behavior": { "launchApp": "manual" }, "session": { "autoStart": true, "debugSynchronization": 0, "server": "ws://localhost:8099", "sessionId": "test" }, "testRunner": { "args": { "testTimeout": 999999 } } "artifacts": false }, } } ``` -------------------------------- ### Install Jest TypeScript Dependencies Source: https://github.com/wix/detox/blob/master/docs/guide/typescript.md Install necessary packages for Jest to work seamlessly with TypeScript. This includes ts-jest and type definitions for Jest and Node. ```bash npm install --save-dev ts-jest @types/jest @types/node ``` -------------------------------- ### Example Detox Test Runner Configuration Source: https://github.com/wix/detox/blob/master/docs/config/testRunner.mdx This JSON configuration sets up the test runner command, including the executable, boolean flags, configuration file path, and default positional arguments. ```json { "testRunner": { "args": { "$0": "nyc jest", "bail": true, "config": "e2e/jest.config.js", "_": ["e2e/sanity-tests"] } } } ``` -------------------------------- ### Boot Verbose Emulator in GUI System Source: https://github.com/wix/detox/blob/master/docs/guide/android-dev-env.md Command to boot an emulator with verbose logging enabled in a GUI-supporting environment. Assumes emulator name is Pixel_API_28_AOSP. ```bash $ANDROID_HOME/emulator/emulator -verbose @Pixel_API_28_AOSP & ``` -------------------------------- ### Install Jest Test Runner Source: https://github.com/wix/detox/blob/master/docs/introduction/partials/_project-setup-bootstrap-other.mdx Install Jest as a development dependency. Jest is a popular JavaScript testing framework that integrates well with Detox for running your end-to-end tests. ```bash npm install jest --save-dev ``` -------------------------------- ### Conventional Commits Format Examples Source: https://github.com/wix/detox/blob/master/docs/contributing/code/submitting-pull-requests.md Examples of commit messages following the Conventional Commits format. Use this format to specify the type of change, scope, and a concise description. ```plaintext fix(ios): resolve crash on scrolling in iOS 17.0 ``` ```plaintext feat(android): add new API for setting the device locale ``` ```plaintext test: update unit tests for new utility function ``` -------------------------------- ### Start React Native Packager Source: https://github.com/wix/detox/blob/master/docs/guide/developing-while-writing-tests.md Manually start the React Native packager if it's not already running. This allows the simulator to reload JavaScript bundle changes when CMD+R is pressed. ```bash npx react-native start ``` -------------------------------- ### Perform Testing Steps with Wix Pilot Source: https://github.com/wix/detox/blob/master/docs/api/pilot.md Executes a series of natural language instructions for testing. Each step is a string describing an action or assertion. ```javascript await pilot.perform( 'Start the application', 'Tap on the "Login" button', 'Enter "user@example.com" into the email field', 'Enter "password123" into the password field', 'Press the "Submit" button', 'The welcome message "Hello, User!" should be displayed' ); ``` -------------------------------- ### Install React Native CLI Globally Source: https://github.com/wix/detox/blob/master/docs/contributing/code/setting-up-the-dev-environment.md Install the React Native command line interface globally using npm. This tool is required for managing React Native projects. ```bash npm install react-native-cli --global ``` -------------------------------- ### Initialize Pilot with PromptHandler Source: https://github.com/wix/detox/blob/master/docs/pilot/testing-with-pilot.md Initializes Pilot with a configured PromptHandler, typically within a `beforeAll` hook or a setup file before running tests. ```javascript const {pilot} = require('detox/index'); const OpenAIPromptHandler = require('./OpenAIPromptHandler'); beforeAll(() => { const promptHandler = new OpenAIPromptHandler('YOUR_OPENAI_API_KEY'); pilot.init(promptHandler); }); ``` -------------------------------- ### Run Detox Start and Ignore Script Errors Source: https://github.com/wix/detox/blob/master/docs/cli/start.md Use the --force option to ignore any errors encountered during the execution of the app's 'start' scripts and continue the Detox process. ```bash detox start -c yourConfiguration --force ``` -------------------------------- ### Set Custom Detox Instruments Path Source: https://github.com/wix/detox/blob/master/docs/troubleshooting/artifacts.md Use the DETOX_INSTRUMENTS_PATH environment variable to point Detox to a custom installation of Detox Instruments. This is useful if Detox Instruments is not installed in the default location. ```bash DETOX_INSTRUMENTS_PATH="/path/to/Detox Instruments.app" detox test ... ``` -------------------------------- ### Initialize URL Blacklist at App Launch (Legacy String) Source: https://github.com/wix/detox/blob/master/docs/api/device.md Launches the app with a URL blacklist using the legacy string format. This format is sensitive to its structure. ```javascript await device.launchApp({ newInstance: true, launchArgs: { detoxURLBlacklistRegex: '\("^http://192\.168\.1\.253:\d{4}/.*","https://e\.crashlytics\.com/spi/v2/events"\)' }, }); ``` -------------------------------- ### Detox JSON Configuration Example Source: https://github.com/wix/detox/blob/master/docs/demo.mdx An example of a JSON configuration object for Detox, specifying items with properties and a file path. This structure is common for defining test targets and their associated properties. ```json { "items": { "object1": { "property1": "dummy_type", "property2": "dummy_device", // highlight-next-line "property3": ["dummy_path/to/dummy_file.dummy"] } } } ``` -------------------------------- ### List Installed Android Virtual Devices Source: https://github.com/wix/detox/blob/master/docs/introduction/partials/_project-setup-devices-android.mdx Run this command in your terminal to see a list of all installed Android Virtual Devices (AVDs) on your system. Ensure your ANDROID_SDK_ROOT or ANDROID_HOME environment variables are set. ```bash emulator -list-avds ``` ```bash $ANDROID_SDK_ROOT/emulator/emulator -list-avds ``` ```bash %ANDROID_HOME%\emulator\emulator -list-avds ``` -------------------------------- ### Version Documentation Source: https://github.com/wix/detox/blob/master/docs/contributing/documentation.md Use this command to version the documentation for a specific release after removing the version from `versions.json`. ```bash npm run docusaurus docs:version ```