zoukankan      html  css  js  c++  java
  • Android无线测试之—UiAutomator UiObject API介绍四

    输入文本与清除文本

    一、输入文本与清除文本相关API

    返回值 API 描述
    boolean setText(String test) 在对象中输入文本
    void clearTextField() 清除编辑框中的文本

    二、输入文本与清除文本实现步骤说明

    1)输入文本:清除文本—>输入文本

    2)清除文本:长按—>清除文本

    三、API应用举例

    package com.test.uiobject;
    
    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="testSetTextAndClearText";
            androidId="1";
            new UiAutomatorHelper(jarName,testClass,testName,androidId);
    
        }
        
        public void testSetTextAndClearText() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(2000);
            UiObject message=new UiObject(new UiSelector().text("Messaging"));
            message.clickAndWaitForNewWindow();
            UiObject createMessage=new UiObject(new UiSelector().resourceId("com.android.mms:id/action_compose_new"));
            createMessage.clickAndWaitForNewWindow();
            
            //输入信息内容
            UiObject typeMessage=new UiObject(new UiSelector().resourceId("com.android.mms:id/embedded_text_editor"));
            typeMessage.setText("hello, my name is fsw!");
            sleep(5000);
            typeMessage.clearTextField();
            
            //通讯地址处这样删除会有问题,需要另外一种方法删除
            UiObject address=new UiObject(new UiSelector().resourceId("com.android.mms:id/recipients_editor"));
    
            //光标移动到末尾,点击backspace键删除
            address.setText("15288810187");
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_END);
            while(address.getText() != "") {
                UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_DEL);
            }
            
            //光标移动到开始,使用delete见删除
            address.setText("15288810187");
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_HOME);
            while(address.getText() != "") {
                UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_FORWARD_DEL);
            }
            
        }
    
    }
    Demo.java
  • 相关阅读:
    关于C#静态函数什么时候被调用的问题
    Visual Studio调试之断点技巧篇
    使用MPLex实现语法高亮显示的功能
    Generate Ellipsoid画椭球用MATLAB
    matlab学习
    12.17 V155 Q169. 机经加感悟。
    GRE阅读
    Matlab7.0程序启动后自动退出问题
    远程打开MATLAB
    Resin是CAUCHO公司的产品,是一个非常流行的application server,对servlet和JSP提供了良好的支持,性能也比较优良,resin自身采用JAVA语言开发。
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4567291.html
Copyright © 2011-2022 走看看