Javascript casperjs:更改输出XUnit XML文件中的测试'classname'
我使用casperjs来运行自动接口测试,并最终生成类似于XUnit的XML输出文件。我想知道是否有办法覆盖或手动设置测试类名?例如,在我的输出文件中,我得到:Javascript casperjs:更改输出XUnit XML文件中的测试'classname',javascript,testing,casperjs,Javascript,Testing,Casperjs,我使用casperjs来运行自动接口测试,并最终生成类似于XUnit的XML输出文件。我想知道是否有办法覆盖或手动设置测试类名?例如,在我的输出文件中,我得到: <testcase name="Found an element matching: .headerProfile" classname="test/casperjs/casper-test" time="0.002"></testcase> <testcase name="Found an element
<testcase name="Found an element matching: .headerProfile" classname="test/casperjs/casper-test" time="0.002"></testcase>
<testcase name="Found an element matching: .headerCalendarTab" classname="test/casperjs/casper-test" time="0.003"></testcase>
<testcase name="Found an element matching: .headerMetricTab" classname="test/casperjs/casper-test" time="0.002"></testcase>
我希望:
<testcase name="Found an element matching: .headerProfile" classname="xxx" time="0.002"></testcase>
<testcase name="Found an element matching: .headerCalendarTab" classname="xxx" time="0.003"></testcase>
<testcase name="Found an element matching: .headerMetricTab" classname="xxx" time="0.002"></testcase>
我搜索了文档,但没有找到任何东西…如果这是您想要的确切结果,请将文件名更改为xxx.js,您的结果将是classnname='xxx' 您可以更改
casper.test
对象的currentTestFile
属性。您可以对整个文件甚至单个测试块执行此操作
对于完整的测试文件,您可以在开头添加以下行:
casper.test.currentTestFile = "newFileName.js";
casper.test.begin("test2", function suite(test){
var oldfile = test.currentTestFile;
test.currentTestFile = "newFile.js";
casper.start().then(function(){
test.assert(true, "was also true");
}).run(function(){
test.currentTestFile = oldfile;
test.done();
});
});
这将导致
<testsuite name="test1" tests="1" failures="0" errors="0" time="0.063" timestamp="2014-07-01T15:37:26.546Z" package="newFileName">
<testcase name="was true" classname="newFileName" time="0.063"></testcase>
<system-out></system-out>
</testsuite>
如果不希望为以下测试套件和测试用例设置此新文件名,则需要记住将其更改回
看这个
注意:这是文档中没有的内部属性。将来它可能会改变行为或一起删除。谢谢,但是。。。这不是我所期望的;)