Friday, June 8, 2012

Android Robotium : Capture Screen or ScreenShot

We are having one question in mind, when we are using Robotium for testing.

Can I take screenshots from inside of Robotium?

Ans: No. we are not having direct API's.

You can find the details information from the following link http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

But we are having alternative approach, where we can achieve taking snapshot of the screen.

Android Robotium ScreenShot Code


By using the above code snippet, we can achieve taking snapshot in Robotium, when your test case fail or success.

Enjoy :)

3 comments :

  1. Thanks for sharing the above code. I guess now Robotium 3.3's includes a function "takeScreenshot()"... haven't tried it though.

    ReplyDelete
  2. Since Robotium is tied to the application under test, I am not able to take the screenshot of the device if the activity closes or is in background. Do you know how can we support screen capture when other activity is in focus.

    ReplyDelete
    Replies
    1. I am not able to get your question properly.
      If other activity is in focus, you can take snapshot from the same activity. right?

      Delete