user1593846 user1593846 - 3 months ago 13
PHP Question

How do I run a PHPUnit Selenium test without having a new browser window run for each function?

Okey, so I am trying to run a selenium test case using PHPUnit. And the first thing I do is trying the login function, this works perfect but then I want to run a function to check information on the page following the login but it opens a new browser instead of continueing in the current browser window. The reason this is a problem is because the page is setup to remove login authentication when the window is closed so if u use $this->url() to go to the page it gives the error that i need to login. This is my code right now, It starts the browser and runs the function to test the login form, then it closes the browser, open a new one and run the link check. This ofc result in a error due to the authentication error because the window was closed. I could run all the tests in one function but that is really sloppy coding and I want to avoid this. Anyone know how to solve this?

<?php
class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
$this->setBrowser("firefox");
$this->setBrowserUrl("https://**************************");
}

public function testLoginForm()
{

$this->url("login.php");
$this->byLinkText('Forgot your password?');
$form = $this->byCssSelector('form');
$this->byName('username')->value('test');
$this->byName('password')->value('1234');
$form->submit();
}


public function testCheckForMainMenueLinks ()
{
$this->url("index.php");
$this->byLinkText('Home');
$this->byLinkText('Products');
$this->byLinkText('About us');
$this->byLinkText('Contact');
}
}
?>

Answer

Okej so I guess you can just call the function directly from another function like so:

public function testOne
{
#code
$this->Two();
}

public function Two()
{
#code
$this->Three();
}

public function Three()
{
#code
}

and so on, this will just run the next function without a new browser, however, if it fails anywhere in any test the whole test is stoped so the feedback wont bee as good as individual tests.