First, run the command introduction:
#Test. Java Packagecom.uiautomatortest;ImportAndroid.os.Bundle;Importandroid.os.RemoteException;ImportCom.android.uiautomator.core.UiDevice;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classTestextendsUiautomatortestcase { Public voidTesthome () {uidevice.getinstance (). Presshome (); Sleep (2000); } Public voidTestmenu () {uidevice.getinstance (). Pressmenu (); Sleep (2000); } Public voidTestrecent ()throwsremoteexception{uidevice.getinstance (). Pressrecentapps (); Sleep (2000); } Public voidTestdemo () {uidevice.getinstance (). Presshome (); Sleep (2000); Bundle Bundle=Getparams (); String Phone=bundle.getstring ("Phone"); System.out.println ("Phone=" +phone); }}
Test.java
Example 1: Run a test class (run all test cases under the Class):
adb shell Uiautomator runtest demo.jar-c com.uiautomatortest.Test
Example 2: Run a test case under a test class:
adb shell Uiautomator runtest demo.jar-c Com.uiautomatortest.test#testhome
Example 3: Run multiple test cases at the same time:
adb shell uiautomator runtest demo.jar-c com.uiautomatortest.test#testhome-c com.uiautomatortest.test#testrecent
Example 4: Use the-e parameter to pass in a key-value pair into the test program:
adb shell uiautomator runtest demo.jar-c com.uiautomatortest.test#testdemo-e phone 12345678
Second, rapid commissioning:
The original problem:
1) Unable to debug directly in eclipse
2) Use life debugging cumbersome and inefficient
Workaround:
To convert the debugging steps into a script, the debugging steps are 5:
So here's how to get a quick compile script:
1) Click the Open Perspective button in Eclipse, select Git Repository exploring, click OK:
2. Click Clone a Git repository, enter https://github.com/fan297/UiAutomatorHelper.git in the pop-up window URI, and go to the next, until finish
3) Import the project, all the way next until finish:
4) More than a project Uiautomatordebug, the project inside the Uiautomatorhelper.java copy to the corresponding project below
5) Add the following code to the project class that you want to run
#将此段代码添加到Test. The last face of the test class for Java Public Static void Main (string[] args) { String jarname, TestClass, testname, Androidid; Jarname= "Demotest"; TestClass= "Com.uiautomatortest.Test"; TestName= "Testdemo"; Androidid= "1"; New Uiautomatorhelper (Jarname, TestClass, testname, Androidid);}
Test.java
6) Select Run as Java application in Eclipse and observe the emulator changes.
Android Wireless Test-uiautmator Run command introduction and quick commissioning