4

アプリケーションのグローバル PHPUnit テスト スイートの一部として、Selenium テスト スイートを追加したいと考えています。Selenium テストのスイートをグローバルAllTests.phpファイルにフックしたところ、Selenium サーバーの実行中にすべてが正常に実行されました。

ただし、Selenium サーバーが実行されていない場合は、スクリプトで Selnium テストをスキップして、テストを実行するために他の開発者が Selenium サーバーをインストールする必要がないようにしたいと考えています。私は通常setUp、各テストケースのメソッド内で接続しようとし、これが失敗した場合はスキップされたとしてテストをマークしますが、これは次のメッセージで RuntimeException をスローするようです:

The response from the Selenium RC server is invalid: ERROR Server Exception: sessionId should not be null; has this session been started yet?

このシナリオでスキップされた Selenium テストをマークする方法はありますか?

4

3 に答える 3

2

PHPUnit 3.4 で導入されたテスト依存関係を使用できます。

基本的

  1. Selenium が起動しているかどうかを確認するテストを作成します。
  2. そうでない場合は、$this->markTestAsSkipped() を呼び出します。
  3. テストを必要とするすべてのセレンがこれに依存するようにします。
于 2009-10-23T19:56:25.743 に答える
0

私の好みのセレン/ PHPUnit構成:

統合 (selenium) テストを維持するのは大変な作業です。私は、テスト ケースの開発に firefox selenium IDE を使用しています。この IDE は、テスト スイートの PHPUnit へのエクスポートをサポートしておらず、個々のテスト ケースのみをサポートしています。そのため、テストを 5 つでも維持しなければならない場合、更新が必要になるたびにテストを再 PHPUnit するために多くの手作業が必要になります。そのため、Selenium IDE の HTML テスト ファイルを使用するように PHPUnit をセットアップしました。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!
} ?>
于 2013-02-26T19:06:28.277 に答える