Gray Box UI Open Source Automation Framework: Detox
For a variety of reasons, automated mobile app testing has always been difficult: tests are inconsistent, we get different results depending on the device we test the app on, and we have to deal with system warnings and pop-ups informing us of system upgrades or permissions. All of this leads to the conclusion that it is more expensive to maintain tests than it is to write them.
I explored automated testing tools when I first started a new project. At the time, I was working on a React Native mobile app, and the first thing I did was research how other specialists test these types of apps. Detox seemed to be fairly trendy, and many people suggested it, so I decided to give it a try.
I would like to share everything I have learned about the tool in the following article. I will concentrate on explaining how detoxworks, how to configure it, how to write tests, and what challenges I've encountered while using detox for a mobile app.
There are three types of automated tests:
- Unit Testing: They are used to prevent unexpected code changes and to ensure that functions perform as expected.
- Integration tests are in charge of ensuring that code parts and APIs are properly connected. From a technical standpoint, they test the application components as a whole.
End-to-End (E2E) tests: They enable testing of the application as a whole, in its execution environment, just as a human does.So, I have one use case that describes the End-to-End testing in detox. In our product-based company, we have a mobile app called "GlideInvest" where the user has logged in and wants to navigate through the tabs .Steps are as follows:
- Splash Screen- By Launching the app, Splash screen will get displayed.
- Login into the app using proper credentials.
- Navigate through Tabs below when user is logged into the system: Home --> Goals --> Funds --> Learn --> Profile
Why Grey Box testing?
Gray box testing is a software testing technique used to test a software product or application with only a partial understanding of its internal structure. Grey box testing seeks and identifies defects caused by incorrect code structure or application use.
Detox, as a Gray Box test framework, is capable of both White and Black Box testing.
Black Box test frameworks allow us to take control of an execution context (a browser, software, mobile apps, etc.) and send control commands to it.
How does Detox work?
Detox is an end-to-end testing framework. This implies that it runs your software on a real device/simulator and interacts with it in the same way that a real user would. This kind of testing can boost your app's confidence and help you automate a manual QA procedure.
When a Detox test runs, it actually has two portions operating at the same time:
- The actual mobile app is normally run on a simulator or emulator. On the device, a typical native build of your app is installed and running. Before the tests begin, your app is normally built once.
Detox comprises the following components:
- Tester: The testing component that executes the test logic while running in a Node.js process on the host computer. The tester is also responsible for device management and artefact collection.
- Detox native client (iOS and Android): A component that is seamlessly integrated into the tested app on the tested device as soon as Detox begins to execute. It syncs with the app, matches user queries, executes user commands (such as taps and scrolls), and validates expectations.
- Detox mediator server: A small web socket server running on the host computer in a Node.js process that connects the tester and the client. Normally, the tester launches a server with a randomised session id and an open port, then passes the session and port to the client app as a launch argument.
In the next blog, I will be explaining the installation and setup in detail for the Detox framework.