$result->setExternalUrl($external_url); $result->setTestsDirectoryRelative($reltestpath); ob_start(); // Vars used for e-mail stats $total_assertions = 0; $total_tests = 0; $assertion_failures = 0; $assertion_errors = 0; $tests_failed = 0; $tests_errored = 0; $tests_unstable = 0; $tests_skipped = 0; $tests_ok = 0; foreach ($tests as $test) { /* @var $test SeleniumTest */ $testresult = new Zoetrope_Result_Testcase(); $testresult->setClassName($test->getTestClassName()); $testresult->setVideoWidth($res_width); $testresult->setVideoHeight($res_height); echo PHP_EOL; echo '####################################################################' . PHP_EOL; echo '## Running test: ' . $test->getTestClassName() . PHP_EOL; echo '####################################################################' . PHP_EOL; // Save JUnit XML and Testdox text to results dir $file_log_junit1 = $test->getTestClassName() . '.xml'; $file_log_junit2 = $results_directory . '/' . $file_log_junit1; $file_testdox_text1 = $test->getTestClassName() . '_testdox.txt'; $file_testdox_text2 = $results_directory . '/' . $file_testdox_text1; $testresult->setLogJunitXmlName($file_log_junit1); $testresult->setLogJunitXml($file_log_junit2); // Only start screen grab if we are not running in foreground (ie. user has started it "command line")
/** * Analyze a Junit XML file * * @param string $file_log_junit2 * @param Zoetrope_Result_Testcase $testresult */ function analyzeJunitXmlFileAndAddToResult($file_log_junit2, Zoetrope_Result_Testcase $testresult) { try { $xml = simplexml_load_file($file_log_junit2); $num_assertions = $xml->xpath('/testsuites/testsuite/@assertions'); $num_failures = $xml->xpath('/testsuites/testsuite/@failures'); $num_errors = $xml->xpath('/testsuites/testsuite/@errors'); $num_tests = $xml->xpath('/testsuites/testsuite/@tests'); $run_time = $xml->xpath('/testsuites/testsuite/@time'); $testresult->setNumberOfAssertions((int) $num_assertions[0]); $testresult->setNumberOfFailure((int) $num_failures[0]); $testresult->setNumberOfErrors((int) $num_errors[0]); $testresult->setNumberOfTests((int) $num_tests[0]); $testresult->setRunTime((int) $run_time[0]); // HTML-ify jUnit XML log stacktrace $xmlerrorstack = $xml->xpath('/testsuites/testsuite/testcase/error'); $xmlfailstack = $xml->xpath('/testsuites/testsuite/testcase/failure'); // Find lines that cause errors in the code, for use in linenumber highlighting - also check if build is unstable foreach ($xmlerrorstack as $stack) { $testresult->addError(new Zoetrope_Result_Error((string) $stack['type'], (string) $stack)); // Regex checking for error messages in stacktrace which should trigger unstable build $unstable = preg_match('#(?:Timed out after \\d+ms\\.|BUILD_UNSTABLE\\:.*|PHPUnit_Framework_Exception\\: Could not connect to the Selenium RC server\\.)#', (string) $stack); // Mark build + specific test unstable if we find any matches to unstable regex if ($unstable && !isset($this_test_unstable)) { // Only unstable if no real failures $this_test_unstable = true; } else { if (!$unstable) { // A single (real) failure is enough to not be unstable $this_test_unstable = false; } } } } catch (Exception $e) { $testresult->addError(new Zoetrope_Result_Error('XML PARSING FAILED', $e->getMessage())); $this_test_unstable = false; } // Only sets test unstable if all tests in it unstable if (isset($this_test_unstable)) { $testresult->setUnstableTest($this_test_unstable); } // Find lines that cause fails in the code, for use in linenumber highlighting - also check if build is unstable /* TODO: TEMPORARILY UNCOMMENTED AS LONG AS WE'RE THROWING A SPECIFIC ERROR EVERY TIME A TEST FAILS foreach ( $xmlfailstack as $stack ) { $testresult->addFailure(new Zoetrope_Result_Error((string)$stack['type'], (string)$stack)); // Regex checking for failure messages in stacktrace which should trigger unstable build $unstable = preg_match( '#BUILD_UNSTABLE\:.*#', (string)$stack ); // Mark build + specific test unstable if we find any matches to unstable regex if ( $unstable && !isset( $this_test_unstable ) ) { $this_test_unstable = true; $build_unstable = true; } else if ( !$unstable ) { $this_test_unstable = false; $build_unstable = false; } } */ }