1

First time using PHPUnit and Selenium. Installed Selenium IDE plugin for Firefox, created some simple tests using the recorder. The IDE formats the tests as HTML tables by default so I installed the PHP formatter addon to the Selenium addon and was able to export the tests as PHPUnit format. Next installed PHPUnit on Windows 7. Also installed the Selenium plugin for PHPUnit.

Then ran my tests using this command:

phpunit Mytests.php

output is:

Time: 0 seconds, Memory: 2.7Mb
OK (0 tests, 0 assertions)

So great no errors, but it doesn't look like the tests have run either. What's wrong? Is it the contents of my test file:

<?php

require_once 'PEAR/PHPUnit/Extensions/SeleniumTestCase.php';

class Mytests extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.foobar.com/");
  }

  public function related_videos()
  {
    // // make sure there are 4 related items
    $this->open("/");
    $this->click("xpath=//div[contains(@id, 'featured')]/article/div/a[contains(@class,'thumb')]");
    $this->waitForPageToLoad("30000");
    try {
        $this->assertEquals("4", $this->getXpathCount("//descendant-or-self::*[@id = 'related']/descendant::article"));
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->verificationErrors, $e->toString());
    }
  }

}
?>

1 Answer 1

4

Phpunit is looking for method names starting with "test" on the testcase instances, if you rename the related_videos method to test_related_videos it should find and run it.

Sign up to request clarification or add additional context in comments.

3 Comments

although now the output is OK, but incomplete or skipped tests! Tests: 1, Assertions: 0, Skipped: 1. The test doesn't launch Chrome on my computer, also do you know why it's being skipped?
ok running the command using the --verbose flag revealed the problem. PHPUnit couldn't connect to the Selenium server. Off to fix that sigh.
@TK123 I am getting same issue .. can you please let me know how to fix that ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.