LET’S DETOX

What is Detox?

--

Detox — a peculiar name. A quick google search on Detox gives you this:

But that’s not what we are here to talk about.

Here, we talk about the Javascript End-to-End App Testing and Automation framework created and maintained by Wix. It can be built into the test application so that the test execution begins with the app launch.

In this article we’ll take a look at app automation with Detox, why it is a strong contender to traditional app automation frameworks like Appium and its pros and cons.

We’ll also have a brief look into the prerequisites needed and a sample test case.

Is this article relevant to you?

If you are a QA tester looking at options to automate your mobile app, or even an app developer looking to write automation scripts for the app you are building, this article is for you!

We have Appium, so why Detox?

Our search for an alternative app test automation framework began due to the flakiness of Appium like false failures and failure to locate page objects on time.

Appium is a black box testing tool with no access to the code it is testing because of which we need to add sleep statements. This makes it slow and flaky.

On the contrary, the Detox philosophy is “Gray Box Testing”, where it knows about the internals of the test product. This is what makes it a strong contender to Appium and the main reason we decided to explore it for the myCRM app automation.

What makes Gray box testing tools like Detox better than Appium?

  • More stable scripts
    Gray box testing tools like Detox synchronises with the test app and can monitor the network requests, JS threads, timers and page loads. This eliminates the need for “sleep” statements and makes the test more stable.
  • Faster scripts
    Gray box testing tools are 5–10 times faster than black box testing tools.
  • Access to app code
    Detox can access the code and data of the app, eliminating the need for writing additional code to do so.

What are the highlights of Detox?

Source: https://wix.github.io/Detox/

Sounds too good to be true, doesn’t it?

Detox is not without its limitations. Some of which are listed below:

  • No real device testing support for IOS,
  • Not a large online community for support which is so important,
  • It does not support Web views and Hybrid,
  • It’s capabilities are not as wide as Appium.

What are the prerequisites to run Detox?

  1. Homebrew: Homebrew is an open source software package management system that simplifies the installation of software on the macOS.
  2. Node.js 8.3.0 or above: Node.js is a JavaScript runtime environment Detox will run on.
  3. Applesimutils: This is a collection of utils for the Apple simulator
  4. Detox command line tools.

What does a Detox test look like?

This is a sample Login code snippet:

As seen above the syntax is easily readable. We can easily write synchronous tests using await/async statements that:

  • Keep track of all network requests that are currently in-flight and wait until they complete,
  • Keep track of pending animations and wait until they complete,
  • Keep track of timers and wait until they expire or are cancelled,
  • Keep track of the React Native operations.

Open the simulator and run the test script:

Summary

In summary, Detox is a handy tool for app test automation considering the speed and stability of the execution of tests. However, the lack of online support is currently the biggest detriment to its adoption.

We are still in the early stages of implementing it in our project and will have a better idea of its capabilities as we proceed.

You can read up further about Detox as follows: https://reactnativetesting.io/e2e/setup/

https://github.com/wix/Detox

--

--