【问题标题】:Webdriver.io how to send data to custom reporterWebdriver.io 如何向自定义报告器发送数据
【发布时间】:2017-01-16 11:15:53
【问题描述】:

我使用来自webdriver.io npm 包的wdio 工具来运行 Mocha 测试用例。

这是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
    });
    ...
}

【问题讨论】:

    标签: javascript node.js selenium-webdriver mocha.js webdriver-io


    【解决方案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;
    });
    

    不确定是否有任何其他官方/标准方式,但这符合目的。

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 2020-08-08
      相关资源
      最近更新 更多