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

    }
}
相关推荐
MasterLi80238 分钟前
我的读书清单
android·linux·学习
怪兽201429 分钟前
fastjson在kotlin不使用kotlin-reflect库怎么使用?
android·开发语言·kotlin
彭同学学习日志34 分钟前
Kotlin Fragment 按钮跳转报错解决:Unresolved reference ‘floatingActionButton‘
android·开发语言·kotlin
Gracker2 小时前
Android Perfetto 系列 9 - CPU 信息解读
android
Gracker2 小时前
Android Perfetto 系列 8:深入理解 Vsync 机制与性能分析
android
Gracker2 小时前
Android Perfetto 系列 07 - MainThread 和 RenderThread 解读
android
Gracker2 小时前
Android Perfetto 系列 5:Android App 基于 Choreographer 的渲染流程
android
Gracker2 小时前
Android Perfetto 系列 6:为什么是 120Hz?高刷新率的优势与挑战
android
apigfly3 小时前
Flutter,Compose,Web 在Android平台上从布局到屏幕的机制探究
android·flutter·webview
czhc11400756634 小时前
Java1112 基类 c#vscode使用 程序结构
android·java·数据库