我正在使用PHPUnit和Selenium在網站上運行自動測試。我創建了覆蓋我大部分網站的測試,但運行速度很慢。它需要25分鐘來運行它們,所以它非常耗時(無論如何,以我的標準:))。我設法通過對測試進行一些調整來使它們更快地工作,主要的調整是使用selenium -browserSessionReuse來重複使用同一個窗口。時間降至16分鐘以便測試運行。PHPUnit測試之間的硒頁面
現在我想在http://local.app/admin/測試的網頁和我所有的測試默認去那裏,但測試之間(當1點測試結束和另一個打開)所使用的硒Firefox窗口去http://local.app/和這是我的主要網站。有沒有辦法控制這個?我寧願不加載網站的主頁,因爲這也需要時間,沒有這個我會進一步減少運行測試所需的時間。
一些代碼:
我開始用硒
java -jar selenium-server-standalone-2.38.0.jar -browserSessionReuse
的phpunit.xml文件有
<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>
我用的Yii的發展。所以我有一個名爲WebTestCase.php的文件,所有我的功能測試擴展。 WebTestCase文件的內容是。
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);
}
}
有人有一個想法,爲什麼在測試瀏覽器轉到網站的主頁?或者我可以如何控制這個?我有大約100次測試,這意味着主頁(甚至緩存)加載100次。謝謝。
任何其他提示使測試運行更快?我想讓它們在無頭服務器上運行,並且時間必須進一步減少,因爲無頭服務器比我的電腦慢很多。
之前,我已經試過了,我知道它是如何工作的。我的問題是,當一整套測試(一個包含很多測試的文件)結束時,因爲我使用browserSessionReuse,瀏覽器保持打開狀態並進入http://local.app/。我從來沒有告訴他去那個鏈接,我實際上不希望它去那個鏈接,因爲這是可能不完成的公共網站。即使它完成,它可能會加載需要時間加載的外部文件,這會減慢我的測試速度。 –