PHPUnitとSeleniumを初めて使用します。Firefox用のSeleniumIDEプラグインをインストールし、レコーダーを使用していくつかの簡単なテストを作成しました。IDEはデフォルトでテストをHTMLテーブルとしてフォーマットするので、PHPフォーマッターアドオンをSeleniumアドオンにインストールし、テストをPHPUnitフォーマットとしてエクスポートすることができました。次にWindows7にPHPUnitをインストールしました。PHPUnit用のSeleniumプラグインもインストールしました。
次に、次のコマンドを使用してテストを実行しました。
phpunit Mytests.php
出力は次のとおりです。
Time: 0 seconds, Memory: 2.7Mb
OK (0 tests, 0 assertions)
エラーはありませんが、テストも実行されていないようです。どうしたの?それは私のテストファイルの内容ですか?
<?php
require_once 'PEAR/PHPUnit/Extensions/SeleniumTestCase.php';
class Mytests extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.foobar.com/");
}
public function related_videos()
{
// // make sure there are 4 related items
$this->open("/");
$this->click("xpath=//div[contains(@id, 'featured')]/article/div/a[contains(@class,'thumb')]");
$this->waitForPageToLoad("30000");
try {
$this->assertEquals("4", $this->getXpathCount("//descendant-or-self::*[@id = 'related']/descendant::article"));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
}
}
?>