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();

    }
}
相关推荐
钛态1 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
王码码20351 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
左手厨刀右手茼蒿2 小时前
Flutter for OpenHarmony: Flutter 三方库 shamsi_date 助力鸿蒙应用精准适配波斯历法(中东出海必备)
android·flutter·ui·华为·自动化·harmonyos
代码飞天2 小时前
wireshark的高级使用
android·java·wireshark
2501_915918413 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
skiy3 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
小小小点4 小时前
Android四大常用布局详解与实战
android
MinQ5 小时前
binder和socket区别及原理
android
Ehtan_Zheng5 小时前
Jetpack Compose 中绘制发光边框的多种方式
android
智塑未来5 小时前
像素蛋糕安卓版 AI 专业修图全场景输出高清成片
android·人工智能