8.Android_UiAutomator 報告查看

1、Android UiAutomator報告查看

1.錯誤類型

1)斷言錯誤:就是斷言這個用例的成功或者失敗(AssrtionFailedError)
2)腳本錯誤:UiObjectNotFoundException(找不到對象異常)、java異常等java

2.報告狀態

1)運行狀態
2)結果狀態
3)運行信息

運行狀態android

結果狀態shell

運行信息瀏覽器

運行前(1) OK(0) 運行前的信息
運行完成(-1) Errors(-1) 運行中的信息
運行完成 (-1) Failures(-2) 運行後的信息

 

3.報告示例說明

 

這裏寫圖片描述

 

2、各類狀態報告及定位問題

1)斷言失敗的例子
  • 示例代碼:

 

//斷言失敗報告例子
public void testDemo1() throws UiObjectNotFoundException{
    //點擊短信查看是否有無會話產生
    //當前界面獲取短信按鈕
    UiObject msm=new UiObject(new UiSelector().text("短信"));
    UiObject None=new UiObject(new UiSelector().text("短信"));
    //點擊短信按鈕
    msm.clickAndWaitForNewWindow();
    assertTrue(!None.exists()); 
}
  • 生成報告內容:
//運行前
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Jian1.test1:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: 1

//運行中
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Failure in testDemo1:
junit.framework.AssertionFailedError//報斷言錯誤
    at Jian1.test1.testDemo1(test1.java:17)//錯誤地點Jian/test1/testDemo1/第17行
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stack=junit.framework.AssertionFailedError
    at Jian1.test1.testDemo1(test1.java:17)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: -2

//運行後
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.F
Time: 2.577
FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0
INSTRUMENTATION_STATUS_CODE: -1
2)報告經過例子
  • 示例代碼:
//報告經過例子
    public void testDemo1() throws UiObjectNotFoundException{
        //點擊短信查看是否有無會話產生
        //當前界面獲取短信按鈕
        UiObject msm=new UiObject(new UiSelector().text("短信"));
        UiObject None=new UiObject(new UiSelector().text("短信"));
        //點擊短信按鈕
        msm.clickAndWaitForNewWindow();
//      assertTrue(!None.exists()); 
        assertTrue(None.exists());  
    }
  • 生成報告內容:
//運行前
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Jian1.test1:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: 1

//運行中
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: 0

//運行後
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.
Time: 3.668
OK (1 test)
INSTRUMENTATION_STATUS_CODE: -1
3)腳本錯誤中途中斷例子
  • 示例代碼:
//腳本錯誤中斷例子
    public void testDemo1() throws UiObjectNotFoundException{
        //獲取一個搜索不到的對象
        UiObject msm=new UiObject(new UiSelector().text("短信123"));
        //點擊對象
        msm.clickAndWaitForNewWindow(); 
    }
  • 生成報告內容:
//運行前
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Jian1.test1:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: 1

//運行中
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Error in testDemo1://腳本運行錯誤
com.android.uiautomator.core.UiObjectNotFoundException: UiSelector[TEXT=短信123]//找不到對象出現的錯誤
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:432)
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:410)
    at Jian1.test1.testDemo1(test1.java:14)//出現的位置
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stack=com.android.uiautomator.core.UiObjectNotFoundException: UiSelector[TEXT=短信123]
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:432)
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:410)
    at Jian1.test1.testDemo1(test1.java:14)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: -1

//運行後
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.E
Time: 11.655
FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1//一個報錯
INSTRUMENTATION_STATUS_CODE: -1
4)多用例同時運行例子
  • 示例代碼:
public void testDemo1() throws UiObjectNotFoundException{
    //獲取一個搜索不到的對象
    UiObject msm=new UiObject(new UiSelector().text("短信123"));
    //點擊對象
    msm.clickAndWaitForNewWindow(); 
}
public void testDemo2(){
    UiDevice.getInstance().pressBack();
}
public void testDemo3(){
    UiDevice.getInstance().pressBack();
    assertTrue(false);//斷言失敗的例子
}
public void testDemo4(){
    UiDevice.getInstance().pressBack();
}
//報告經過例子
public void testDemo5() throws UiObjectNotFoundException{
    //點擊短信查看是否有無會話產生
    //當前界面獲取短信按鈕
    UiObject msm=new UiObject(new UiSelector().text("短信"));
    UiObject None=new UiObject(new UiSelector().text("短信"));
    //點擊短信按鈕
    msm.clickAndWaitForNewWindow();
    assertTrue(None.exists());//斷言成功    
}
  • 生成報告:
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Jian1.test1:
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: 1


INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Error in testDemo1:
com.android.uiautomator.core.UiObjectNotFoundException: UiSelector[TEXT=短信123]
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:432)
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:410)
    at Jian1.test1.testDemo1(test1.java:16)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: stack=com.android.uiautomator.core.UiObjectNotFoundException: UiSelector[TEXT=短信123]
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:432)
    at com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow(UiObject.java:410)
    at Jian1.test1.testDemo1(test1.java:16)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: test=testDemo1
INSTRUMENTATION_STATUS_CODE: -1


INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo2
INSTRUMENTATION_STATUS_CODE: 1


INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo2
INSTRUMENTATION_STATUS_CODE: 0


INSTRUMENTATION_STATUS: current=3
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo3
INSTRUMENTATION_STATUS_CODE: 1


INSTRUMENTATION_STATUS: current=3
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Failure in testDemo3:
junit.framework.AssertionFailedError
    at Jian1.test1.testDemo3(test1.java:23)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: stack=junit.framework.AssertionFailedError
    at Jian1.test1.testDemo3(test1.java:23)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: test=testDemo3
INSTRUMENTATION_STATUS_CODE: -2


INSTRUMENTATION_STATUS: current=4
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo4
INSTRUMENTATION_STATUS_CODE: 1


INSTRUMENTATION_STATUS: current=4
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo4
INSTRUMENTATION_STATUS_CODE: 0


INSTRUMENTATION_STATUS: current=5
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo5
INSTRUMENTATION_STATUS_CODE: 1


INSTRUMENTATION_STATUS: current=5
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: numtests=5
INSTRUMENTATION_STATUS: test=testDemo5
INSTRUMENTATION_STATUS_CODE: 0


INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.E..F..
Time: 16.215
FAILURES!!!
Tests run: 5,  Failures: 1,  Errors: 1
INSTRUMENTATION_STATUS_CODE: -1

3、輸出信息到報告

1.setup與tearDown

1)setup(開始)
2)tearDown(結尾)

2.相關API

1)Bundle
2)getAutomationSupport().sendStatus(int ,Bundle)
  • 例如:
//setUp
protected  void setUp() throws Exception{
    super.setUp();
    System.out.println("setUp:用例開始執行了---------");
    //新建bundle對象
    Bundle bundle=new Bundle();
    bundle.putString("key1", "value1");
    bundle.putString("key2", "value2");
    bundle.putString("key3", "value3");
    bundle.putString("key4", "value4");
    bundle.putString("key5", "value5");
    //發送狀態,注意不能跟系統狀態碼同樣(0,1,-1),這裏咱們用10
    getAutomationSupport().sendStatus(10, bundle);  
}
//testCase
public void testReport(){

    System.out.println("test:用例正在執行中------------");
    //新建bundle對象
    Bundle bundle=new Bundle();
    bundle.putString("key1-", "value1-");
    bundle.putString("key2-", "value2-");
    bundle.putString("key3-", "value3-");
    bundle.putString("key4-", "value4-");
    bundle.putString("key5-", "value5-");
    //發送狀態,注意不能跟系統狀態碼同樣(0,1,-1),這裏咱們用11
    getAutomationSupport().sendStatus(11, bundle);  
    UiDevice.getInstance().pressBack();
}
//tearDown
protected void tearDown() throws Exception {
    // TODO Auto-generated method stub
    super.tearDown();
    System.out.println("tearDown:用例執行完了-----------");
    //新建bundle對象
    Bundle bundle=new Bundle();
    bundle.putString("key1*", "value1*");
    bundle.putString("key2*", "value2*");
    bundle.putString("key3*", "value3*");
    bundle.putString("key4*", "value4*");
    bundle.putString("key5*", "value5*");
    //發送狀態,注意不能跟系統狀態碼同樣(0,1,-1),這裏咱們用12
    getAutomationSupport().sendStatus(12, bundle);
}
  • 生成報告:
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=
Jian1.test1:
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo6
INSTRUMENTATION_STATUS_CODE: 1


setUp:用例開始執行了---------
INSTRUMENTATION_STATUS: key4=value4
INSTRUMENTATION_STATUS: key3=value3
INSTRUMENTATION_STATUS: key5=value5
INSTRUMENTATION_STATUS: key2=value2
INSTRUMENTATION_STATUS: key1=value1
INSTRUMENTATION_STATUS_CODE: 10


