CB-11162 Appium tests: retry spec on failure

This commit is contained in:
Alexander Sorokin 2016-04-27 18:02:48 +03:00
parent d4a55f20ec
commit 57b177f3fb

View File

@ -157,7 +157,7 @@ describe('Camera tests Android.', function () {
}) })
.fail(function (failure) { .fail(function (failure) {
console.log(failure); console.log(failure);
fail(failure); throw failure;
}); });
} }
@ -170,30 +170,20 @@ describe('Camera tests Android.', function () {
.executeAsync(cameraHelper.checkPicture, [getCurrentPromiseId()]) .executeAsync(cameraHelper.checkPicture, [getCurrentPromiseId()])
.then(function (result) { .then(function (result) {
if (shouldLoad) { if (shouldLoad) {
expect(result.length).toBeGreaterThan(0); if (result.length === 0) {
throw 'The result is an empty string.';
}
if (result.indexOf('ERROR') >= 0) { if (result.indexOf('ERROR') >= 0) {
return fail(result); throw result;
} }
} else { } else {
if (result.indexOf('ERROR') === -1) { if (result.indexOf('ERROR') === -1) {
return fail('Unexpected success callback with result: ' + result); throw 'Unexpected success callback with result: ' + result;
} }
expect(result.indexOf('ERROR')).toBe(0);
} }
}); });
} }
function runCombinedSpec(spec) {
return driver
.then(function () {
return getPicture(spec.options);
})
.then(function () {
return checkPicture(true);
})
.fail(saveScreenshotAndFail);
}
// deletes the latest image from the gallery // deletes the latest image from the gallery
function deleteImage() { function deleteImage() {
var holdTile = new wd.TouchAction(); var holdTile = new wd.TouchAction();
@ -229,6 +219,41 @@ describe('Camera tests Android.', function () {
}); });
} }
function recreateSession() {
return driver
.quit()
.finally(function () {
return getDriver();
});
}
function tryRunSpec(spec) {
return driver
.then(spec)
.fail(function () {
return recreateSession()
.then(spec)
.fail(function() {
return recreateSession()
.then(spec);
});
})
.fail(saveScreenshotAndFail);
}
function runCombinedSpec(s) {
var spec = function () {
return driver
.then(function () {
return getPicture(s.options);
})
.then(function () {
return checkPicture(true);
});
};
return tryRunSpec(spec);
}
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() getDriver()
.fail(fail) .fail(fail)
@ -253,30 +278,34 @@ describe('Camera tests Android.', function () {
describe('Specs.', function () { describe('Specs.', function () {
// getPicture() with saveToPhotoLibrary = true // getPicture() with saveToPhotoLibrary = true
it('camera.ui.spec.1 Saving the picture to photo library', function (done) { it('camera.ui.spec.1 Saving a picture to the photo library', function (done) {
var spec = function() {
var options = { var options = {
quality: 50, quality: 50,
allowEdit: false, allowEdit: false,
sourceType: cameraConstants.PictureSourceType.CAMERA, sourceType: cameraConstants.PictureSourceType.CAMERA,
saveToPhotoAlbum: true saveToPhotoAlbum: true
}; };
driver return driver
.then(function () { .then(function () {
return getPicture(options); return getPicture(options);
}) })
.then(function () { .then(function () {
isTestPictureSaved = true; isTestPictureSaved = true;
return checkPicture(true); return checkPicture(true);
}) });
.fail(saveScreenshotAndFail) };
return tryRunSpec(spec)
.done(done); .done(done);
}, 3 * MINUTE); }, 10 * MINUTE);
// getPicture() with mediaType: VIDEO, sourceType: PHOTOLIBRARY // getPicture() with mediaType: VIDEO, sourceType: PHOTOLIBRARY
it('camera.ui.spec.2 Selecting only videos', function (done) { it('camera.ui.spec.2 Selecting only videos', function (done) {
var spec = function () {
var options = { sourceType: cameraConstants.PictureSourceType.PHOTOLIBRARY, var options = { sourceType: cameraConstants.PictureSourceType.PHOTOLIBRARY,
mediaType: cameraConstants.MediaType.VIDEO }; mediaType: cameraConstants.MediaType.VIDEO };
driver return driver
.then(function () { .then(function () {
return getPicture(options, true); return getPicture(options, true);
}) })
@ -315,19 +344,21 @@ describe('Camera tests Android.', function () {
// error means we're already in webview // error means we're already in webview
return driver; return driver;
}); });
}) });
.fail(saveScreenshotAndFail) };
return tryRunSpec(spec)
.done(done); .done(done);
}, 3 * MINUTE); }, 10 * MINUTE);
// getPicture(), then dismiss // getPicture(), then dismiss
// wait for the error callback to be called // wait for the error callback to be called
it('camera.ui.spec.3 Dismissing the camera', function (done) { it('camera.ui.spec.3 Dismissing the camera', function (done) {
var spec = function () {
var options = { quality: 50, var options = { quality: 50,
allowEdit: true, allowEdit: true,
sourceType: cameraConstants.PictureSourceType.CAMERA, sourceType: cameraConstants.PictureSourceType.CAMERA,
destinationType: cameraConstants.DestinationType.FILE_URI }; destinationType: cameraConstants.DestinationType.FILE_URI };
driver return driver
.then(function () { .then(function () {
return getPicture(options, true); return getPicture(options, true);
}) })
@ -336,19 +367,22 @@ describe('Camera tests Android.', function () {
.click() .click()
.then(function () { .then(function () {
return checkPicture(false); return checkPicture(false);
}) });
.fail(saveScreenshotAndFail) };
return tryRunSpec(spec)
.done(done); .done(done);
}, 3 * MINUTE); }, 10 * MINUTE);
// getPicture(), then take picture but dismiss the edit // getPicture(), then take picture but dismiss the edit
// wait for the error callback to be called // wait for the error callback to be called
it('camera.ui.spec.4 Dismissing the edit', function (done) { it('camera.ui.spec.4 Dismissing the edit', function (done) {
var spec = function () {
var options = { quality: 50, var options = { quality: 50,
allowEdit: true, allowEdit: true,
sourceType: cameraConstants.PictureSourceType.CAMERA, sourceType: cameraConstants.PictureSourceType.CAMERA,
destinationType: cameraConstants.DestinationType.FILE_URI }; destinationType: cameraConstants.DestinationType.FILE_URI };
driver return driver
.then(function () { .then(function () {
return getPicture(options, true); return getPicture(options, true);
}) })
@ -361,20 +395,21 @@ describe('Camera tests Android.', function () {
.click() .click()
.then(function () { .then(function () {
return checkPicture(false); return checkPicture(false);
}) });
.fail(saveScreenshotAndFail) };
return tryRunSpec(spec)
.done(done); .done(done);
}, 3 * MINUTE); }, 10 * MINUTE);
// combine various options for getPicture() // combine various options for getPicture()
generateSpecs().forEach(function (spec) { generateSpecs().forEach(function (spec) {
it('camera.ui.spec.5.' + spec.id + ' Combining options. ' + spec.description, function (done) { it('camera.ui.spec.5.' + spec.id + ' Combining options. ' + spec.description, function (done) {
runCombinedSpec(spec) runCombinedSpec(spec)
.done(done); .done(done);
}, 3 * MINUTE); }, 10 * MINUTE);
}); });
it('camera.ui.util Delete test image from device library', function (done) { it('camera.ui.util Delete test image from device library', function (done) {
if (!isTestPictureSaved) { if (!isTestPictureSaved) {
// couldn't save test picture earlier, so nothing to delete here // couldn't save test picture earlier, so nothing to delete here