Native Technologies

Unlocking New Possibilities with Maestro: Beyond Automated Testing

Introduction

You've probably heard of Maestro —a powerful tool for automated testing that seamlessly operates on both Android and iOS platforms. It's open-source and stands out as one of the most reliable testing tools in its class. But, have you ever considered utilizing Maestro for more than just running tests?

Personally, I turn to Maestro when I need to check the integration of approximate developments on my device. Manually repeating the same user interactions within your application for validation purposes can be time-consuming and tedious. While there are better and robust alternatives like unit tests, integration tests, previews and snapshots, there are scenarios where these might not be the ideal choice. In such cases, using Maestro to interactively verify your developments by launching the application and allowing maestro to navigate deeply within it can be a game-changer.

Before we dive into the subject, it's worth mentioning that a powerful deep-link launch with ADB can achieve similar results in some cases.

Using Maestro for application development checking in the deepest screen of your app

Utilizing Maestro for testing your application's deep functionalities follows the same principle as using it for automated testing. If you're new to creating Maestro flows, don't worry; it's quite straightforward, and the documentation on their website is well-detailed —especially for beginners. Additionally, Maestro Studio makes the process even more user-friendly.

Let's explore a simple use case: navigating through various screens of an application, assuming the user is already logged in, this will be simpler for your initial scenario.

Now, launching this Maestro flow is a very simple, leading me directly to the gallery – the deep part of my app where I need to assess the behavior I've recently coded. A simple command ++code>maestro test pathOfMyFile/nameOfMyFile.yaml++/code> does the trick. However, to minimize time wastage, let's explore how to execute it instantly.

Swiftly Launching Your Maestro flow

Launching your Maestro flow can be done in several ways, and I'll outline three options and share my personal favorite

Option 1: Automator Quick Actions and Shortcuts

Are you familiar with Automator and Shortcuts applications? If you are, you have the capability to create a service that launches your preferred Maestro flow. Mac users with a Touch Bar can even add a dedicated button for quick access. For those without the Touch Bar, you can conveniently place the shortcut in the top bar of your screen.

Option 2: Use a Keyboard Shortcut with Raycast

Raycast is a productivity-boosting tool that many find indispensable. Creating a script and linking it to a keyboard shortcut is straightforward with Raycast. Moreover, you can print a toaster on your screen, similar to Android toasts, using the ++code>echo++/code> command within your script. It can notify you when the script has finished, for instance. This is my preferred method, but I have one more option to share.

Option 3: Use a Custom Gradle Task (Android Developers Only)

For Android developers, you can create a custom Gradle task to install the app on your device and run the Maestro flow with a single click (or a keyboard shortcut). Here's an example Gradle code snippet:

Simply add this code to the ++code>build.gradle++/code> file at the root of your project.

Please note that you might need to add the ++code>--no-configuration-cache++/code> parameter when running the task if you encounter any issues.

iOS developers, unfortunately, will have to explore the other two solutions or find their own.

Exploring Other Potential Uses

Data Set Creation

If generating test data through server API calls appears complex, Maestro can be an excellent tool for automating data creation within your app.

Replicating Elusive Bugs

Reproducing intermittent bugs can be a challenging task. However, Maestro can be your savior in such situations. By automating the user interactions that trigger the bug and allowing Maestro to replay them until the issue surfaces, you can gain better insights into the problem. Additionally, Maestro can help maintain consistency when testing on multiple devices, making it an invaluable asset in your quality assurance toolkit.

Going further with ADB

At the 2023 Droidcon in Berlin, Benjamin Kadel presented an alternative using ADB and uiAutomator2 to cover the same purpose. If you don’t know him, subscribe to his YouTube channel; he's a wonderful speaker and YouTuber. ADB has the advantage of executing faster, but flows will be harder to write, and they will be less reliable if you change the device.

Q&A

Is Maestro Worth Using in Your Daily Workflow if You're Not Testing with It Yet?

For your Maestro flows to maintain reliability, it's essential to include unique IDs for your views. Without them, Maestro may struggle to execute correctly on different device configurations, such as varying screen sizes or languages.

When you're just beginning to integrate Maestro into your workflow, you may not notice an immediate surge in your development experience. However, its benefits accumulate over time as you continuously refine your work methods.

In conclusion, even if you haven't been using Maestro for testing, it's still highly beneficial to incorporate it into your daily routine. The advantages it brings to your development process make it a valuable tool for improving efficiency and reliability.

What Can You Accomplish During Maestro's Execution?

While Maestro is running, you have the opportunity to multitask and make the most of your time.

  • You can catch up on your messages
  • You can check your schedule
  • You can take a step back on your day: reflect on your accomplishments, challenges, and plan your next steps.

Be careful, while it's tempting to handle short tasks during Maestro's execution, be cautious not to lose focus on your development work.

Don't Wait to Incorporate Maestro into Your Daily Workflow

In conclusion, while Maestro excels at automated testing, its versatility extends beyond that. It can significantly enhance your development workflow by streamlining the testing of deep application features and automating repetitive tasks. How much time will you save ? It's challenging to quantify the precise amount of time you'll save, it depends on the nature of your tasks The best way to find out is by trying it yourself.

With multiple options available to swiftly launch your Maestro flows, integrating it into your development toolkit is a wise decision. Take the leap and unlock Maestro's full potential in your application development journey. You'll be surprised by the efficiency and productivity gains it brings to your daily work.

Développeur mobile ?

Rejoins nos équipes