Reputation: 2993
I am trying to use PHPUnit with selenium
I start the server java -jar c:/xampp/selenium-server-standalone-2.18.0.jar
This is my test
require_once 'PHPUnit/Extensions/Selenium2TestCase.php';
class WebTest extends PHPUnit_Extensions_Selenium2TestCase {
protected function setUp() {
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://localhost/");
}
public function testMyTestCase() {
$this->url('my/url/index.php');
$link = $this->byId('1-m-0');
$this->assertEquals('11', $link->text());
}
}
Item with id="1-m-0" exists on page, but test fails cause it gets element as null. I have tried with other elements, SeleniumTestCase class (with the same server) but not luck !
What i do wrong?
Upvotes: 2
Views: 7203
Reputation: 624
In case you find the phpunit library a little bit confusing we created a library that interacts with the Selenium Json Wire Protocol but we aimed to make it as similar as possible with the official documentation examples. So an example from the selenium site in Java would have nearly the same syntax in php.
Check it out: https://github.com/Nearsoft/PHP-SeleniumClient
If you like it share it, get involved, fork it or do as you please :)
Regards, Mark.
Upvotes: 0
Reputation: 2993
Ok, found it out. Here is my class now :
class WebTest extends PHPUnit_Extensions_SeleniumTestCase {
protected function setUp() {
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://localhost/");
}
public function testPlay() {
$this->open('http://localhost/my/url/index.php');
$this->waitForPageToLoad(4000);
// Wait for ajax to load
$this->waitForCondition("selenium.browserbot.getCurrentWindow().$('#mytable').length > 0");
$ids = array(
'1-m-0',
'2-n-1',
);
// Click ids
foreach ($ids as $v) {
$xpath = "xpath=//button[@id='{$v}']";
$this->assertElementPresent($xpath);
$this->click($xpath);
}
}
}
This article helped me: http://devzone.zend.com/1014/acceptance-testing-of-web-applications-with-php/
I m using this selenium server: selenium-server-standalone-2.18.0.jar
Upvotes: 4