2017-01-16 89 views
0

我使用wdio工具從webdriver.io npm包運行摩卡測試用例。Webdriver.io如何將數據發送到自定義記者

這裏是wdio.conf.js部分:

var htmlReporter = require('./js/reporter/htmlReporter'); 
htmlReporter.reporterName = 'htmlReporter'; 

exports.config = { 
    specs: [ 
     './test.js' 
    ], 
    reporters: [htmlReporter], 
    ... 
} 

test.js: 應該發送的定製數據

describe('Test suite', function() { 
    // is it possible to send some data to the current test-suite? 
    // this.customData ? 
    it('Test case', function() { 
     // is it possible to send some data to the current test-case? 
     // this.customData ? 
    }); 
}); 

});

htmlReporter.js: 應該接收自定義數據

var htmlReporter = function(options) { 
var self = this; 
    this.on('suite:start', function(suite) { 
     // how to get a custom data? 
     // suite.customData is undefined 
    }); 

    this.on('test:pass', function(test) { 
     // how to get a custom data? 
     // suite.customData is undefined 
    }); 
    ... 
} 

回答

1

面對發送自定義消息,失敗的測試同樣的問題。在測試錯誤對象和增加的消息再次引發錯誤

describe('Test suite', function() { 
    it('Test case', function() { 
     try { 
      //test failed due to error! 
     } catch(err) { 
     err.message.myCustomMessage = "Test failed due to XXX". 
     throw err; 
     } finally { 

     } 
    }); 
}); 

然後在定製記者

this.on('test:fail', function(test) { 
    var myCustomMessage = test.err.message.myCustomMessage; 
}); 

不知道是否有任何其他官方/標準的方法,但是這對服務器D目的。

謝謝。

相關問題