record.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 =strval( $testResult['browserInfo']);
  15. $host = strval($testResult['hostInfo']);
  16. $caseName = strval($testResult['name']);
  17. $fail = strval($testResult['failNumber']);
  18. $total = strval($testResult['totalNumber']);
  19. $cov = strval($testResult['cov']);
  20. $recordCovForBrowser = strval($testResult['recordCovForBrowser']);
  21. if (!array_key_exists($caseName, $caseList)) { //如果这个用例不存在
  22. $caseInfo = array (
  23. 'hostInfo' => $host,
  24. 'fail' => $fail,
  25. 'total' => $total,
  26. 'cov' => $cov,
  27. 'recordCovForBrowser' => $recordCovForBrowser
  28. );
  29. // $totalCov += $cov;
  30. $caseList[$caseName] = array (
  31. $browser => $caseInfo//,
  32. // 'totalCov'=>$totalCov
  33. );
  34. // $caseList['totalCov'] = $totalCov;
  35. } else { //否则添加到相应的用例中去
  36. $foundCase = $caseList[$caseName]; //找到用例名称对应的array,$caseName为key
  37. if (!array_key_exists($browser, $foundCase)) { //如果没有该浏览器信息,则添加
  38. // $totalCov += $cov;
  39. $caseList[$caseName][$browser] = array (
  40. 'hostInfo' => $host,
  41. 'fail' => $fail,
  42. 'total' => $total,
  43. 'cov' => $cov,
  44. 'recordCovForBrowser' => $recordCovForBrowser
  45. );
  46. // $caseList[$caseName]['totalCov'] = $totalCov;
  47. } else {
  48. $foundBrowser = $foundCase[$browser]; //有这个浏览器
  49. array_push($foundBrowser, array (
  50. 'hostInfo' => $host,
  51. 'fail' => $fail,
  52. 'total' => $total,
  53. 'cov' => $cov,
  54. 'recordCovForBrowser' => $recordCovForBrowser
  55. ));
  56. }
  57. }
  58. }
  59. }
  60. //根据需求添加仅记录失败情况的接口
  61. if($onlyfails){//如果仅考虑失败情况,此处根据用例情况过滤
  62. foreach($caseList as $name => $info){
  63. $all_success = true;//记录当前用例是否全部运行成功
  64. foreach($info as $b => $result){
  65. if($result['fail'] > 0)
  66. $all_success = false;//如果有失败情况则终止循环并进入下一个用例分析
  67. break;
  68. }
  69. //if($all_success) //如果全部通过则从记录中移除
  70. //unset($caseList[$name]);
  71. }
  72. }
  73. return $caseList;
  74. }
  75. function record()
  76. {
  77. // require_once 'geneXML.php';
  78. /*如果全部运行完毕,发送邮件*/
  79. $kissList = interXML(false);
  80. require_once 'geneHTML.php';
  81. if (sizeof($kissList) > 0) {
  82. //针对kissList过滤,移除全部正确用例
  83. $html = geneHTML($kissList);
  84. $report = 'report.html';
  85. $handle = fopen("$report", "w");
  86. fwrite($handle, $html);
  87. fclose($handle);
  88. // require_once 'geneHistory.php';
  89. // geneHistory($html);
  90. }
  91. }
  92. ?>