Cellular UI automation with out programming wisdom — Maestro | through Arkadiusz Jakubas | Dec, 2023

Arkadiusz Jakubas

In recent times, I’ve been searching for a device that may rapidly automate UI assessments for a couple of identical Android programs. The factors for the device had been fast configuration, strengthen for hybrid programs, and simplicity of use. I got here throughout a moderately new device — Maestro — that stuck my consideration, and I in the end made up our minds to combine it into our venture. On this article, I’ll percentage the information and reviews I’ve collected, demonstrating tips on how to set up the device, write and execute preliminary assessments, and support those assessments for progressed maintainability.

What’s Maestro

Maestro is designed for developing end-to-end UI assessments on cellular, providing compatibility with each Android and iOS platforms. On Android, checking out is conceivable on each bodily units and emulators, whilst on iOS, it lately helps simulators best. The core idea revolves round “flows,” representing consumer trips.

Assessments are written in YAML recordsdata and interpreted; there is not any wish to collect the rest. Consumer depends on predefined Maestro instructions (reminiscent of tapOn, assertVisible, scroll), getting rid of the wish to know any programming language. Due to this fact, customers best wish to familiarize themselves with the record of instructions and the device’s rules.

Key facets

The issues I actually experience about this device come with:

  • just right dealing with of delays, flakiness and context adjustments (internet/local) — each local and internet components within the utility are instantly visual and able for interplay,
  • speedy and easy setup — only one command in terminal,
  • ease of use — it’s somewhat clean to be informed this device,
  • pass platform — assessments may also be simply reused on each platforms,
  • flexibility — Maestro has get entry to now not best to the appliance however mainly the whole lot it sees at the telephone display. This permits, as an example, amendment of telephone settings or interplay with the gadget bar,
  • easy integration with CI — all interactions with Maestro are performed the usage of instructions within the terminal.

Set up procedure

Set up is an overly speedy procedure. Maestro is a unmarried binary document that may be put in with one command within the terminal:

curl -Ls "https://get.maestro.cellular.dev" | bash

And that’s it, Maestro is able to use, with none advanced configurations and many others.

There is not any want for any complicated IDE both; assessments may also be written even in a easy textual content editor. Then again, I’d counsel a minimum of a device that gives syntax highlighting, and shows the folder construction on your comfort all the way through construction.

To be had instructions

Sooner than writing first check, right here’s a snappy evaluate of probably the most very important instructions to come up with an concept of what it seems like:

Fundamental Maestro instructions

In fact, the record of supported movements is a lot more in depth and may also be discovered within the Maestro documentation.

Discovering selectors

Maestro framework additionally provides the chances to check up on selectors with which we will be able to have interaction. There is not any wish to set up any third-party equipment.

  • Maestro Studio — UI assistant, which permits to view selectors, suggests conceivable instructions, and gives the chance to take a look at them out. There’s easy terminal command to run it:
maestro studio
Maestro Studio
  • Selectors hierarchy — command to show the hierarchy of all components within the terminal.
maestro hierarchy
Hierarchy in terminal

Writing first check

After all — you already know the instructions, you know the way to search for the selectors — it’s time to put in writing the primary check. Let’s input improper login credentials on a easy login web page, and test if the right kind pop-up is displayed.

Take a look at app evaluate

The state of affairs could be very easy, here’s what you wish to have to automate it:

  • appId — assets. Defines the appliance that will likely be opened,
  • launchApp — opens the app,
  • tapOn — clicks at the textual content fields and the button,
  • inputText — enters credentials,
  • assertVisible — exams if the pop-up with right kind textual content is opened.

That is what the code had to automate those steps seems like. You’ll be able to title it loginTest.yaml:

appId: com.arjak.loginmaestro
---

- launchApp
- tapOn: "username"
- inputText: "TestUser"
- tapOn: "password"
- inputText: "TestPassword"
- tapOn: "LOGIN"
- assertVisible: "Improper Login Credentials"

Executing first check

Assessments are initiated from the terminal. They are able to be done in quite a lot of tactics, with 3 maximum elementary ones being:

maestro check testName.yaml
  • a couple of assessments execution:
maestro check testsFolderName/
  • assessments execution + JUnit record era:
maestro check --format junit testsFolderName/

Now, you’ll use a type of instructions and run the check:

Take a look at was once done correctly, you’ll see all of the steps within the terminal. Quite simple, isn’t it?

In fact, keeping up assessments written on this approach in greater tasks could be tricky and time-consuming. Thankfully, the framework supplies the facility to put in writing assessments in some way that permits more uncomplicated control.

There are two steps that can make the assessments extra tester-friendly.

Flows

Flows are the basic idea of this framework that permits higher check control. They’re used to keep away from duplication of code, through developing the recordsdata (flows) with the repetitive steps. They are able to be run from any other check recordsdata the usage of runFlow command.

