量角器:Jasmine-Reporter(jasmine2)正在生成奇怪的Junit XML报告

时间:2015-07-31 21:15:30

标签: javascript node.js junit jasmine protractor

之前我正在使用Jasmine报告器1.x,我可以生成很好的Junit Xml报告。但后来由于一些新的酷功能我们转移到Jasmine reporter2.x。但问题是我无法为我的测试结果生成正确的Junit XML报告。我的XML输出如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<testsuites>
 <testsuite name="focused specs" timestamp="2015-07-31T17:00:42" hostname="localhost" time="6.225" errors="0" tests="3" skipped="0" disabled="0" failures="0">
  <testcase classname="focused specs" name="DDD" time="2.169" />
  <testcase classname="focused specs" name="EEE" time="1.514" />
  <testcase classname="focused specs" name="FFF" time="0.615" />
 </testsuite>
 <testsuite name="focused specs.SQLITE" timestamp="2015-07-31T17:00:46" hostname="localhost" time="0" errors="0" tests="0" skipped="0" disabled="0" failures="0">
 </testsuite>
 <testsuite name="focused specs.System admin page UI - delete user from MS SQL database through UI" timestamp="2015-07-31T17:00:46" hostname="localhost" time="1.924" errors="0" tests="3" skipped="0" disabled="0" failures="0">
  <testcase classname="focused specs.System admin page UI - delete user from MS SQL database through UI" name="AAA" time="1.018" />
  <testcase classname="focused specs.System admin page UI - delete user from MS SQL database through UI" name="BBB" time="0.171" />
  <testcase classname="focused specs.System admin page UI - delete user from MS SQL database through UI" name="CCC" time="0.225" />
 </testsuite>
</testsuites>

我不明白为什么我会看到重点规格&#39;内部类和测试套件名称。另外,对于我的第一个测试套件,您可以看到缺少测试套件名称(替换为&#39;重点规格&#39;)并显示在下一个标签&#39; SQLITE&#39;中。 这就是我在.conf文件中使用报告插件的方式:

&#13;
&#13;
exports.config = {
  //multiCapabilities: [{'browserName': 'firefox'},{'browserName': 'chrome'},{'browserName': 'internet explorer'}],
	capabilities: {'browserName': 'chrome'},
  	seleniumAddress: 'http://localhost:4444/wd/hub',
	specs: ['./runner/runner-*.js'],
	allScriptsTimeout: 10000,
	getPageTimeout: 10000,
	framework: 'jasmine2',
	onPrepare: function() {
		var jasmineReporters = require('jasmine-reporters');
		var capsPromise = browser.getCapabilities();
		capsPromise.then(function(caps){
			var browserName = caps.caps_.browserName.toUpperCase();
			var browserVersion = caps.caps_.version;
			var prePendStr = browserName + "-" + browserVersion + "-";
			jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
				consolidateAll: true,
				savePath: 'XML-Results',
				filePrefix: prePendStr
			}));
		});
	},
};
&#13;
&#13;
&#13;

关于我为什么受苦的任何想法?

感谢。

1 个答案:

答案 0 :(得分:1)

我也遇到了和你一样的问题。

经过研究,我发现Protractor在开始测试执行之前会等待onPrepare() can optionally return a promise

这里可能发生的是测试在报告文件初始化之前开始执行。

您可以参考此answer

我能够通过在获取浏览器功能时返回一个承诺来解决这个问题:



    onPrepare: function () {
        var jasmineReporters = require('jasmine-reporters');

        // return promise here to ensure this gets completed before tests run
        return browser.getCapabilities().then(function (caps) {
            var browserName = caps.caps_.browserName.toUpperCase();
            var browserVersion = caps.caps_.version;
            var prePendStr = browserName + "-" + browserVersion + "-";

            jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
                consolidateAll: true,
                savePath: 'XML-Results',
                filePrefix: prePendStr
            }));
        });
    }


如果有帮助,请告诉我。