browser.saveScreenshot() hangs when called

三世轮回 提交于 2019-12-12 04:30:49

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/41086403/browser-savescreenshot-hangs-when-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!