ant javascript getProperty xml



我有一个像这样的文件rapport.xml:

<?xml version="1.0"?>
<testsuites name="COMPTES" tests="8" time="7" timestamp="2014-07-01T17-20-07" failures="8" errors="0">
    <testsuite name="100" tests="4" failures="4" errors="0" time="7">
        <testcase classname="Script.COMPTES.100" name="TEST1" time="1">
            <failure message="Not exist file or used" type="fileNotExist">
                File No matches
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST2" time="2">
            <failure message="Not exist file or used" type="fileUsed">
                Data set in use
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST3" time="3">
            <failure message="Not exist file or used" type="fileNotExist">
                File No matches
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST4" time="3">
            <failure message="File abended" type="abended">
                File abended
            </failure>
        </testcase>
    </testsuite>
    <testsuite name="120" tests="4" failures="4" errors="0" time="7">
        <testcase classname="Script.COMPTES.120" name="TEST1" time="1">
            <failure message="Not exist file or used" type="fileUsed">
                Data set in use
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.120" name="TEST2" time="2">
            <failure message="Not exist file or used" type="fileNotExist">
                File No matches
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.120" name="TEST3" time="3">
            <failure message="File abended" type="abended">
                File abended
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.120" name="TEST4" time="3">
            <failure message="Not exist file or used" type="fileUsed">
                Data set in use
            </failure>
        </testcase>     
    </testsuite>
</testsuites>

在build.xml中,我使用javascript标签,但我无法访问"testsuite"的"testcase"的数量

<script language="javascript">
    <![CDATA[ 
    var testsuites = project.getProperty('testsuites.name');
      var testsuite = project.getProperty('testsuites.testsuite').split(',');
      var testcase = testsuite[0].getProperty('testsuites.testsuite.testcase').split(',');
      println('testcase ' + testcase.length);
    project.setProperty('testsuites ', testsuites );
    ]]>
</script>

我想检索"testcase"的数目,其失败是不存在的文件,或用于每个"testsuite"的附加文件。

我想显示:

[script] testsuite : 100 
[script] count file used : 1
[script] count file no matches : 2
[script] count file abended : 1
[script] testsuite : 120
[script] count file used : 2
[script] count file no matches : 1
[script] count file abended : 1

你能帮我一下吗,谢谢你

—EDIT,使用xmltask直接解决方案—

当使用xmltask时,它是一块蛋糕:

<project>
  <!-- Import XMLTask -->
  <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
 <xmltask source="rapport.xml">
  <call path="//testsuite">
   <param name="testsuite" path="@name"/>
   <param name="fileused" path="count(testcase/failure[@type='fileUsed'])"/>
   <param name="filenomatch" path="count(testcase/failure[@type='fileNotExist'])"/>
   <param name="fileabended" path="count(testcase/failure[@type='abended'])"/>
  <actions>
   <echo>
    testsuite : @{testsuite}
    count file used : @{fileused}
    count file no matches : @{filenomatch}
    count file abended : @{fileabended}</echo>
  </actions>
  </call>
 </xmltask>
</project>

输出:

[echo]     testsuite : 100
[echo]     count file used : 1
[echo]     count file no matches : 2
[echo]     count file abended : 1
[echo]     testsuite : 120
[echo]     count file used : 2
[echo]     count file no matches : 1
[echo]     count file abended : 1

否则它会变得很复杂,一个快速使用脚本任务与javascript:

<project>
 <xmlproperty file="rapport.xml" collapseattributes="true"/>
<!--
<xmlproperty file="rapport.xml" collapseattributes="true"/>
<echoproperties prefix="testsuites"/>
[echoproperties] testsuites.errors=0
[echoproperties] testsuites.failures=6
[echoproperties] testsuites.name=COMPTES
[echoproperties] testsuites.tests=6
[echoproperties] testsuites.testsuite.errors=0,0
[echoproperties] testsuites.testsuite.failures=6,6
[echoproperties] testsuites.testsuite.name=100,120
[echoproperties] testsuites.testsuite.testcase.classname=Script.COMPTES.100,Script.COMPTES.100,Script.COMPTES.100,Script.COMPTES.100,Script.COMPTES.120,Script.COMPTES.120,Script.COMPTES.120,Script.COMPTES.120
[echoproperties] testsuites.testsuite.testcase.failure=File No matches,Data set in use,File No matches,File abended,Data set in use,File No matches,File abended,Data set in use
[echoproperties] testsuites.testsuite.testcase.failure.message=Not exist file or used,Not exist file or used,Not exist file or used,File abended,Not exist file or used,Not exist file or used,File abended,Not exist file or used
[echoproperties] testsuites.testsuite.testcase.failure.type=fileNotExist,fileUsed,fileNotExist,abended,fileUsed,fileNotExist,abended,fileUsed
[echoproperties] testsuites.testsuite.testcase.name=TEST1,TEST2,TEST3,TEST4,TEST1,TEST2,TEST3,TEST4
[echoproperties] testsuites.testsuite.testcase.time=1,2,3,3,1,2,3,3
[echoproperties] testsuites.testsuite.tests=6,6
[echoproperties] testsuites.testsuite.time=7,7
[echoproperties] testsuites.time=7
[echoproperties] testsuites.timestamp=2014-07-01T17-20-07
-->
<script language="javascript">
importPackage(java.util);
var testsuites = project.getProperty('testsuites.testsuite.name').split(',');
var testcases = project.getProperty('testsuites.testsuite.testcase.classname');
var testcaseclasses = new ArrayList(Arrays.asList(testcases.split(',')));
// determine how many different TestClasses
var testsunique = new ArrayList(new HashSet(testcaseclasses));
Collections.sort(testsunique);
var failures = project.getProperty('testsuites.testsuite.testcase.failure.type');
var failuretypes = new ArrayList(Arrays.asList(failures.split(',')));
// determine how many different Failuretypes
var failuresunique = new ArrayList(new HashSet(failuretypes));
Collections.sort(failuresunique);

for (var i=0; i &lt; testsuites.length; i++) {
 println('testsuite : ' + testsuites[i]);
 for (var j=0; j &lt; failuresunique.size(); j++) {
  println ('count ' + failuresunique.get(j) + ' : ' + Collections.frequency(failuretypes.subList(0,Collections.frequency(testcaseclasses, testsunique.get(i))), failuresunique.get(j)));
 }
 failuretypes.remove(failuretypes.subList(0,Collections.frequency(testcaseclasses, testsunique.get(i))).clear());
}
</script>
</project>

输出:

[script] testsuite : 100
[script] count abended : 1
[script] count fileNotExist : 2
[script] count fileUsed : 1
[script] testsuite : 120
[script] count abended : 1
[script] count fileNotExist : 1
[script] count fileUsed : 2

看起来你的javascript有bug。应该是:

var testcase = testsuite[0].getProperty('testcase').split(',');

相关内容

  • 没有找到相关文章

最新更新