3
I need to create several test scripts for WEB using Phpunit and Selenium. I was successful with my initial tests. I even managed to test the login and logout of my website effectively.
The problem is that I can only perform all the functions of the script at once, and it makes me waste a lot of time in a single test, besides preventing me from reusing the code already written for other tests.
I would like to know how to, in a test script as shown below, run only some specific functions.
<?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 illustrate what I’m wanting to do: in the above script, I intend to call only the function testLogoutAction(). However, when I run the script, it executes all the functions declared in order.
This also happens when I join the class to another. For example, in the following test, it executes all functions of the previous code, and then continues the execution of the respective class tests.
<?php
require_once("LoginTest.php");
class ContasTest extends LoginTest
{ ...
Great! It worked really well this way. I appreciate it. Can tell if there is a way to use this filter through Cakephp’s test interface (Test Suite), or it is possible only from the command line itself?
– LucasPinheiro23
I don’t know. I don’t use Cakephp. :)
– Paulo Henrique