2012-02-15 14 views
3

テストが読み込まれずにタイムアウト値に達したページを開こうとすると、テストは停止またはスローされません例外。その代わりに、ページが正常に読み込まれたかのように動きます。 falseを返す最初のアサーションでクリックと停止を行います。Seleniumテストのタイムアウトでテストが停止しないPHPUnit 3.6.10 Selenium RC 2.19.0

私はPHPUnitの3.6.10のコミットログにこれを見つけた:https://github.com/sebastianbergmann/phpunit/commit/cb772b06e9bd97f478fff7a212e3a4f7fe96bc29ソースで

:それはまだキャッチしなければならないようhttps://github.com/sebastianbergmann/phpunit/blob/5d0ff52bdff9afd479e38fdc880adce453ce88e5/PHPUnit/Framework/TestResult.php#L665

例外が見えますが、残念ながら例外はしていないようですテストを停止するようにトリガするので、私はここで何をすべきか分からない。ここで

は私が話してい行動を誘発するためのサンプルテストです:

<?php 
class Example extends PHPUnit_Extensions_SeleniumTestCase 
{ 
    protected function setUp() { 
     $this->setBrowser('*firefox'); 
     $this->setBrowserUrl('http://myserver/timeout.php'); 
     $this->setTimeout(10); 
     $this->setWaitForPageToLoad(true); 
    } 

    public function testMyTestCase() { 
     // This should trigger an exception after timeout: 
     $this->openAndWait('/'); 

     // Anything below this line SHOULD never be executed because of timeout: 
     $this->click('id=clicketyclickthiswontbeclicked'); 
     $this->click('id=moreclicksthatwillnotbeclicked'); 

     // This will fail the test, because timeout didn't stop it 
     $this->assertTextPresent('this text'); 
    } 
} 
?> 

次のPHPファイルはタイムアウトをトリガする必要があります。

timeout.php:

<?php 

// Should trigger timeout 
sleep(30); 

// (...) Rest of the page 

?> 

私が何か間違ったことをやっているか、これはバグだろうか?

答えて

1

誰かがこの問題を抱えている場合に備えて、私はここに自分自身で答えるつもりです。この問題を回避するには、waitForPageToLoad関数をオーバーライドします。親関数を呼び出して、ページのロードが実際にタイムアウトしたかどうかを判断するために、ページがロードされるのを待っている時間を追跡し、実行された場合は例外をスローします。ここで

は、そのためのコードです:

protected function waitForPageToLoad($timeout=null) { 
    if (is_null($timeout)) { 
     $timeout = 30000; 
    } 
    $start = time(); 
    parent::waitForPageToLoad($timeout); 
    $end = time(); 
    if (($end - $start) >= ($timeout/1000)) { 
     throw new Exception('Timed out after '.$timeout.'ms.'); 
    } 
} 

これは非常に不必要なようだが、現時点では、それは私のために動作しますが、私はまだ、このようなハックを必要としない答えをしたいと思います。

関連する問題