我正在尝试使用股票浏览器运行的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());
}
}
答案 0 :(得分:1)
(我最初在这里发布了这个答案:https://discuss.appium.io/t/appium-hangs-when-taking-a-screenshot-android/5318/4?u=savishy)
我知道这是一个稍微陈旧的主题,但是使用Appium Java客户端3.2.0,我遇到了这个问题,并且认为我会使用我的解决方案。
这是挂起发生的代码行。我知道因为之前的log.debug
行被打印出来了。
log.debug(filePath);
File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
这是Appium Server Log:
2015-11-26 09:20:03:085 - info: <-- POST /wd/hub/session/93df24a9-1b33-49c8-aea1-b3b768f21d97/element 200 1210.866 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"93df24a9-1b33-49c8-aea1-b3b768f21d97"}
2015-11-26 09:20:03:101 - info: --> GET /wd/hub/session/93df24a9-1b33-49c8-aea1-b3b768f21d97/screenshot {}
2015-11-26 09:20:03:103 - debug: executing cmd: D:\vish\adt-bundle\sdk\platform-tools\adb.exe -s TA64303N7W shell "/system/bin/rm /data/local/tmp/screenshot.png; /system/bin/screencap -p /data/local/tmp/screenshot.png "
进一步调试:查看/ data / local / tmp
我看了/data/local/tmp
设备文件夹。以下是内容,权限和时间戳:
$ adb shell ls -l /data/local/tmp
-rw-rw-rw- shell shell 20456741 2015-11-25 21:41 0978df74a3eeb9a231b2e0cb5a1f7e73.apk
-rw-rw-rw- shell shell 48797 2015-10-10 03:23 AppiumBootstrap.jar
-rw-rw-rw- shell shell 2554 2015-07-25 23:40 UIAutomatorTest.jar
drwxrwxrwx shell shell 2015-07-25 23:36 dalvik-cache
-rw------- root root 8529 2015-11-18 15:38 dump.xml
drwx------ shell shell 2015-08-07 16:37 local
drwxrwxrwx shell shell 2015-10-14 15:33 mobizen
-rw-rw-r-- root root 379501 2015-11-18 15:38 screenshot.png
-rw-rw-rw- shell shell 53503 2015-11-26 14:49 strings.json
-rw------- shell shell 13965 2015-11-19 14:20 uidump.xml
如您所见,大约一周前有一个文件screenshot.png
。 (可能是由旧的Appium Java运行捕获的)。
下一步:尝试使用adb shell手动删除
下一步 - 我尝试使用Appium使用的确切adb shell
命令删除此文件。这是输出。注意来自shell的提示?
vish@freeman /cygdrive/d/vish/ma-app-verification-android/appium-projects/AppiumAndroid
$ adb -s TA64303N7W shell "/system/bin/rm /data/local/tmp/screenshot.png"
override rw-rw-r-- root:root for '/data/local/tmp/screenshot.png'?
(鼓辊)
上面提到的提示是导致Appium挂起的原因。
幸运的是,我的手机已经根植了,所以我能够以root身份手动删除有问题的屏幕截图:
vish@freeman /cygdrive/d/vish/ma-app-verification-android/appium-projects/AppiumAndroid
$ adb root
vish@freeman /cygdrive/d/vish/ma-app-verification-android/appium-projects/AppiumAndroid
$ adb shell rm /data/local/tmp/screenshot.png
答案 1 :(得分:0)
管理修复它必须使用稍微不同的代码才能在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());
}
}
};