Note that there are some explanatory texts on larger screens.

plurals
  1. POSelenium/PHPUnit tests always run twice, fail on second pass
    primarykey
    data
    text
    <p>The problem I am having is that I have setup runners for my Selenium/PHPUnit tests and they are always being run twice, per test, one after the other. And then it will move onto the next test. I found <a href="http://www.phpunit.de/ticket/688" rel="nofollow">http://www.phpunit.de/ticket/688</a> that bug seems to be exactly what is happening to me -- so I removed all references to PHPUnit_MAIN_METHOD but I am still having the same problem, and it seems that "bug" was resolved two years ago anyways, and I am using the newest version of PHPUnit.</p> <p>Here is my runner code:</p> <pre><code>&lt;?php require_once '/libs/prefix.php'; class WWW_TestSuite { public static function main() { PHPUnit_TextUI_TestRunner::run(self::suite()); } public static function suite(){ global $TEST_CASES, $TEST_FILES, $DOMAINS, $SUB_DOMAINS, $LOG_FILES; $suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework'); $GLOBALS['testDomain'] = 'cco'; $GLOBALS['startURL'] = 'www.domain.com'; $GLOBALS['resultsFile'] = $LOG_FILES['www.domain.com']; $numberOfTests = count($TEST_CASES['cco']); $resultsFile = $GLOBALS['resultsFile']; $fh = fopen($resultsFile, 'w'); fwrite($fh, CRLF.DELIM_PLUS.CRLF); fwrite($fh, $numberOfTests.NUMBER_OF_TESTS_STRING.CRLF); fwrite($fh, DELIM_PLUS.CRLF); fclose($fh); foreach ($TEST_CASES['cco'] as $testCase){ include $TEST_FILES['cco'][$testCase]; $suite-&gt;addTestSuite($testCase); } return $suite; } } ?&gt; </code></pre> <p>And my reporting class code:</p> <pre><code>&lt;?php class reporting extends PHPUnit_Extensions_SeleniumTestCase { private $linkNotFound; private $imageNotFound; private $textNotFound; private $testStatus; private $successLines = array(); private $errorLines = array(); public function testContentPresent($testContent, $className){ foreach ($testContent as $contentType=&gt;$contentArr){ foreach ($contentArr as $currentContent){ try { $this-&gt;assertTrue($this-&gt;$contentType($currentContent)); $this-&gt;successLines[] = $contentType.': '.$currentContent; } catch (PHPUnit_Framework_AssertionFailedError $e) { $this-&gt;textNotFound = 1; $this-&gt;errorLines[] = $contentType.': '.$currentContent; } } } $this-&gt;print_report($this-&gt;testURL, $className, $this-&gt;errorLines, $this-&gt;successLines); } public function print_report($testURL, $testName, $errorLines='', $successLines=''){ $timeStamp = CRLF.date("m/d/y h:i:s a").CRLF; $resultsFile = $GLOBALS['resultsFile']; $fh = fopen($resultsFile, 'a'); fwrite($fh, CRLF.DELIM_NUM); fwrite($fh, $timeStamp); fwrite($fh, "TEST NAME: ".$testName.CRLF); fwrite($fh, "TEST URL: ".$testURL.CRLF); fwrite($fh, DELIM_NUM.CRLF); if (!empty($successLines)) { fwrite($fh, DELIM_STAR.CRLF); fwrite($fh, TEST_PASS.CRLF); fwrite($fh, DELIM_STAR.CRLF); foreach ($successLines as $successLine){ fwrite($fh, $successLine.CRLF); } }else { fwrite($fh, DELIM_STAR.CRLF); fwrite($fh, TEST_PASS.": NONE".CRLF); fwrite($fh, DELIM_STAR.CRLF); } if (!empty($errorLines)) { fwrite($fh, DELIM_STAR.CRLF); fwrite($fh, TEST_FAIL.CRLF); fwrite($fh, DELIM_STAR.CRLF); foreach ($errorLines as $errorLine){ fwrite($fh, $errorLine.CRLF); } }else { fwrite($fh, DELIM_STAR.CRLF); fwrite($fh, TEST_FAIL.": NONE".CRLF); fwrite($fh, DELIM_STAR.CRLF); } fclose($fh); } } ?&gt; </code></pre> <p>And here are the constants that are being used:</p> <pre><code>&lt;?php // REPORT VARIABLES define('DELIM_NUM', '#################################################################################################'); define('DELIM_STAR', '***************************************************************'); define('DELIM_PLUS', '++++++++++++++++++++++++++++++++++++++++++++'); define('NUMBER_OF_TESTS_STRING', ' TESTS HAVE RUN IN THE FOLLOWING BATCH.'); define('CRLF' ,"\n"); define('TEST_PASS', "SUCCESSES"); define('TEST_FAIL', "ERRORS"); // DIRECTORY VARS define('CCO_TESTS_DIR', '/tests/CCO/'); // $DOMAINS - DOMAINS ARRAY $DOMAINS = array ( 'cco' =&gt; '.domain.com' ); // $SUB_DOMAINS - SUB DOMAINS ARRAY $SUB_DOMAINS = array ( 'www', 'dev2' ); // $LOG_FILES - LOG FILE PATHS ARRAY $LOG_FILES = array ( 'www.domain.com' =&gt; CCO_LOG_FILES_DIR.date("m.d.y-H.i.s").'-CCO-WWW.txt' ); // $TEST_CASES - TEST CASE NAMES ARRAY $TEST_CASES = array ( 'cco' =&gt; array( 'CCO_TestName' ) ); // $TEST_FILES - ARRAY ASSOCIATING A TEST NAME WITH THE TEST FILE. $TEST_FILES = array ( 'cco' =&gt; array ( 'CCO_TestName' =&gt; CCO_TESTS_DIR.'CCO_TestName.php' ) ); // $TEST_NAME_URL_RELATION - ARRAY ASSOCIATING TEST CLASSES WITH THEIR ASSOCIATED URL ROOT. $TEST_NAME_URL_RELATION = array( 'cco'=&gt;array( 'CCO_TestName' =&gt; '/testdoc.asp?querystring=123' ) ); ?&gt; </code></pre> <p>Can anyone see why these tests would run twice, and ALWAYS fail on the second time through?</p> <p>Example of CLI output while running tests:</p> <pre><code>CCO_TestName www.domain.com .www.domain.com E </code></pre> <p>And the results file only gets updated with the results of the first test (which is normal behavior we get no logging if we get an E on the test, but I am wondering why it is running twice to begin with?</p> <p>EDIT: Forgot to include my setup file:</p> <pre><code>&lt;?php global $TEST_NAME_URL_RELATION; $testName = get_class($this); $this-&gt;reporting = new reporting(); $this-&gt;errorLines = array(); $this-&gt;startURL = $GLOBALS['startURL']; $this-&gt;setBrowser("*firefox"); $this-&gt;setBrowserUrl("http://".$this-&gt;startURL); $this-&gt;testUrlRoot = $TEST_NAME_URL_RELATION[$GLOBALS['testDomain']][$testName]; $this-&gt;testURL = $this-&gt;startURL.$this-&gt;testUrlRoot; print ($this-&gt;testURL."\n"); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload