browser.saveScreenshot() 在调用时挂起 [英] browser.saveScreenshot() hangs when called
问题描述
我正在为 Cordova 应用程序编写自动化测试.我想保存每个页面的截图,这是我的代码.
Hi I am writing automation tests for a Cordova application. I want to save screenshots of each page, here is my code.
it("should take screenshot", function() {
return browser.contexts().then(function(cnt){
console.log(cnt[1]);
return browser.context(cnt[1]);
}).then(function(){
return browser.saveScreenshot("/Users/User/Documents/dev/engineerappcopy/VGimages/nexLogin.png")
});
});
这是我的 Appium 控制台:
Here is my Appium console:
[HTTP] --> GET /wd/hub/session/610d95af-6501-4c72-ac38-0184a8608dfd/screenshot {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [GET /wd/hub/session/610d95af-6501-4c72-ac38-0184a8608dfd/screenshot] to [GET http://127.0.0.1:9515/wd/hub/session/4d5f3f8a24e28f7fbf65eebc47cc02d8/screenshot] with body: {}
[HTTP] --> GET /wd/hub/status {}
[MJSONWP] Calling AppiumDriver.getStatus() with args: []
[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 14 ms - 83
我是自动化和 JS 的新手,感谢您的建议.
Im new to automation and JS, thanks for any advice.
推荐答案
事实证明 savescreenshot() 与cordova 应用程序不兼容.不过我确实找到了解决方案!
It turns out savescreenshot(), is not compatible with cordova applications. However I did find a solution!
使用这些命令,我们可以直接从模拟器中截取屏幕截图:
Using these commands we can take a screen shot directly from the emulator:
adb pull /sdcard/screenshot.png screenshot.png
adb shell /system/bin/screencap -p /sdcard/screenshot.png
那么我们如何以编程方式做到这一点呢?好吧,nodeJS 有child_process",它可以向终端调用命令!
So how can we do this programmatically? well nodeJS has 'child_process' which can call commands to the terminal!
it("should take screenshot", function() {
const exec = require('child_process').exec;
exec('adb shell /system/bin/screencap -p /sdcard/tester.png', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
exec('adb pull /sdcard/tester.png tester.png', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
});
所以使用像这样的东西^,我可以截取一个保存到模拟器sd卡的截图,然后把这个截图拉到我的目录中!
So using something like this ^, I can take a screenshot that is saved to the emulators sd card, and then pull this screenshot onto my directory!
这篇关于browser.saveScreenshot() 在调用时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!