Selectors
Commands that interact with a view (e.g tapOn
, assertVisible
, copyTextFrom
) require the view to be specified using using a selector.
There are many different selectors available:
Shorthand selector for text
If you want to use the text
selector, you can use the following shorthand:
Relative position selectors
Apart from the selectors mentioned above, Maestro is also able to select views using their relative position (i.e. "below another view", or "contains child"):
Selecting one view among many similar
If you have multiple views matching the same selector (i.e. many views with text Hello
), use index
parameter to specify which one to select exactly. For example, the following command will pick the 3rd view that has text Hello
:
Using Regular Expressions
All text fields in Maestro element selectors are regular expressions. Whilst this document isn't intending to replace documentation on regular expressions (use your favourite search engine), here are a few examples of how it operates. In these examples, we've used assertVisible
, but it's applicable to any text or id field.
Partial Matches
If you're on a screen with the sentence 'the quick brown fox jumps over the lazy log', and want to assert on two words in the sentence this won't work:
Because it's a regular expression, it needs to match the text of the entire element. This would work:
Patterns
Regular Expressions are powerful. Imagine a screen that generates a random 6-digit number. Assuming you don't want to imbue your test with all of the material to generate an identical random number, you could assert that you're getting a number of the correct format like this:
Escaping
One downside of regular expressions is that like any expression, there are control characters. If you're attempting to assert on the text 'Movies [NEW]', this won't work:
That's because square brackets have meaning in regular expressions. Instead, you'll need this:
Last updated