browser.saveScreenshot()在调用时挂起 [英] browser.saveScreenshot() hangs when called
问题描述
您好,我正在为Cordova应用程序编写自动化测试。
我要保存每个页面的截图,这里是我的代码。
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控制台:
[HTTP] - >驱动程序代理活动,通过HTTP代理传递请求
[JSONWP Proxy]代理[GET / wd / hub / session / 610d95af-6501-4c72-ac38-0184a8608dfd / screenshot {}
[MJSONWP] wd / hub / session / 610d95af-6501-4c72-ac38-0184a8608dfd / screenshot]至[GET http://127.0.0.1:9515/wd/hub/session/4d5f3f8a24e28f7fbf65eebc47cc02d8/screenshot] with body:{}
[HTTP] - > GET / wd / hub / status {}
[MJSONWP]使用args调用AppiumDriver.getStatus():[]
[MJSONWP]响应客户端driver.getStatus )result:{build:{version:1.5.3...
[HTTP]< - GET / wd / hub / status 200 14 ms - 83
对于自动化和JS,我感谢任何建议。
解决方案结果savecreenshot(),与cordova应用程序不兼容。
使用这些命令,我们可以直接从模拟器截取屏幕截图:
adb pull /sdcard/screenshot.png screenshot.png
adb shell / system / bin / screencap -p /sdcard/screenshot.png
那么我们如何以编程方式做呢?
well nodeJS有'child_process',可以调用命令到终端!
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;
}
.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卡的屏幕截图,然后将此截图拖到我的目录!
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")
});
});
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
Im new to automation and JS, thanks for any advice.
解决方案 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
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}`);
});
});
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屋!