2012-02-15 80 views
3

,并在达到超时值,测试不停止或抛一个例外。相反,它只是继续前进,就像页面已成功加载一样。它执行点击并在第一个返回false的断言处停止。Selenium测试超时不停止测试的PHPUnit 3.6.10硒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.'); 
    } 
} 

这似乎令人难以置信的是不必要的,但在那一刻,我的作品,但我还是想回答,不需要这样的黑客。