Android無線測試之—UiAutomator UiObject API介紹七

來源:互聯網
上載者:User

標籤:

判斷對象是否存在

1、判斷對象是否存在相關API

傳回值 API 描述
boolean waitForExists(long timeout) 等待對象出現
boolean waitUntilGone(long timeout) 等待對象消失
boolean exists() 檢查對象是否存在

 

 

 

 

2、API應用舉例

package com.test.uiobject;import java.io.File;import android.graphics.Rect;import android.view.KeyEvent;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.core.UiObject;import com.android.uiautomator.core.UiObjectNotFoundException;import com.android.uiautomator.core.UiSelector;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class Demo extends UiAutomatorTestCase {    /**     * @param args     */    public static void main(String[] args) {        String jarName,testClass,testName,androidId;        jarName="demo";        testClass="com.test.uiobject.Demo";        testName="testExists";        androidId="1";        new UiAutomatorHelper(jarName,testClass,testName,androidId);    }        public void testExists() throws UiObjectNotFoundException{        UiDevice.getInstance().pressHome();        sleep(2000);        UiObject message=new UiObject(new UiSelector().text("Messaging"));        message.click();        sleep(2000);                UiObject text=new UiObject(new UiSelector().text("No conversations."));        if(text.exists()){            System.out.println("No conversations, please create a message");        }                UiObject create=new UiObject(new UiSelector().resourceId("com.android.mms:id/action_compose_new"));        if(create.waitForExists(5000)){            create.click();            UiObject to=new UiObject(new UiSelector().resourceId("com.android.mms:id/recipients_editor"));            to.click();            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_1);            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_0);            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_0);            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_8);            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_6);            UiObject typeMessage=new UiObject(new UiSelector().resourceId("com.android.mms:id/embedded_text_editor"));            typeMessage.setText("hello, my name is fsw!");            UiObject button=new UiObject(new UiSelector().resourceId("com.android.mms:id/send_button_sms"));            button.click();            sleep(2000);        }    }}
Demo.java

 

Android無線測試之—UiAutomator UiObject API介紹七

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.