Wednesday, 20 June 2012

Selenium for Android: MonkeyTalk Installation and Use

This guide will explain how to do automated testing on the android emulator using Gorilla Logic MonkeyTalk. To do this you must have a working installation of Eclipse IDE, ADT Plugin, Android sdk, an avd image file and a test project to work with. I'm using the SimpleCalc program from MobileTutsPlus but any simple app will do to get this working. I'd advise using a completed working app so you know that any errors are not issues with the app

Prerequisite tutorials

"Eclipse with Android SDK - Installation Guide" from this blog. You'll may need this to help set up your environment. It also contains some "other topics" such as how to load an android app into Eclipse, install a .apk on the emulator, how to run the app etc.

You will need

  • Windows 7 x64 - All instructions are for Windows users.
  • Gorilla Logic - MonkeyTalk (free open source download)
  • Android SDK (free open source download)
  • Eclipse IDE with ADT plugin installed (other steps below).
As before, follow the Eclipse tutorial I did if you are unsure about how to configure these programs.

Reason for using MonkeyTalk

Android testing can potentially be a lot easier and faster with record / playback facilities and scripting. We can write our own scripts by hand but this is a time consuming task which requires repeating whenever the AUT changes.

Having a record / playback facility enables us to create a script as we browse the Android emulator / device and create a script without having to manually write any code. We can then repeat the tests over and over to load in data or check for defects. The scripts created can be edited manually and require little technical knowledge to modify. For this reason record / playback software is excellent for test teams composed of non-technical people who understand a software specification but do not know how to develop software. Many test teams enjoy using Selenium IDE for this job on a website but what about testing Android applications?

Several such tools exist for Android. One of these is MonkeyTalk SDK (free & open source), there is also BotBot (free & open source) and bitbar TestDroid (proprietary). This guide focuses exclusively on MonkeyTalk.

Getting MonkeyTalk

To use MonkeyTalk you need to set up an account with them. This is pretty straight-forward. Afterwards login and navigate to the download page and get MonkeyTalk IDE:

Download MonkeyTalk

Unzip MonkeyTalk and place it at the root of the C: drive in a folder called "monkeytalk".

Take the MonkeyTalkIDE folder and place it in c:\program files , unless you are running the x86 version on an x64 system, in which case place it in c:\Program Files (x86).

Aspect J

You will need to install AspectJ to Eclipse. Go to Help > "Install new Software" > In Work with:

Several urls are needed to get the packages you need:

"AJDT Development tools" from: http://download.eclipse.org/tools/ajdt/37/update

(You may also need:

"Apache Maven" from: http://q4e.googlecode.com/svn/trunk/updatesite-iam/  )

Setting up a MonkeyTalk Project and Running a Test

Import a suitable program to test in Eclipse, anything simple with a couple of buttons and input boxes will do.

Convert to Aspect J

Right click your project in Eclipse > Configure > "Convert to AspectJ"

Nothing wil appear happen except some visible folder changes.

Create a libs folder in the Android project if none exists.

Navigate to the MonkeyTalk agent for Android, located at:

C:\monkeytalk\agents\android

Copy the android agent into the libs folder from c:\monkeytalk\agents\android

Right click on MonkeyTalk-agent.jar > AspectJ Tools > Add to Aspectpath > You will see some folder changes happen.

Update your AndroidManifest.xml to include the following two permissions:
    android.permission.INTERNET
    android.permission.GET_TASKS

To do this, open the manifest file and add these lines under the root element <manifest> :

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_TASKS" />

Update the project properties (right-click on the project > Properties > Java Build Path), select the Order and Export tab, and check the checkbox next to the AspectJ Runtime Library to export it.

Run the project on a suitable emulator (i.e. same api version).

Create the MonkeyTalk Project in IDE

Open the MonkeyTalk IDE where scripts will be recorded / played. You may want to create a shortcut to this application.

Create a new MonkeyTalk project by giving it a name and choosing the workspace where all of these will go.

Right click the new project in the MT IDE and select new Script. Give it a filename and click Finish.

Connecting the MonkeyTalk IDE to the Emulator

Open the MonkeyTalk IDE > Click the test > Click the Android drop down next to the play button > Select "Android Emulator / Tethered Device" > The first time through will ask you to enter the location of the Android SDK > after you exit this screen, click on the Android icon again and you will get this message in the console if successful:


"Connection set to Android Emulator or Tethered Device"

If not, ensure that the emulator is running and that the app is visible that you want to test.

Recording through the MonkeyTalk IDE

Load the emulator you want to use with MT installed as in previous steps. Load the application you want to test on the emulator.

Connect as in previous steps.

Click record

Go to the running emulator > Click the steps you need to record in the emulator (similar to Selenium IDE) > Click stop when finished > Click play to play back the test and watch it performing the steps you ran.

That's it!

4 comments:

  1. HI buddy,

    Whether for this tool, is there need an source code of apps or only .apk files is necessary .kinldy clarify this question.

    Thanks in advance

    Regards,
    Vijay

    ReplyDelete
    Replies
    1. If I understand you correctly you need to know if you can use monkeytalk with an apk file? To my knowledge you will need the app to be modified to work with MonkeyTalk. If you only have access to an apk from a developer you could ask the developer to modify the apk to make it work with MonkeyTalk as in the above instructions.

      Delete
  2. i have performed the same steps but my recording button is not enabeld what to do

    ReplyDelete
    Replies
    1. Sorry I don't have time to work on Monkey Talk at the moment. But full instructions are given on the MT site:

      http://www.gorillalogic.com/monkeytalk-documentation/monkeytalk-getting-started/install-agent/android

      Delete

HyperSmash