
Behavior Driven Mobile Testing
Ido Cohen
CEO
When it comes to testing mobile applications it becomes harder to build and execute with traditional tools that focus on UI. There are a lot of moving parts, usually, it requires coding, involves a lot of maintenance, and often suffers from instability, but it doesn't have to be like that.
In this article, I will show you how to capture the behavior of your mobile application and turn it into end-to-end API-driven flows in a fun way and with a fraction of the effort compared to other methods out there.
Mobile testing is hard
- Slow - Mobile testing tools don't excel in speed, simulating user interaction usually comes with overhead.
- Flaky - Behavior and UI often change and break tests that rely on specific elements or flows that were changed.
- Expensive - Traditional mobile testing will occupy expensive devices for a long time and will require more resources to maintain and analyze them.
- Hard to maintain - It is difficult to get to the root cause of mobile tests failures, they're hard to debug and contain multiple moving parts.
- Higher entry barrier - Most of the tools out there will require coding, deploying new frameworks, and getting to know and use them.
- Impossible with rich graphic applications - Dynamic applications with progressive animations or continuous state (ie. Games, Navigation, Imaging, etc.) are almost impossible to automate due to their chaotic nature.
Introducing Mobile integration testing
Testing the behavior of applications without falling into the noted pitfalls can be easily achieved with end-to-end API testing. APIs by nature are fast, stable, reliable, seldom break and now easy to build, maintain and don't require coding. In the next section we will see exactly how to build our first test out of any mobile application.
Generating tests from user behavior on any/your mobile app - high level
Setup diagram
This is how our setup will look like on a high level
General steps
The following steps will be required to accomplish your first test:
- *Setup an android application on android emulator device on your machine (Mac)
- *Setup proxy engine (Proxyman)
- Capture user behavior
- Generating automated tests with Loadmill
* Required only for the initial setup
1. Setup android application using the Android emulator
Download Android Studio
Make sure you install the right version for your chipset. There's no need to create a project through the initial screen.
Create a new android device
Open the device manager (AVD) - In android studio, select More-actions -> 'Virtual Device Manager'
Click on "Create Device" and select one without the "Play store" logo, then select next.
Select api level 32 and click next. Note that arm64 ABI images are optimized for mac silicon.
Click on "Show advanced settings" and ensure setting enough Internal storage. Click on finish.
Start the newly added device from the device manager (this is the only time we will start it from the device manager, next times we will use a cli command)
Install android application
Get an apk file of your android application, alternatively you can try downloading any app from APKMirror. Install it by dragging the downloaded APK into the running device emulator screen.
2. Setting proxy (Proxyman)
Environment setup
- Make sure you have OpenSSL installed on your mac by running "openssl version"
- Make sure you have access to the Android Debug Bridge from your terminal (adb version)
- Make sure that you can access the emulator cli from your terminal (emulator version)
Installing Proxyman
Download Proxyman & install it. Set Proxyman to use only the external proxy.
Preparing the certificate
Proxyman creates a custom SSL certificate to be able to decrypt the app requests. Open http://proxy.man/ssl and download the certificate. Rename the file using the command shown in the tutorial.
Deploying the certificate into the device
Execute the terminal commands to deploy the certificate to the Android device system trust store.
Validating the certificate on the device
Navigate to settings -> Security -> Encryption & Credentials -> Trusted Credentials. If all went well you will find "Proxyman LLC" certificate under the "System" tab.
Configuring Proxyman as the proxy on your device
In Proxyman navigate to "Certificate -> Install Certificate on Android -> Physical Devices..."
Copy the IP and port for the next steps.
In your device, navigate to your current wifi settings and configure the proxy.
3. Capturing user behavior
Starting the device
Start your device with: emulator -avd <avd_name_here> -writable-system
Inserting URL(s) into SSL Proxying list
Tell ProxyMan what traffic to decrypt by going to "Tools" -> "SSL Proxying List".
Starting capturing traffic
In ProxyMan make sure you see the 'pause' sign in the top left corner (it means it is turned on). In your emulator device, open the app.
Once 'driving' the application you should see requests being captured. Note the SSL unlocked sign, it means your requests are being decrypted by ProxyMan.
Exporting traffic data
Export the entire set as HAR file: right click on the domain and select Export -> as HAR (HTTP Archive)
4. Generating automated tests with Loadmill
Go to Loadmill and import the HAR file. In Loadmill test designer, navigate to your suite and click on 'import flow'.
Loadmill creates a new API flow from your traffic with automatic parameterization and chaining of all parameters - done with zero effort.
Now you can run your flow and enhance it further. To get the most out of your tests, head to Loadmill documentation.
Try Loadmill's Droid CUA
Turn Jira stories, epics, and plain-English requirements into executable flows across web and mobile platforms.
Download now