自学内容网 自学内容网

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

    }
}

原文地址:https://blog.csdn.net/m0_60277871/article/details/143981460

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!