I need to create multiple test scripts for WEB using PHPUnit and Selenium . I was successful with my initial tests. I was even able to test the login and logout of my web page effectively.
The problem is that I can only execute all the functions of the script at once, and this makes me waste a lot of time on a single test, besides preventing me from reusing the code already written for other tests.
I would like to know how to perform only a few specific functions in a test script like the one below.
<?php
class LoginTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$url = EXAMPLE_URL;
$this->setBrowser('firefox');
$this->setBrowserUrl($url);
$this->prepareSession();
$this->url(EXAMPLE_URL/users/login);
$this->currentWindow()->maximize();
}
private function testTitle($title = null)
{
if (!$title)
$title = EXAMPLE_TITLE_LOGIN;
$this->assertEquals($title,$this->title());
}
private function testLoginFormExists()
{
//Verifica se está na tela de login
$this->testTitle();
$name = $this->byName('data[User][username]');
$passwd = $this->byName('data[User][password]');
$this->assertEquals('',$name->value());
$this->assertEquals('',$passwd->value());
}
private function testLoginAction()
{
//Verifica se o form de login existe
$this->testLoginFormExists();
$form = $this->byId('UserLoginForm');
$action = $form->attribute('action');
$this->assertEquals(EXAMPLE_URL/users/login, $action);
$this->byName('data[User][username]')->value('admin');
$this->byName('data[User][password]')->value('ventovento');
$form->submit();
//Verifica se logou corretamente
$this->testTitle(EXAMPLE_TITLE_HOME);
}
private function testLogoutAction()
{
//Verifica se realiza login
$this->testLoginAction();
//Realiza logout
$this->byId('img-logout')->click();
//Verifica se realizou logout corretamente
$this->testTitle();
}
}
?>
To better exemplify what I'm trying to do: in the script above, I intend to call only the testLogoutAction () function. However, when I run the script, it executes all declared functions in order.
This also happens when I extend the class to another. For example, in the following test, it performs all the functions of the previous code, and then continues testing of the respective class.
<?php
require_once("LoginTest.php");
class ContasTest extends LoginTest
{ ...