I am trying to run a SeleniumTestCase with phpunit but I cannot get it to run with the phpunit.bat script.
My goal is to use phpunit with Selenium RC in CruiseControl & phpUnderControl. This is what the test looks like:
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser('*firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->open('http://www.example.com/');
$this->assertTitleEquals('Example Web Page');
}
}
I also got PEAR in the include_path and PHPUnit installed with the Selenium extension. I installed these with the pear installer so I guess that's not the problem.
Any help would be very much appreciated.
Thanks, Remy
Here is the deal:
If you have a "Class PHPUnit_Extensions_SeleniumTestCase could not be found in (testcase file name)" problem, you have to do the following two things:
1. Rename the file of test case to the name of the class it contains 2. You should launch phpunit from the folder with your tests.
This should fix your problem.
Andrew
Try:
It can be namespace issue, as it was for me.
Here is how i solved this problem:
sudo apt-get install php5-curl
sudo pear install phpunit/PHPUnit_Selenium
After that you should have the missing file installed
Happy coding...
When it fails it doesn't always print out the most verbose error messages.
Always remember to start Selenium too prior to running test.
java -jar selenium-server-standalone-2.39.0.jar
Here is an example of code that was working for myself. http://www.siteconsortium.com/h/p1.php?id=php002. Obviously there are a lot of different way to write the test suite, and launch the test case but I used the set_class_path to get rid of class issues at first.
Do not presume that the pear install occurred without problems.
I had installed phpunit through pear but despite it saying the install went fine when I looked inside the folder, I had all these files starting with .tmp, eg PHPUnit/Util/.tmpErrorHandler.php so naturally when i ran a test for the 1st time it gave me the same error as above. After checking that indeed the file wasn't there I did a manual install of PHPUnit to the same folder as pear and alas, all was fine. I'm in Mac/leopard.
About Selenim RC don't forget to start it by running in terminal java -jar /path/to/file/selenium-server.jar
I found that the following sample from PHPUnit tutorial was working while the same error appeared in the test that I had written. The solution was a surprise. Ensure that your class is inside a
<?php .. ?>
block and not a<? .. ?>
block in the script.