What are the advantages? In case of any adjustments you wish to have to replace only one document as a substitute of a couple of ones. Additionally, it’s more uncomplicated to create new assessments and they’re extra clear.

Let’s attempt to enforce the flows within the check app. This time, let’s test the capability of the buttons visual at the pop-up with details about improper login information (“Create new account” and “Take a look at once more”).
Reusable drift on this case may well be the state of affairs of getting into login information.

At first, you wish to have to transport repetitive steps into separate document. You’ll be able to title it incorrectLogin.yaml:

appId: com.arjak.loginmaestro
---

- launchApp
- tapOn: "username"
- inputText: "TestUser"
- tapOn: "password"
- inputText: "TestPassword"
- tapOn: "LOGIN"
- assertVisible: "Improper Login Credentials"

Then let’s create the check to test the Take a look at Once more button. You simply wish to invoke the drift the usage of the runFlow command, after which give you the steps explicit to the given check. Here’s the pattern code:

appId: com.arjak.loginmaestro
---

- runFlow: incorrectLogin.yaml
- tapOn: "Take a look at once more"
- assertVisible: "Input your login credentials"

In a similar fashion, in the second, invoke the drift after which test the check explicit state of affairs:

appId: com.arjak.loginmaestro
---

- runFlow: incorrectLogin.yaml
- tapOn: "Create new account"
- assertVisible: "Input your information"

Let’s run this check:

As you’ll see, Maestro appropriately invoked the drift after which returned to the unique document to finish the remainder steps.

Web page Object Type

The second one stage of improving Maestro assessments, a just right good friend of each automation tester, Web page Object Type. If you happen to’re now not acquainted with it, I strongly counsel looking at one of the vital tutorials.

It’s conceivable to enforce easy Web page Object Type throughout the Maestro venture the usage of the strengthen of a minimum subset of vanilla JavaScript APIs with some purpose-built Maestro extensions.

How does it paintings? You want to outline variables in easy js recordsdata (Pages). Then they may be able to be used to reference component IDs, textual content and many others.

Principally, POM means that you can replace a component in a single position which can then cascade all over all of assessments/flows. It will provide you with:

  • progressed clarity and grouping,
  • diminished useless duplication,
  • progressed check/drift repairs.

Let’s take a look at it within the utility. This time you wish to have to click on “Create new account” button at the Login Web page and input dummy information at the Sign up Web page. At first you wish to have to outline the pages (Login and Sign up):

loginPage.js:

output.loginPage = {
usernameField: "Cellular quantity or electronic mail cope with",
passwordField: "Password",
loginButton: "Login",
createAccountButton: "Create new account"
}

registerPage.js:

output.registerPage = {
name: "Input your information",
signUpButton: "Enroll",
nameField: "title",
usernameField: "username",
emailField: "electronic mail",
phoneField: "telephone",
passwordField: "password"
}

Utilization of POM adjustments the glance of the assessments moderately:

appId: com.arjak.loginmaestro
---
- runScript: loginPage.js
- runScript: registerPage.js

- launchApp
- assertVisible: ${output.loginPage.passwordField}
- assertVisible: ${output.loginPage.loginButton}
- tapOn: ${output.loginPage.createAccountButton}
- assertVisible: ${output.registerPage.name}
- tapOn: ${output.registerPage.nameField}
- inputText: "TestName"
- tapOn: ${output.registerPage.usernameField}
- inputText: "TestUsername"
- tapOn: ${output.registerPage.emailField}
- inputText: "check@check.check"
- tapOn: ${output.registerPage.phoneField}
- inputText: "1111111"
- tapOn: ${output.registerPage.passwordField}
- inputText: "TestPassword"
- tapOn: ${output.registerPage.signUpButton}

At first, you wish to have to invoke the pages the usage of the runScript command. Then, you wish to have to specify which components of the web page will likely be used and that’s it.

Now, consider that we have got 100 assessments the usage of the login capability, and the selector we use to click on the login button adjustments. Due to this manner, you best edit one variable in LoginPage as a substitute of all of the assessments to regulate them.

For the remaining time, let’s attempt to run the check:

Appears just right, Maestro was once ready to reference the right kind components and execute the instructions.

Conclusion

As it is advisable to see, Maestro framework is an easy and easy-to-learn device that can be utilized in greater tasks. It doesn’t require any programming abilities or complicated configurations, which make it clean to be informed for the brand new customers.

In fact, it gives many extra attention-grabbing options described within the documentation, reminiscent of:

  • tags,
  • JavaScript strengthen,
  • recording,
  • Maestro Cloud.

It’s additionally price noting that this device remains to be being advanced. It’s a good suggestion to on occasion test their GitHub repository for updates.

Preview photograph

Leave a Comment

Your email address will not be published. Required fields are marked *