Question
How do you check if a div has a particular css class or other attribute with PHPUnit and Selenium?
Background
I have been using PHPUnit and Selenium to perform functional testing on a number of sites. Test are currently extending PHPUnit_Extensions_SeleniumTestCase but I have no issue using PHPUnit_Extensions_Selenium2TestCase if it will provide a better solution.
Test Example
This is an example of a test, the real world usage is much more complicated with test classes abstracted out into several sub classes that my test cases extend.
In this example I would like to be able to click a button (some_button) and check if a div (some_div) has the css class 'active'.
class ExampleTest extends PHPUnit_Extensions_SeleniumTestCase {
protected $captureScreenshotOnFailure = true;
public function setUp() {
//Load some base application configuration and set $base_url
$this->setBrowser('firefox');
$this->setBrowserUrl($base_url);
}
public function testIfButtonChangesClass() {
$this->open("/test_page");
$this->select("id=some_combo", "value=2");
$this->assertFalse($this->isVisible('id=some_button'));
$this->click("id=some_button");
//How do I test if some_div has the class active? it would be nice to do
//something like this?
$this->assertTrue($this->hasClass('id=some_div','active'));
}
}
}