Android Wireless Test-uiautmator Run command introduction and quick commissioning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.