@samitouri / QOS-React-2 / commits / 7c8b70eedb

better error handling for jasmine task

Thomas Aylott committed Nov 8, 2013 at 16:29 UTC 7c8b70eedbceb63a67baac6cd3e6fcac8a136838
1 file changed +28 -6
grunt/tasks/webdriver-jasmine.js
+28 -6
@@ -7,10 +7,12 @@ module.exports = function(){
7
8 var desiredCapabilities = {};
9 if (config.desiredCapabilities) Object.keys(config.desiredCapabilities).forEach(function(key){
10 + if (config.desiredCapabilities[key] === undefined) return;
11 desiredCapabilities[key] = config.desiredCapabilities[key];
12 });
13 + grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities));
14
13 - grunt.verbose.write('webdriver remote', JSON.stringify(config.webdriver.remote));
15 + grunt.verbose.writeln('webdriver remote', JSON.stringify(config.webdriver.remote));
16 var browser = wd.promiseChainRemote(config.webdriver.remote);
17
18 browser.on('status', function(info) {
@@ -21,21 +23,38 @@ module.exports = function(){
23 grunt.verbose.writeln(' > ' + meth, path, data || '');
24 });
25
26 + var report = null;
27 +
28 + // browser._debugPromise();
29 browser
30 .init(desiredCapabilities)
31 + .then(config.onStart && config.onStart.bind(config, browser))
32 .get(config.url)
33 .then(function(){return browser;})
34 .then(getJSReport)
29 - .then(config.onComplete && config.onComplete.bind(browser), config.onError && config.onError.bind(browser))
30 - .fail(grunt.verbose.writeln.bind(grunt.verbose))
31 - .fin(function(){
35 + .then(function(data){ report = data; })
36 + .fail(function(error){
37 + grunt.log.error(error);
38 + return browser
39 + .eval('document.documentElement.innerText || document.documentElement.textContent')
40 + .then(grunt.verbose.writeln.bind(grunt.verbose))
41 + .then(function(){throw error})
42 + ;
43 + })
44 + .finally(function(){
45 if (grunt.option('webdriver-keep-open')) return;
46 grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.');
47 return browser.quit();
48 })
49 .done(
37 - taskSucceeded.bind(null,true),
38 - taskSucceeded.bind(null,false)
50 + function(){
51 + if (config.onComplete) config.onComplete(report);
52 + taskSucceeded(true);
53 + },
54 + function(error){
55 + if (config.onError) config.onError(error);
56 + taskSucceeded(false);
57 + }
58 )
59 ;
60 }
@@ -43,6 +62,9 @@ module.exports = function(){
62 function getJSReport(browser){
63 return browser
64 .waitForCondition("typeof window.jasmine != 'undefined'", 500)
65 + .fail(function(error){
66 + throw Error("The test page didn't load properly. " + error);
67 + })
68 .waitForCondition("typeof window.jasmine.getJSReport != 'undefined'", 10e3)
69 .waitForCondition("window.testImageURL.running <= 0", 5e3)
70 .eval("jasmine.getJSReport()")