2

私の一般的なテスト設定は次のようになります。

class MySeleniumTest extends PHPUnit_Extensions_SeleniumTestCase{

    public static $browsers = array(
        array(
            'name'    => 'Mozilla - Firefox',
            'browser' => '*firefox',
            'host'    => 'localhost',
            'port'    => 4444,
            'timeout' => 30000,
        ),
        array(
            'name'    => 'Google - Chrome',
            'browser' => '*googlechrome',
            'host'    => 'localhost',
            'port'    => 4444,
            'timeout' => 30000,
        )
    );

    //etc
}

ここから、個々のテスト ファイルは次のようになります。

class MyTest extends MySeleniumTest{
    public function setUp(){
        parent::setUp();
        $this->setUser(1);
    }

    public function testPageTitle(){
        //Login and open the test page.
        $this->login(8);
        $this->open('/test/page');
        //Check the title.
        $this->assertTitle('Test Page');
    }
}

ここから、PHPUnit で実行するMyTest.phpと、PHPUnit は自動的に各テスト ケースを で実行しMyTest.phpます。さらに、指定された各ブラウザーで個別に各テストを実行します。私ができるようにしたいのは、そのテスト ケース内から特定のテスト ケースを実行しているドライバーに関する情報を取得することです。次のようなものです:

public function testPageTitle(){
    //Login and open the test page.
    $this->login(8);
    $this->open('/test/page');
    //Check the title.
    $this->assertTitle('Test Page');

    $driver = $this->getDriver();
    print($driver['browser']); //or something.
}

ただし、これは機能しません。そして$this->getDrivers()、テストにドライバーを追加するだけで、セットアップでのみ使用されると想定されています。何か案は?ありがとう!

4

1 に答える 1

1

配列であっても、$this->driversその中には常に1つの要素しかありません。こちらで確認できます。したがって $this->drivers[0]、現在実行中のブラウザに関する情報が含まれており、$this->drivers[0]->getBrowser()ブラウザ名を出力するために使用できます。

例:

require_once 'MySeleniumTest.php';

class MyTest extends MySeleniumTest{
    public function setUp(){
        parent::setUp();
        $this->setBrowserUrl('http://www.google.com/');
    }

    public function testPageTitle(){
        $this->open('http://google.com');

        echo "{$this->drivers[0]->getBrowser()}\n";
    }
}

出力:

PHPUnit 3.7.18 by Sebastian Bergmann.

.*firefox
.*googlechrome


Time: 7 seconds, Memory: 3.50Mb

OK (2 tests, 0 assertions)
于 2013-03-09T17:16:08.720 に答える