Appium Android模拟器无法关闭或使测试失败

山姆·埃利斯

我有一个针对我要运行的Appium测试,并使用库存浏览器运行了Android Emulator。该测试在iOS上通过,但在Android上却无法通过,因为Android似乎比iOS对元素定位器更为挑剔。

无论如何,我的问题是我希望它在这一点上失败,因为它找不到尝试单击的元素,但是测试只是挂起(大约10分钟,然后被套接字超时杀死),并且不会导致测试失败。仿真器保持打开状态,并且测试似乎正在继续运行。

我已经通过npm安装了最新版本的Appium。

这是我想要的功能:

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "browser");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("takesScreenshot", true);
        capabilities.setCapability("version", "5.1.1");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("avd", "nexus5");
        webDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                                      capabilities);

我的Appium日志显示以下内容:

        info: Got response with status 200: {"sessionId":"27038f591907917c7f2c1ce48db7d032","status":13,"value":{"message":"unknown error: Element is not clickable at point (342, 32). Other element would receive the click: <button class=\"butto...
        info: <-- POST /wd/hub/session/27038f591907917c7f2c1ce48db7d032/element/0.9723546949680895-1/click 200 825.852 ms - 381 
        info: --> GET /wd/hub/session/27038f591907917c7f2c1ce48db7d032/screenshot {}
        info: Proxying [GET /wd/hub/session/27038f591907917c7f2c1ce48db7d032/screenshot] to [GET http://127.0.0.1:9515/wd/hub/session/27038f591907917c7f2c1ce48db7d032/screenshot] with body: {}
        info: [debug] Didn't get a new command in 30 secs, shutting down...
        info: Shutting down appium session
        info: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/27038f591907917c7f2c1ce48db7d032] with no body

我希望我的测试由于无法单击该元素而在此时退出。有人可以提供任何建议吗?

谢谢

更新

在捕获屏幕快照的地方添加了代码,这看起来像是导致测试挂起的原因:

  public void captureScreenshot(String methodName) {
                try {
                    new File(screenshotDirectory).mkdirs();
                    String filename = methodName + ".png";
                    File screenshot = ((TakesScreenshot) webDriverService.getWebDriver()).getScreenshotAs(OutputType.FILE);
                    FileUtils.copyFile(screenshot, new File(screenshotDirectory + filename));
                } catch (Exception e) {
                    System.out.println(e.toString());
                }
            }
山姆·埃利斯

设法修复它必须使用稍微不同的代码段才能在android上截屏:

        public void captureScreenshot(String methodName) {
            try {
                new File(screenshotDirectory).mkdirs();
                String filename = methodName + ".png";
                AppiumDriver webDriver = (AppiumDriver) webDriverService.getWebDriver();
                webDriver.context("NATIVE_APP");
                File screenshot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot, new File(screenshotDirectory + filename));
            } catch (Exception e) {
                System.out.println(e.toString());
            }
        }
    };

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过Appium JUnit测试监视iOS模拟器/ Android模拟器的HTTP流量?

无法通过appium在android模拟器中启动计算器

在远程VPS上运行Appium和Android模拟器

错误:uncaughtException:无法从Appium for Android模拟器读取null的属性“ sockets”

无法通过android模拟器在appium中启动apk文件

Nightwatch / Appium配置,用于在iOS模拟器上测试浏览器

使用 Appium 在模拟器上测试 iOS 应用程序 - 找不到元素

用于滑动的 TouchAction 无法运行 iOS 模拟器 - Appium Java

阻止iOS模拟器通过appium重启的方法

引导ios模拟器后,Appium Desktop终止

在Android模拟器上通过appium或adb启用“ show_touches”

如何在带有Appium的Android模拟器中禁用互联网连接?

无法在Android 7.0上运行Appium测试

无法安装Appium

Appium测试启动在多个设备上失败

无法使用 appium 打开或关闭数据

Appium / Wdio-无法关闭Android上的位置权限警报

使用Appium测试NativeScript应用

通过appium脚本使用telnet关闭Android仿真器

Appium Inspector无法加载图像

如何在Appium服务器上终止Appium会话

将 appium 设置更改为在模拟器中没有应用程序的全新状态

Appium无法在Android上的Expo App上开始测试

使用Appium对Android应用进行黑色测试

使用Appium的Xpath for Android元素

Android Appium WebDriverWait引发NoSuchMethodError

运行测试后如何关闭Android SDK模拟器

Appium无法在Android设备上找到按钮

无法使用Appium移动Android SeekBar