CB-10750 Appium tests: fail fast if session is irrecoverable

This commit is contained in:
Alexander Sorokin 2016-03-01 18:27:08 +03:00
parent 2cd2528d1c
commit d51e23ad7b
2 changed files with 30 additions and 17 deletions

View File

@ -26,9 +26,11 @@ describe('Camera tests Android.', function () {
var webviewContext = DEFAULT_WEBVIEW_CONTEXT; var webviewContext = DEFAULT_WEBVIEW_CONTEXT;
// this indicates that the device library has the test picture: // this indicates that the device library has the test picture:
var isTestPictureSaved = false; var isTestPictureSaved = false;
// this indicates that there was a critical error and tests cannot continue: // this indicates that there was a critical error and we should try to recover:
var errorFlag = false;
// this indicates that we couldn't restore Appium session and should fail fast:
var stopFlag = false; var stopFlag = false;
// we need to know the screen width and height to properly click on an image in the gallery // we need to know the screen width and height to properly click on an image in the gallery:
var screenWidth = DEFAULT_SCREEN_WIDTH; var screenWidth = DEFAULT_SCREEN_WIDTH;
var screenHeight = DEFAULT_SCREEN_HEIGHT; var screenHeight = DEFAULT_SCREEN_HEIGHT;
@ -168,7 +170,7 @@ describe('Camera tests Android.', function () {
.execute('window.location = "../index.html"') .execute('window.location = "../index.html"')
.sleep(5000) .sleep(5000)
.fail(function () { .fail(function () {
stopFlag = true; errorFlag = true;
throw 'Couldn\'t find start page.'; throw 'Couldn\'t find start page.';
}); });
}, function () { }, function () {
@ -261,7 +263,7 @@ describe('Camera tests Android.', function () {
// we should try to recreate the session for the following tests // we should try to recreate the session for the following tests
if (msg.indexOf('Error response status: 6') >= 0 || if (msg.indexOf('Error response status: 6') >= 0 ||
msg.indexOf('Error response status: 7') >= 0) { msg.indexOf('Error response status: 7') >= 0) {
stopFlag = true; errorFlag = true;
} }
return result; return result;
} }
@ -271,7 +273,13 @@ describe('Camera tests Android.', function () {
}); });
it('camera.ui.util configuring driver and starting a session', function (done) { it('camera.ui.util configuring driver and starting a session', function (done) {
getDriver().then(done); stopFlag = true; // just in case of timeout
getDriver().then(function () {
stopFlag = false;
}, function (error) {
fail(error);
})
.finally(done);
}, 5 * MINUTE); }, 5 * MINUTE);
it('camera.ui.util determine webview context name', function (done) { it('camera.ui.util determine webview context name', function (done) {
@ -316,19 +324,14 @@ describe('Camera tests Android.', function () {
describe('Specs.', function () { describe('Specs.', function () {
beforeEach(function (done) { beforeEach(function (done) {
// prepare the app for the test
if (!stopFlag) { if (!stopFlag) {
return driver return driver
.context(webviewContext) .context(webviewContext)
.then(function () { .then(function () {
return driver; // no-op return driver; // no-op
}, function (error) { }, function (error) {
if (error.message.indexOf('Error response status: 6') >= 0) {
// the session has expired but we can fix this!
console.log('The session has expired. Trying to start a new one...');
return getDriver();
} else {
expect(true).toFailWithMessage(error); expect(true).toFailWithMessage(error);
}
}) })
.execute('document.getElementById("info").innerHTML = "' + STARTING_MESSAGE + '";') .execute('document.getElementById("info").innerHTML = "' + STARTING_MESSAGE + '";')
.finally(done); .finally(done);
@ -337,20 +340,30 @@ describe('Camera tests Android.', function () {
}, 3 * MINUTE); }, 3 * MINUTE);
afterEach(function (done) { afterEach(function (done) {
if (!stopFlag) { if (!errorFlag || stopFlag) {
// either there's no error or we've failed irrecoverably
// nothing to worry about!
done(); done();
return; return;
} }
// recreate the session if there was a critical error in the spec // recreate the session if there was a critical error in a previous spec
stopFlag = true; // we're going to set this to false if we're able to restore the session
return driver return driver
.quit() .quit()
.then(function () { .then(function () {
return getDriver() return getDriver()
.then(function () { .then(function () {
errorFlag = false;
stopFlag = false; stopFlag = false;
done(); }, function (error) {
}); fail(error);
stopFlag = true;
}); });
}, function (error) {
fail(error);
stopFlag = true;
})
.finally(done);
}, 3 * MINUTE); }, 3 * MINUTE);
// getPicture() with saveToPhotoLibrary = true // getPicture() with saveToPhotoLibrary = true

View File

@ -11,7 +11,7 @@ module.exports.getDriver = function (platform, callback) {
}, },
driverConfig = { driverConfig = {
browserName: '', browserName: '',
'appium-version': '1.3', 'appium-version': '1.5',
platformName: platform, platformName: platform,
platformVersion: global.PLATFORM_VERSION || '', platformVersion: global.PLATFORM_VERSION || '',
deviceName: global.DEVICE_NAME || '', deviceName: global.DEVICE_NAME || '',