I am using PHPUnit and Selenium to run automatic testing on a website. I have created tests that cover most of my website but they run rather slow. It takes 25 minutes to run them all so it is quite time consuming (by my standards anyway :)). I managed to make them work a lot quicker by making some tweaks to the tests, the main tweak was to start selenium with -browserSessionReuse that reuses the same window all the time. The time went down to 16 minutes for the tests to run.
Now I am trying to test the pages at http://local.app/admin/ and all my tests go there by default, but between the tests (when 1 tests finishes and the other one opens) the firefox window that is used by selenium goes to http://local.app/ and this is my main website. Is there a way to control this? I would rather not have it load the homepage of the website as this also takes time and without this I will further decrease the time it takes to run the tests.
Some code:
I start selenium with
java -jar selenium-server-standalone-2.38.0.jar -browserSessionReuse
The phpunit.xml file has
<phpunit bootstrap="bootstrap.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<selenium>
<!--browser name="Internet Explorer" browser="*iexplore" /-->
<browser name="Firefox" browser="*firefox" />
</selenium>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../models/</directory>
<directory suffix=".php">../controllers/</directory>
<directory suffix=".php">../components/</directory>
<directory suffix=".php">../widgets/</directory>
<directory suffix=".php">../../common/</directory>
<exclude>
<directory suffix=".php">../../common/modules/core/extensions/Html2Pdf/</directory>
<directory suffix=".php">../../common/modules/core/extensions/bootstrap/</directory>
<directory suffix=".php">../../common/modules/core/views/</directory>
<directory suffix=".php">../../common/modules/core/widgets/views/</directory>
<directory suffix=".php">../../common/modules/core/tests/</directory>
<directory suffix=".php">../../common/modules/core/migrations/</directory>
<directory suffix=".php">../../common/modules/core/components/Mandrill/</directory>
<directory suffix=".php">../../common/modules/core/components/PHPMailer/</directory>
<directory suffix=".php">../../common/widgets/views/</directory>
<directory suffix=".php">../../common/lib/</directory>
<directory suffix=".php">../widgets/views/</directory>
<directory suffix=".php">../widgets/views/</directory>
<file>../../common/modules/core/components/Mandrill.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="reports" charset="UTF-8" lowUpperBound="20" highLowerBound="60" />
<log type="coverage-clover" target="reports/coverage.xml" />
<log type="junit" target="reports/phpunit.xml" />
</logging>
I use Yii for the development. So I have a file called WebTestCase.php that all my functional tests extend. The content of the WebTestCase file is.
define('TEST_BASE_URL','http://local.app/admin/index-test.php/');
class WebTestCase extends \CWebTestCase
{
const TIMEOUT = 2;
public static $logged_in = false;
protected $coverageScriptUrl = 'http://local.app/phpunit_coverage.php';
/**
* Sets up before each test method runs.
* This mainly sets the base URL for the test application.
*/
protected function setUp()
{
parent::setUp();
$this->setBrowser('*firefox');
$this->setBrowserUrl(TEST_BASE_URL);
}
}
Anybody has an idea why between the tests the browser goes to the homepage of the website? Or how I can control this? I have around 100 tests so that means the homepage (even cached) is loaded 100 times. Thank you.
Any other tips to make the tests run even faster? I want to make them run on a headless server and the time has to go down further as the headless server is a lot slower then my computer.