MonkeyTalk testing with Android : Some initial notes and lessons learned

Some issues ran into while setting up MonkeyTalk

  • Almost immediately I realized that the basic commands provided by the MonkeyTalk UI and the .mt file would not be enough and that I would have to use JavaScript. That was OK by me as I have basic knowledge of JavaScript. IF you want conditions, variables etc. you might as well start immediately with JavaScript
  • If you would like to use a javascript script for your test, you must first create a MonkeyTalk script with .mt extension, then Export and then when you edit it, you can execute those tests. When you set up the .mt file, it creates proper include links in the libs.
  • conditional “if” in javascript is best handled with try and catch like this. I’ve been successful at nesting them too :
try
{
app.label("#24").verifyWildcard("*Setup: Start*");
app.device().screenshot();
app.button("Next").tap();
}
// if text "Setup: Start" is not in label 24, go on without stopping test
catch(e)
{
app.device().screenshot();
// now check if label 15 contains "Alert"
try
{
app.label("#15").verifyWildcard("*Alert*");
app.button("Next").tap();
}
// finally do this
catch(e)
{
app.button("Next").tap();
}
}
  • Component Tree is essential. Add it to your view, found in Other when adding views. Then when the device is connected to the view you want to automate click to refresh the Component Tree. There you can find all the IDs that you need
  • Good way to check text on your page is with wildcards. You don’t have to match the string exactly (at least for your initial attempts at learning):
app.label("#15").verifyWildcard("*Alert*");
  • Seems like the app.device().back(); command on Android has issues as of now (Dec 2013). It does not execute the same as on the device. Device returns to the previous view, MonkeyTalk returns view to Android Home page. Workaround is to use adb through Shell Exec. I had to enter full path to adb for it to work, something like this:
var adb_path = "/home/tester/android-sdk/platform-tools/adb"
app.system().exec(adb_path, "shell", "input", "keyevent", "4");
  • It is a good idea to check your main functions through a .mt file. Try out how the default function works with your device/view, then view in the JavaScript tab to learn of the proper Javascript notation. The feature to “Play Row” or “Play Rows” is awesome for troubleshooting/debugging.