Set up:用例開始執行...
INSTRUMENTATION_STATUS: key4=value4
INSTRUMENTATION_STATUS: key3=value3
INSTRUMENTATION_STATUS: key5=value5
INSTRUMENTATION_STATUS: key2=value2
INSTRUMENTATION_STATUS: key1=value1
INSTRUMENTATION_STATUS_CODE: 10


tearDown:用例執行完了-----------
INSTRUMENTATION_STATUS: key4*=value4*
INSTRUMENTATION_STATUS: key5*=value5*
INSTRUMENTATION_STATUS: key1*=value1*
INSTRUMENTATION_STATUS: key2*=value2*
INSTRUMENTATION_STATUS: key3*=value3*
INSTRUMENTATION_STATUS_CODE: 12


INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: class=Jian1.test1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: test=testDemo6
INSTRUMENTATION_STATUS_CODE: 0


INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.
Time: 0.083
OK (1 test)
INSTRUMENTATION_STATUS_CODE: -1

4、傳入參數控制腳本

  • 演示範例
1)經過-e傳入數據到用例中,如:撥打一個指定電話
public void testDemo7() throws UiObjectNotFoundException{
    //初始化動做(按返回鍵才能萬全退出一個應用)
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressHome();//返回桌面
    //獲取對象
    UiObject call=new UiObject(new UiSelector().text("撥號"));//撥號按鈕
    UiObject dialpad=new UiObject(new UiSelector().className("android.widget.TableLayout"));//撥號盤
    //點擊對象
    call.clickAndWaitForNewWindow();
    dialpad.clickAndWaitForNewWindow();
    //傳入參數
    Bundle b=getParams();
    String phone =(String) b.get("phone");//-e key value   -e phone 10086
    //邏輯判斷和輸入
    for (int i=0;i<phone.length();i++){
        String c=phone.charAt(i)+"";
        UiObject phoneNum=new UiObject(new UiSelector().text(c));//撥號盤
        phoneNum.click();
        sleep(1200);
    }
}
  • 注意事項:
1.Uiautomator不能進行傳參的快速調試,能夠先run一下,用例push到手機上以後而後使用命令行進行輸入,上面的用例運行命令爲:
adb shell uiautomator runtest test.jar --nohup -c Jian1.test1#testDemo7 -e phone 10086
2)經過-e出傳入總體控制參數控制腳本,如:清理應用數據
public void testDemo8() throws UiObjectNotFoundException {
    //初始化動做(按返回鍵才能萬全退出一個應用)
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressBack();
    UiDevice.getInstance().pressHome();//返回桌面
    //傳入參數
    Bundle b=getParams();
    String ctrl=(String) b.get("ctrl");
    //開始邏輯斷定
    boolean isClear=Boolean.valueOf(ctrl);
    if(isClear){
        //執行清理步驟
        //點菜單按鈕
        UiDevice.getInstance().pressMenu();
        //點管理應用按鈕
        UiObject manAPP=new UiObject(new UiSelector().text("管理應用"));
        manAPP.clickAndWaitForNewWindow();  
        //滾動查找對象並點擊
        UiScrollable list=new UiScrollable(new UiSelector().resourceId("android:id/list"));
        UiObject browser=new UiObject(new UiSelector().text("瀏覽器"));
        list.scrollIntoView(browser);
        browser.clickAndWaitForNewWindow();
        //點擊清除數據按鈕
        UiObject clear=new UiObject(new UiSelector().text("清除數據"));
        clear.clickAndWaitForNewWindow();
        //點擊肯定
        UiObject OK=new UiObject(new UiSelector().text("肯定"));
        OK.clearTextField();

    }else{
        //不執行清理
        System.out.println("不執行清理-------------");
    }
    //打開瀏覽器
    UiObject browser=new UiObject(new UiSelector().text("瀏覽器"));
    browser.clickAndWaitForNewWindow();
}
  • 注意事項
1.Uiautomator不能進行傳參的快速調試,能夠先run一下,用例push到手機上以後而後使用命令行進行輸入,上面的用例運行命令爲:
adb shell uiautomator runtest test.jar --nohup -c Jian1.test1#testDemo8 -e ctrl false
or
adb shell uiautomator runtest test.jar --nohup -c Jian1.test1#testDemo8 -e ctrl true
相關文章
相關標籤/搜索