Skip to content

Commit

Permalink
better error handling for jasmine task
Browse files Browse the repository at this point in the history
  • Loading branch information
subtleGradient committed Nov 13, 2013
1 parent f12c428 commit 7c8b70e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions grunt/tasks/webdriver-jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ module.exports = function(){

var desiredCapabilities = {};
if (config.desiredCapabilities) Object.keys(config.desiredCapabilities).forEach(function(key){
if (config.desiredCapabilities[key] === undefined) return;
desiredCapabilities[key] = config.desiredCapabilities[key];
});
grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities));

grunt.verbose.write('webdriver remote', JSON.stringify(config.webdriver.remote));
grunt.verbose.writeln('webdriver remote', JSON.stringify(config.webdriver.remote));
var browser = wd.promiseChainRemote(config.webdriver.remote);

browser.on('status', function(info) {
Expand All @@ -21,28 +23,48 @@ module.exports = function(){
grunt.verbose.writeln(' > ' + meth, path, data || '');
});

var report = null;

// browser._debugPromise();
browser
.init(desiredCapabilities)
.then(config.onStart && config.onStart.bind(config, browser))
.get(config.url)
.then(function(){return browser;})
.then(getJSReport)
.then(config.onComplete && config.onComplete.bind(browser), config.onError && config.onError.bind(browser))
.fail(grunt.verbose.writeln.bind(grunt.verbose))
.fin(function(){
.then(function(data){ report = data; })
.fail(function(error){
grunt.log.error(error);
return browser
.eval('document.documentElement.innerText || document.documentElement.textContent')
.then(grunt.verbose.writeln.bind(grunt.verbose))
.then(function(){throw error})
;
})
.finally(function(){
if (grunt.option('webdriver-keep-open')) return;
grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.');
return browser.quit();
})
.done(
taskSucceeded.bind(null,true),
taskSucceeded.bind(null,false)
function(){
if (config.onComplete) config.onComplete(report);
taskSucceeded(true);
},
function(error){
if (config.onError) config.onError(error);
taskSucceeded(false);
}
)
;
}

function getJSReport(browser){
return browser
.waitForCondition("typeof window.jasmine != 'undefined'", 500)
.fail(function(error){
throw Error("The test page didn't load properly. " + error);
})
.waitForCondition("typeof window.jasmine.getJSReport != 'undefined'", 10e3)
.waitForCondition("window.testImageURL.running <= 0", 5e3)
.eval("jasmine.getJSReport()")
Expand Down

0 comments on commit 7c8b70e

Please sign in to comment.