我首选的 selenium / PHPUnit 配置:
维护集成(硒)测试可能需要做很多工作。我使用firefox selenium IDE开发测试用例,不支持将测试套件导出到PHPUnit,只支持个别测试用例。因此 - 如果我不得不维护 5 个测试,那么每次需要更新它们时都需要大量手动工作来重新 PHPUnit。这就是我设置 PHPUnit 以使用 Selenium IDE 的 HTML 测试文件的原因!它们可以在 PHPUnit 和 selenium IDE 之间重新加载和重用
<?php
class RunSeleniumTests extends PHPUnit_Extensions_SeleniumTestCase {
protected $captureScreenshotOnFailure = true;
protected $screenshotPath = 'build/screenshots';
protected $screenshotUrl = "http://localhost/site-under-test/build/screenshots";
//This is where the magic happens! PHPUnit will parse all "selenese" *.html files
public static $seleneseDirectory = 'tests/selenium';
protected function setUp() {
parent::setUp();
$selenium_running = false;
$fp = @fsockopen('localhost', 4444);
if ($fp !== false) {
$selenium_running = true;
fclose($fp);
}
if (! $selenium_running)
$this->markTestSkipped('Please start selenium server');
//OK to run tests
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://localhost/");
$this->setSpeed(0);
$this->start();
//Setup each test case to be logged into WordPress
$this->open('/site-under-test/wp-login.php');
$this->type('id=user_login', 'admin');
$this->type('id=user_pass', '1234');
$this->click('id=wp-submit');
$this->waitForPageToLoad();
}
//No need to write separate tests here - PHPUnit runs them all from the Selenese files stored in the $seleneseDirectory above!
} ?>