I have been utilizing Protractor for my test automation needs. Despite successfully testing my hybrid Android application with Protractor (jasmine) and Appium, I am facing challenges with the browser.takeScreenshot()
function. Interestingly, all other tests such as button clicks are functioning properly.
To rule out any potential plugin-related issues, I created a new blank app. However, even without any Cordova Plugins, the screenshot feature is not working. Surprisingly, I can take screenshots using the device itself.
I have attempted various solutions from platforms like StackOverflow, but none of them have resolved the issue (and it appears that very few people have encountered this problem).
Furthermore, I employed the protractor-jasmin2-screenshot-reporter to check if there was an issue with the screenshot code in my tests, but the result remains consistent. Strangely, when running tests on Chrome by setting browserName: 'Chrome' and navigating to a webpage like www.google.com to capture a screenshot, it works perfectly fine. The problem only arises within my hybrid app environment.
(The
browser.takeScreenshot().then(function (png) {...
code is sourced from official protractor documents and other reputable sources).
Specifications
- Protractor: 5.0.0
- Appium (Desktop Client): 1.4.16.1 (latest version)
- Windows 10 Enterprise 64 Bit
- Chromedriver: 2.27 (latest version)
- Angular: 1.5.3
- Node.js: 6.9.1
- Android: 6.0.1 and 4.4.2 (Galaxy S6 and Alcatel Pixi)
- Cordova 6.4.0
Protractor Configuration (config.js)
exports.config = {
seleniumAddress : 'http://localhost:4723/wd/hub',
capabilities : {
platformVersion : '',
platformName : '',
deviceName : '',
browserName : '',
autoWebview : true,
app : 'C:/Projekte/WifiWizardTestApp/platforms/android/build/outputs/apk/android-debug.apk',
newCommandTimeout : 60
},
baseUrl : 'http://localhost:8080',
onPrepare : function () {
var wd = require('wd');
var protractor = require('protractor');
var wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
},
};
Sample Test Script (test.spec.js)
var fs = require('fs');
describe('Testing the browse state', function () {
it('should be able to take a screenshot', function (done) {
browser.sleep(2000);
browser.takeScreenshot().then(function (png) {
console.log('browser.takeScreenshot()');
var stream = fs.createWriteStream('screenshot.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
done();
});
});
it('should be able to take another screenshot', function () {
browser.takeScreenshot().then(function (png) {
console.log('browser.takeScreenshot()');
var stream = fs.createWriteStream('screenshot2.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
});
Console Output (Android 6.0.1)
C:\Projekte\WifiWizardTestApp>protractor protractor.config.js --specs tests/browse.spec.js
[09:27:44] I/hosted - Using the selenium server at http://localhost:4723/wd/hub
[09:27:44] I/launcher - Running 1 instances of WebDriver
Started
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
FA Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
Failures:
1) Testing the browse state should be able to take a screenshot
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
...
Console Output (Android 4.4.2)
C:\Projekte\WifiWizardTestApp>protractor protractor.config.js --specs tests/browse.spec.js
[15:15:49] I/hosted - Using the selenium server at http://localhost:4723/wd/hub
[15:15:49] I/launcher - Running 1 instances of WebDriver
Started
FF
Failures:
1) Testing the browse state should be able to take a screenshot
Message:
Failed: unknown error: unhandled inspector error: {"code":-32603,"message":"Unable to capture screenshot"}
...