7 Random Robotium Tricks

I’ve been exploring and using Robotium for close to a year and here are some tips that I wish I had known when I started:

1.)  ArrayList<View> listOfTouchables = solo.getView(R.resource.id).getTouchables();

This is GREAT! I love it because, combined with the uiautomator tool included with the Android SDK, I can get views that don’t have text or a resource id. As long as the parent view has an id I can get to the view by traversing the ArrayList of touchables. I have found that it works quickly, and reliably.

2.) I had no clue that solo.waitForText () returns a boolean value. I know I could have stumbled on this sooner had I RTFM(Read The F#&*$@^ Manual), but another SDET showed me and it’s been a great way to condense code. The code is condensed because we can combine verification with controlling the flow of the tests without a heavy reliance on solo.sleep(Integer x).

3.) Use solo.searchButton(String x ) before you click on it with the resource id. In the event of an error, this has the benefit of letting you know the string that the automation was trying to find versus just the integer that gets returned if you use just the resource id. This also allows you to leverage the Robotium’s built in time out versus using solo.sleep(Integer x).

4.) Use solo.clickOnListItem(Integer x) is wonderful for selecting items in the navigation drawer. This has been great for me, especially when the items in the navigation drawer are shifting and more are being added. Combine this with the use of constants and you’ll have really easily manageable navigation drawer automation.

5.) Use solo.getCurrentActivity().hasWindowFocus() This little gem I stumbled on through Google and I had no clue how it would ever be useful. I was wrong and I’m sure a large numbers of applications that require automation will be able to use this puppy. It’s great for checking things that your application hands over to the Android OS via Intents. I use it because we have a few spots in our automation that open a URL in the browser. It’s great because I don’t honestly care if it actually opens in a browser, just that we’ve left the application and that’s what this does. One word of caution: If you’re using this with AppThwack your tests WILL timeout. So be careful when using it on their platform so as to not blow your minutes.

6.) This one is general, but the fact that Robotium is able to automate within webviews is great. The drawback is that it relies on the ids and if you’re leveraging an external API your automation can just break with very little to no notice and fixing it can be a bit painful. In my case I was using it with the Paypal API and we had a myriad of issues with the page not loading or not loading completely. This caused the test to be brittle and not really useful around that part. Don’t be discouraged though, because if you’re using an internally managed webpage this will be a great asset for end to end testing.

7.) I’m not sure how subtle I’ve been about this, but I HATE HATE HATE using solo.sleep() or any set time sleep in any automation framework. By this, I mean having a solo.sleep(40000) after clicking the a login button. I know there are a plethora of times where it’s easier, but it bugs me when I am forced to use it. I love Robotium because I have a ton of options to use without ever resorting to it. I know. I know. Anytime I use solo.waitForView, solo.waitForText or whatever else, under the hood we’re using sleep. The beauty of it being used there is that it’s abstracted from me. I don’t have to directly call it. It keeps my code looking slightly crisper. In the login example, a better option would be to use a solo.waitForView, with a timeout. This way if your login takes only 10 seconds, your test will progress sooner than waiting the additional 30 (and unnecessary) seconds. So, my last tip is that with Robotium you can wait for almost anything. You can solo.waitForView, solo.searchButton, or another of the myriad of options available in the framework. There are very few valid reasons to wait for a set amount of time, every single time.

BONUS: This was hard for me to find when I was starting off, and has been bookmarked since stumbling on it. I present to you the list of ALL the methods available within the Solo class.

ALL THE METHODS!!!

That’s all I have for today. The next post will be the first of three parts in the negotiation series. Feel free to comment, and you better share!

Sophie’s Choice…

My kids are asleep and I have free time…

aaaaaannnnnddddd

I’m researching ways to make my functional automated testing more performant with Robotium. This might just be me, but when I use the solo.clickOnText(String x) and solo.clickOnButton(String x) are faster than solo.clickOnView(solo.getView(R.id.name)). I prefer to use the latter because I feel it helps me guarantee that I’ll hit the right button, but the clickOnButton() method is my lazy favorite because it goes faster. It also has the added benefit of a decent log message when it can’t be found. It’ll say something like “Button with text ‘x’ can’t be found.” versus “View with id ‘939494949729’ can’t be found.” The problem with using the text is that content changes OFTEN in development. This means added maintenance in order to avoid false failures. In my opinion the best tests are the ones that you only have write once. That means making it as generic as possible for most of the visual interaction. You don’t want your tests to hinge on something as volatile as the content. That’s what I’m noodling through tonight…

Should I choose the path with frequent maintenance, and gain speed or should I choose the path of low maintenance and lose speed?