uiautomator案例

test下新建类

复制代码
public class ButtonClickTest {
    private UiDevice device;

    @Before
    public void setUp() {
        // 初始化 UiDevice 实例
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        try {
            device.executeShellCommand("am start -n com.yy.test/.MainActivity"); //启动,包名,Activity名
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testButtonClick() throws UiObjectNotFoundException {

        UiObject user = device.findObject(new UiSelector().resourceId("com.yy.test:id/user"));
        user.clearTextField();
        user.setText("admin");

        UiObject pass = device.findObject(new UiSelector().resourceId("com.yy.test:id/pass"));
        pass.clearTextField();
        pass.setText("123456");

        UiObject button = device.findObject(new UiSelector().resourceId("com.yy.test:id/btnLogin"));
        button.click();

    }
}
相关推荐
CV资深专家4 小时前
在 Android 框架中,接口的可见性规则
android
daifgFuture8 小时前
Android 3D球形水平圆形旋转,旋转动态更换图片
android·3d
二流小码农9 小时前
鸿蒙开发:loading动画的几种实现方式
android·ios·harmonyos
爱吃西红柿!10 小时前
fastadmin fildList 动态下拉框默认选中
android·前端·javascript
悠哉清闲11 小时前
工厂模式与多态结合
android·java
大耳猫11 小时前
Android SharedFlow 详解
android·kotlin·sharedflow
火柴就是我12 小时前
升级 Android Studio 后报错 Error loading build artifacts from redirect.txt
android
androidwork13 小时前
掌握 MotionLayout:交互动画开发
android·kotlin·交互
奔跑吧 android13 小时前
【android bluetooth 协议分析 14】【HFP详解 1】【案例一: 手机侧显示来电,但车机侧没有显示来电: 讲解AT+CLCC命令】
android·hfp·aosp13·telecom·ag·hf·headsetclient
Chenyu_31014 小时前
09.MySQL内外连接
android·数据库·mysql