Mobile app automation using MonkeyTalk Java API

Gorilla Logic has released its MonkeyTalk api for java. We can automate mobile application using java language for both iOS and android application. In this post I will show you how to setup and created test scripts in java. Following are requirement to setup:
Setup:
  1. Install Java on your machine.
  2. Download MonkeyTalk from link: “https://www.cloudmonkeymobile.com/developer-resources/downloads”
  3. Unzip downloaded monkeytalk zip file in your machine.
  4. You need to setup your application with monkeytalk agent, 
  5. Run application on emulator or devices.

Procedure to create test scripts:
1. Now you are ready to create your first monkey talk java project for mobile automation. In this I am using sample application provided by “Gorilla Logic” you can find from downloaded monkeytalk zip folder.
2. Open  “MonkeyTalkIDE “ folder into Monkeytalk unzip folder and click on “MonkeyTalkIDE.exe”
Monkey talk IDE should be opened

3. Create new java project.
4. Add “monkeytalk-java-1.0.62-all-in-one.jar” and “junit.jar” jar files into project class path.

5. Create a java class file for Junit test like below


package com.test;

import java.io.File;
import java.io.IOException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.gorillalogic.monkeytalk.java.MonkeyTalkDriver;
import com.gorillalogic.monkeytalk.java.api.Application;

public class SampleTest {
        private static MonkeyTalkDriver mt;
    private Application app;

    @BeforeClass
    public static void beforeClass() throws IOException {
        mt = new MonkeyTalkDriver(new File("."), "Android");
        mt.setThinktime(500);
        mt.setTimeout(5000);         
    }

    @Test
    public void testLogin() throws InterruptedException {
        app = mt.app();
        app.tabBar().select("login");
        app.input("username").enterText("Admin");
        app.input("password").enterText("Admin");
        app.button("LOGIN").tap();
        Thread.sleep(4000);
        app.button("LOGOUT").tap();        
    }
   
    @Test
    public void testForms() throws InterruptedException {
        app = mt.app();       
        app.tabBar().select("forms");
        app.itemSelector("myDropdown").select("Hydrogen");
        app.itemSelector("myDropdown").select("Lithium");
        app.checkBox("mySwitch").off();
        app.buttonSelector("myRadios").select("B");              
    }
   
    @Test
    public void testHierarchy() throws InterruptedException {
        app = mt.app();      
        app.tabBar().select("hierarchy");
        app.table("elements").select("Hydrogen");
        app.device().back();        
    }
   
    @Test
    public void testWeb() throws InterruptedException {
        app = mt.app();       
        app.tabBar().select("web");
        app.input("userInput").tap();
        app.input("userInput").enterText("Test");
        app.textArea("txtarea").tap();
        app.textArea("txtarea").enterText("This is testing");
        app.itemSelector("Fruits").select("Banana");
        app.radioButtons("rbox").select("B");
        app.checkBox("e").on();
        app.button("GO!").tap();      
    }
}


In above Junit test file, I have created four test methods for sample android application.
For elements locator you can find from xml file of your application or just record scenario from Monkeytalk IDE and copy element IDE from recorded scenario for the same

Execution:  For execution just right click on test script and run as Junit, Also you can run this by using ant and maven. Below screen is of execution above test script.


No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution