Building Mobile UI Tests using REPL
Building Mobile UI Tests using REPL
REPL builds a list of methods to automate a mobile app for use in a UI test. The typical workflow starts with the tree command to list elements in the current view. Next, app methods wait for elements, enter text, tap buttons and so on. Then the copy command saves your REPL activity to the clipboard. Finally, you paste REPL commands into your test method. Once you paste the REPL output, you can clean it up and add assertions.
[Test]
public void TestTotals()
{
app.EnterTexte => e.Class("EntryEditText"), "50");
app.EnterText(e => e.Class("EntryEditText").Index(1), "53.75");
app.ClearText(e => e.Class("EntryEditText").Index(2));
app.EnterText(e => e.Class("EntryEditText").Index(2), "20");
app.SetSliderValue(e => e.Class("FormsSeekBar"), 200);
app.WaitForElement(e => e.Class("FormsTextView").Index(4));
app.WaitForElement(e => e.Class("FormsTextView").Index(6));
app.WaitFor(() => app.Query(e => e.Class("FormsTextView").Index(6))[0].Text != "$0.00");
Assert.AreEqual(app.Query(e => e.Class("FormsTextView").Index(4))[0].Text, "$10.00");
Assert.AreEqual(app.Query(e => e.Class("FormsTextView").Index(6))[0].Text, "$63.75");
app.Screenshot("Tip and total amounts");
}
The screenshot shows the Android emulator on the left, and the REPL command line on the right. You’re seeing the output of the tree command and the beginning of a Query to locate a specific element.
The Video Walk Through
This video shows how to run REPL, and how to use the utility to build a list of methods for your UI test. I hope the video is useful for you. Please let me know in the comments if there are aspects you’d like expanded.
Originally published at Falafel Software Blog.