java 无法设置AndroidDriver,AndroidUIAutomator2无法启动新会话,响应代码为500

mkshixfv  于 2023-05-12  发布在  Java
关注(0)|答案(1)|浏览(243)

我正在使用Appium 2.0.0-beta.61和AndroidUiAutomator2,当我尝试启动Android驱动程序时,它失败了,返回响应代码500。我尝试从设备中删除Appium服务器应用程序,并像其他线程建议的那样使用不同的设备,但没有帮助。
增加 uiautomator2ServerLaunchTimeout 也没有帮助。

[AndroidUiautomator2Driver@9c56 (e03bdf49)] The instrumentation process cannot be initialized within 120000ms timeout. Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of 'uiautomator2ServerLaunchTimeout' capability
10:31:32 SamsungS8Plus [ERROR] Failed to set driver. Closing Appium to prevent it from staying open after test fail. Please check exception below:
10:31:32 SamsungS8Plus [ERROR] Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized within 120000ms timeout. Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of 'uiautomator2ServerLaunchTimeout' capability 
Host info: host: 'INV-15330', ip: '192.168.67.232'
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:adbPort=5037, appium:systemPort=8301, appium:newCommandTimeout=180, appium:androidInstallTimeout=120000, appium:automationName=UIAutomator2, appium:udid=712KPRW1234990, appium:uiautomator2ServerLaunchTimeout=120000, appium:autoGrantPermissions=true, appium:remoteAdbHost=localhost, appium:appActivity=com.unity3d.player.UnityPlayerActivity, platformName=ANDROID, appium:app=C:\Users\Gre\Documents\htautomation\games\Puzzle\Android\Puzzle.apk, appium:uiautomator2ServerInstallTimeout=120000}], desiredCapabilities=Capabilities {appium:adbPort: 5037, appium:androidInstallTimeout: 120000, appium:app: C:\Users\Gre\Doc..., appium:appActivity: com.unity3d.player.UnityPla..., appium:autoGrantPermissions: true, appium:automationName: UIAutomator2, appium:newCommandTimeout: 180, appium:remoteAdbHost: localhost, appium:systemPort: 8301, appium:udid: 712KPRW1234990, appium:uiautomator2ServerInstallTimeout: 120000, appium:uiautomator2ServerLaunchTimeout: 120000, platformName: ANDROID}}]
Capabilities {appium:adbPort: 5037, appium:androidInstallTimeout: 120000, appium:app: C:\Users\Gre\Doc..., appium:appActivity: com.unity3d.player.UnityPla..., appium:autoGrantPermissions: true, appium:automationName: UIAutomator2, appium:newCommandTimeout: 180, appium:remoteAdbHost: localhost, appium:systemPort: 8301, appium:udid: 712KPRW1234990, appium:uiautomator2ServerInstallTimeout: 120000, appium:uiautomator2ServerLaunchTimeout: 120000, platformName: ANDROID}
AppiumServiceBuilder builder;
        builder = new AppiumServiceBuilder()
                .withArgument(GeneralServerFlag.LOG_LEVEL, "error")
                .withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_screen_streaming, chromedriver_autodownload")
                .withIPAddress("127.0.0.1")
                .usingPort(getAppiumServerFromSystemEnv());

        server = AppiumDriverLocalService.buildService(builder);
        server.start();
try {
            driver = new AndroidDriver(server.getUrl(), options);
        } catch (org.openqa.selenium.SessionNotCreatedException e) {
            loggerUtils.log(LoggerLevel.ERROR,"[HTA] Failed to set driver. Closing Appium to prevent it from staying open after test fail. Please check exception below:");
            loggerUtils.log(LoggerLevel.ERROR, e.getMessage());
            closeAppiumServer();
        }

我想在真实的的设备上启动一个android应用程序。使用Appium2和AndroidUiAutomator2。AndroidDriver无法初始化,发生超时并返回响应代码500。

v1l68za4

v1l68za41#

所以我找到了解决问题的办法。我以前

UiAutomator2Options.setRemoteAdbHost("localhost")

这就是问题所在我真的不知道为什么,因为“localhost”是默认值。但是把它改成

UiAutomator2Options.setRemoteAdbHost("127.0.0.1")

帮我解决了这个问题会话已正确启动。

相关问题