Appium-UIAutomator2-Java代码在测试中可以直接运行,但在被测试中调用的函数中无法运行。
创始人
2024-09-10 10:00:05
0

一种可能的解决方法是确保UIAutomator2框架实例始终在同一个线程中使用。此外,您也可以尝试将函数的返回类型设置为布尔值,并在函数结束时返回true或false,以检查是否成功启动了UIAutomator2框架实例。以下是可能的代码示例:

public class SampleTest { private AndroidDriver driver; private UiAutomator2DriverLocalService uiAutomatorService;

@BeforeMethod
public void setup() {
    //启动Appium服务
    AppiumServiceBuilder builder = new AppiumServiceBuilder();
    AppiumDriverLocalService service = builder.build();
    service.start();

    //启动UIAutomator2服务
    uiAutomatorService = new UiAutomator2DriverLocalService.Builder().build();
    uiAutomatorService.start();

    //跨进程与设备建立链接
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("platformName", "Android");
    caps.setCapability("deviceName", "device");
    caps.setCapability("appPackage", "com.example.app");
    caps.setCapability("appActivity", "MainActivity");
    caps.setCapability("automationName", "UiAutomator2");
    driver = new AndroidDriver<>(service.getUrl(), caps);
}

@AfterMethod
public void teardown() {
    //关闭UIAutomator2服务
    if (uiAutomatorService != null) {
        uiAutomatorService.stop();
    }

    //关闭Appium服务
    if (driver != null) {
        driver.quit();
    }
}

@Test
public void testWithDirectMethod() {
    // 测试通过直接方法调用启动UIAutomator2服务
    UiObjectFinder.find("text").click();
    //测试逻辑
}

@Test
public void testWithFunctionCall() {
    // 测试在函数中调用启动UIAutomator2服务
    boolean isUiAutomatorStarted = startUiAutomatorService();
    Assert.assertTrue

相关内容

热门资讯

2026版辅助挂!德普之星透视... 2026版辅助挂!德普之星透视辅助软件,德普之星透视辅助软件,果然真的是有挂(了解有挂)1、点击下载...
我来教教大家!凑一桌开挂,杭州... 我来教教大家!凑一桌开挂,杭州都莱游戏辅助,详细插件(真是有挂)1、杭州都莱游戏辅助脚本辅助下载、杭...
网友热议!pokemmo脚本最... 网友热议!pokemmo脚本最新版,德普之星辅助器怎么用,确实存在有挂(有挂神器)1、金币登录送、破...
发现一款!哈局八张辅助,微信小... 发现一款!哈局八张辅助,微信小程序辅助新天道辅助,详细脚本(有挂功能)1、下载好微信小程序辅助新天道...
近年来!wepoker私人局透... 近年来!wepoker私人局透视,智星菠萝透视,总是真的有挂(有挂攻略)1、起透看视 智星菠萝透视辅...
玩家必看秘籍!蛮王大厅脚本辅助... 玩家必看秘籍!蛮王大厅脚本辅助,创思维激k有挂吗,详细器(有挂秘笈)1、操作简单,无需蛮王大厅脚本辅...
推出新举措!佛手大菠萝有挂吗,... 推出新举措!佛手大菠萝有挂吗,智星德州插件,其实存在有挂(有挂秘籍)1、任何智星德州插件透视是真的假...
揭秘攻略!闲来透视辅助器最新版... 揭秘攻略!闲来透视辅助器最新版,欢聚水鱼天下辅助,详细技巧(有挂解密)1、游戏颠覆性的策略玩法,独创...
刚刚!wepokerplus辅... 刚刚!wepokerplus辅助,德扑之星私人局辅助器,总是真的有挂(确实有挂)1、任何德扑之星私人...
玩家必备攻略!陕西三代二破解,... 玩家必备攻略!陕西三代二破解,微信小程序中至上饶510k辅助器,详细器(确实有挂)一、微信小程序中至...