geneXML.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * 追加接口参数,支持过滤成功用例
  4. * @param unknown_type $onlyfails
  5. */
  6. function interXML($onlyfails) {
  7. if(!file_exists('report.xml'))
  8. return array();
  9. $xmlFile = simpleXML_load_file("report.xml");
  10. $caseList = array ();
  11. foreach($xmlFile->testsuite as $testsuite){
  12. foreach ($testsuite->testcase as $testResult) {
  13. // $totalCov = 0;
  14. $browser = $testResult['browserInfo'];
  15. $host = $testResult['hostInfo'];
  16. $caseName = $testResult['name']; //得到用例名称
  17. settype($caseName, "string"); //$caseName本来类型为object,需要做转换
  18. $fail = $testResult['failNumber'];
  19. $total = $testResult['totalNumber'];
  20. $cov = $testResult['cov'];
  21. settype($browser, "string");
  22. settype($host, "string");
  23. settype($fail, "string");
  24. settype($total, "string");
  25. settype($cov, "float");
  26. if (!array_key_exists($caseName, $caseList)) { //如果这个用例不存在
  27. $caseInfo = array (
  28. 'hostInfo' => $host,
  29. 'fail' => $fail,
  30. 'total' => $total,
  31. 'cov' => $cov
  32. );
  33. // $totalCov += $cov;
  34. $caseList[$caseName] = array (
  35. $browser => $caseInfo//,
  36. // 'totalCov'=>$totalCov
  37. );
  38. // $caseList['totalCov'] = $totalCov;
  39. } else { //否则添加到相应的用例中去
  40. $foundCase = $caseList[$caseName]; //找到用例名称对应的array,$caseName为key
  41. if (!array_key_exists($browser, $foundCase)) { //如果没有该浏览器信息,则添加
  42. // $totalCov += $cov;
  43. $caseList[$caseName][$browser] = array (
  44. 'hostInfo' => $host,
  45. 'fail' => $fail,
  46. 'total' => $total,
  47. 'cov' => $cov
  48. );
  49. // $caseList[$caseName]['totalCov'] = $totalCov;
  50. } else {
  51. $foundBrowser = $foundCase[$browser]; //有这个浏览器
  52. array_push($foundBrowser, array (
  53. 'hostInfo' => $host,
  54. 'fail' => $fail,
  55. 'total' => $total,
  56. 'cov' => $cov
  57. ));
  58. }
  59. }
  60. }
  61. }
  62. //根据需求添加仅记录失败情况的接口
  63. if($onlyfails){//如果仅考虑失败情况,此处根据用例情况过滤
  64. foreach($caseList as $name => $info){
  65. $all_success = true;//记录当前用例是否全部运行成功
  66. foreach($info as $b => $result){
  67. if($result['fail'] > 0)
  68. $all_success = false;//如果有失败情况则终止循环并进入下一个用例分析
  69. break;
  70. }
  71. //if($all_success) //如果全部通过则从记录中移除
  72. //unset($caseList[$name]);
  73. }
  74. }
  75. return $caseList;
  76. }
  77. ?>