added screenshotWaitTimeout cap

This commit is contained in:
sebv
2014-11-06 18:08:47 +08:00
parent 7d76daaa4b
commit b7542d3f97
3 changed files with 47 additions and 28 deletions

View File

@@ -79,3 +79,4 @@
|`interKeyDelay`| The delay, in ms, between keystrokes sent to an element when typing.|e.g., `100`|
|`showIOSLog`| Whether to show any logs captured from a device in the appium logs. Default `false`|`true` or `false`|
|`sendKeyStrategy`| strategy to use to type test into a test field. Simulator default: `oneByOne`. Real device default: 'grouped' |`oneByOne`, `grouped` or setValue|
|`screenshotWaitTimeout`| Max timeout in sec to wait for a screenshot to be generated. default: 10 |e.g., `5`|

View File

@@ -1232,24 +1232,26 @@ iOSController.getScreenshot = function (cb) {
function (cb) { this.getOrientation(function () { cb(); }); }.bind(this),
function (cb) { this.proxy(command, cb); }.bind(this),
function (response, cb) {
var data = null;
var count = 0;
var data;
var screenshotWaitTimeout = (this.args.screenshotWaitTimeout || 10) * 1000;
logger.debug('Waiting ' + screenshotWaitTimeout + ' ms for screenshot to ge generated.');
var startMs = Date.now();
var lastErr;
async.until(
function () { return data; },
function () { return data || Date.now() - startMs > screenshotWaitTimeout; },
function (cb) {
setTimeout(function () {
fs.readFile(shotPath, function (err, _data) {
if (err && ++count > 20) {
return cb(new Error("Timed out waiting for screenshot file. " + err.toString()));
}
if (!err) {
data = _data;
}
lastErr = err;
if (!err) { data = _data; }
cb();
});
}, 300);
},
function (err) {
if (!data) {
return cb(new Error("Timed out waiting for screenshot file. " + (lastErr || '').toString()));
}
cb(err, response, data);
}
);

View File

@@ -3,27 +3,43 @@
var setup = require("../../common/setup-base");
describe('safari - screenshots @skip-ios6', function () {
var driver;
setup(this, {browserName: 'safari'}).then(function (d) { driver = d; });
describe('default' ,function () {
var driver;
setup(this, {browserName: 'safari'}).then(function (d) { driver = d; });
it('should get an app screenshot', function (done) {
driver
.takeScreenshot()
.should.eventually.exist
it('should get an app screenshot', function (done) {
driver
.takeScreenshot()
.should.eventually.exist
.nodeify(done);
});
it('should get an app screenshot in landscape mode', function (done) {
driver.takeScreenshot().then(function (screenshot1) {
screenshot1.should.exist;
return driver
.setOrientation("LANDSCAPE")
// A useless error does often exist here, let's ignore it
.catch(function () {})
.takeScreenshot().then(function (screenshot2) {
screenshot2.should.exist;
screenshot2.should.not.eql(screenshot1);
});
}).sleep(3000) // cooldown
.nodeify(done);
});
});
it('should get an app screenshot in landscape mode', function (done) {
driver.takeScreenshot().then(function (screenshot1) {
screenshot1.should.exist;
return driver
.setOrientation("LANDSCAPE")
// A useless error does often exist here, let's ignore it
.catch(function () {})
.takeScreenshot().then(function (screenshot2) {
screenshot2.should.exist;
screenshot2.should.not.eql(screenshot1);
});
}).sleep(3000) // cooldown
.nodeify(done);
describe('setting screenshotWaitTimeout' ,function () {
var driver;
setup(this, {browserName: 'safari', screenshotWaitTimeout: 5})
.then(function (d) { driver = d; });
it('should get an app screenshot', function (done) {
driver
.takeScreenshot()
.should.eventually.exist
.nodeify(done);
});
});
});