Using MonkeyTalk in AndroidStudio


Let me first introduce what MonkeyTalk is?
Monkey talk is a mobile app testing tool. MonkeyTalk automates real, functional interactive tests for iOS and Android apps – everything from simple “smoke tests” to sophisticated data-driven test suites. Native, mobile, and hybrid app, real devices or simulators. Moreover, automation saves time, it is re-usable, repeatable and so on. Monkey talk is an open source automation tool. It supports both Android and iPhone. It is very easy to learn and its a powerful functional testing tool.

Everything is in the web. So, why am I writing this blog?
Its because recently I have switched to android studio for android development. There are loads of tutorial based in Eclipse but very few based in Android Studio. So, I thought maybe this will be useful for everyone out there who is struggling to use MonkeyTalk in Android Studio.

Requirements for MonkeyTalk are….
1. Android Studio
2. MonkeyTalk IDE which you can download from this link

Procedure :
Before you proceed with this blog, I presume you know how to use android studio and gradle build system.
So, here we start.

There are two important steps to be followed:

Step 1: We build an instrumented apk using Android Studio

Step 2: We perform automation on instrumented apk using MonkeyTalk IDE

How to make an instrumented apk ?

      1. I assume you have a ready project in Android Studio which can be compiled successfully using Android Studio. You can get a test project from this github link.
      2. Now, in your app folder create a new folder named monkey-libs folder. Inside this folder place Monkey Talk Agent as shown in the github.
      3. Then, in your build.gradle file located inside app folder, add the aspectj dependency inside buildscript
         buildscript {  
           repositories {  
             mavenCentral()  
           }  
           dependencies {  
             classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5'  
           }  
         }  
        
      4. Add aspectj plugin in dependencies of buildscript
      5. Then to activate the aspectj plugin, write the given code in build.gradle file
         apply plugin: 'android-aspectj'  
        
      6. Then compile the Java file with AspectJ plugin by writing the following code in build.gradle file
         dependencies {  
         compile fileTree(dir: 'libs', include: ['*.jar'])  
         monkeytalkCompile fileTree(dir: 'monkey-libs', include: ['*.jar'])  
         }  
        
      7. Thats all you need to do in build.gradle file.
      8. Now we need to create an instrumented apk. To get instrumented apk you need to create a folder name monkeytalk inside src folder. This monkey talk folder must contain AndroidManifest file. Just one AndroidManifest file is required. You can see the sample here .
      9. AndroidManifest file located inside monkeytalk must consist of the following permissions:
         <?xml version="1.0" encoding="utf-8"?>  
         <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
           package="com.georgepapas.monkeytalkdemo" >  
           <uses-permission android:name="android.permission.GET_TASKS"/>  
           <uses-permission android:name="android.permission.INTERNET"/>  
         </manifest>  
        
      10. and thats all. A build instrumented with monkey talk aspects will be generated and installed in the emulator or your device by running the given code:
         ./gradlew clean installMonkeytalk  
        

Hence, you can find an instrumented apk in your device or emulator.

Now, how to run the automation ?

      1.  Start your monkey talk ide.
      2. Go to File > New > MonkeyTalk Project > project name (say TestMonkeyTalk)
      3. Right click on project TestMonkeyTalk > New > Script > ScriptName (say testScript)
      4. Open your device which has debugging mode enabled and start your app.
      5. Press Connect > Android Device.
      6. Then press the Record Button and start using your app. As you finish visiting all the pages of the app, press stop button.
      7. Hence, now you have a Script for automation.
      8. Now, to start the automation, press the play button.

Hence, you have successfully automated your testing procedure.

Good luck with monkey talk.

See you later in the next blog.

Until then Happy Coding 🙂

Advertisements

7 thoughts on “Using MonkeyTalk in AndroidStudio

  1. Hi. I am new to Android studio and MonkeyTalk. I know Eclipse to some extent. My basic Q is, do we need to instrument Monkey talk into the apk and then only I can use it?

  2. I followed the above steps and the app is working fine on the emulator. But when I input the generated .apk. I have taken the .apk file from project_name -> app -> build -> output -> apk -> appname_debug.apk (Is it a correct position to take the instrumented .apk??)

    when I try to import this .apk to MonkeyTalk IDE, it says its not instructed yet

    can u guide me with this? Thank you..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s