From couple of days I was looking that each monkeyTalk automation script would run individually without affecting each other, It means that AUT (Application Under Test) at initial stage for each test.
So I think that if I launch application before running test and closing after test execution, I will get solution.
After searching, I got some adb commands to launch and close installed application. Below commands are for the same:
To launch Application:
Where “com.gorillalogic.monkeytalk.demo1” is application package name and “RootActivity” is main activity class name.
To close application
Where “com.gorillalogic.monkeytalk.demo1” is application package name.
We can execute above adb command using java code by using “Runtime.getRuntime().exec()” method.
Below example is junit test script having two methods with implemented launching and closing application approach.
So I think that if I launch application before running test and closing after test execution, I will get solution.
After searching, I got some adb commands to launch and close installed application. Below commands are for the same:
To launch Application:
adb shell am
start -n com.gorillalogic.monkeytalk.demo1/.RootActivity
Where “com.gorillalogic.monkeytalk.demo1” is application package name and “RootActivity” is main activity class name.
To close application
adb shell am
force-stop com.gorillalogic.monkeytalk.demo1
Where “com.gorillalogic.monkeytalk.demo1” is application package name.
We can execute above adb command using java code by using “Runtime.getRuntime().exec()” method.
Below example is junit test script having two methods with implemented launching and closing application approach.
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); } @Before public void testBefore() throws IOException, InterruptedException{ Runtime.getRuntime().exec("adb shell am start -n com.gorillalogic.monkeytalk.demo1/.RootActivity"); Thread.sleep(10000); } @After public void closeApp() throws IOException{ Runtime.getRuntime().exec("adb shell am force-stop com.gorillalogic.monkeytalk.demo1"); } @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"); } }
No comments:
Post a Comment
Leave your comments, queries, suggestion I will try to provide solution