【问题标题】:Phpunit - Selenium2 - Wait for page to be completely loadedPhpunit - Selenium2 - 等待页面完全加载
【发布时间】:2013-06-19 16:14:44
【问题描述】:

我正在使用带有 selenium 2 (Selenium2TestCase) 扩展的 phpunit 来检查我网站的界面。 所以我的测试页面包含这个:

testDisplay()
{
...
file_put_contents('/home/toto/www/screenshots/before.html', $this->source());
sleep(5);
file_put_contents(/home/toto/www/screenshots/after.html', $this->source());
$this->assertContains('toto42', $this->source());
...
}

然后当我执行时:

$> phpunit testSelenium.php

我的页面有 2 个 html 文件,在 sleep(5) 之前和之后:

before.html:

<META charset="utf-8"/>
<META content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<TITLE>Test</TITLE>

<LINK href="/css/style.css" rel="stylesheet"/>
<LINK href="/css/bootstrap.css" rel="stylesheet"/>
<SCRIPT src="/js/jquery-1.7.1.min.js" type="text/javascript"/>
</HEAD></HTML>

在.html 之后:

<META charset="utf-8"/>
<META content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<TITLE>Test</TITLE>

<LINK href="/css/style.css" rel="stylesheet"/>
<LINK href="/css/bootstrap.css" rel="stylesheet"/>
<SCRIPT src="/js/jquery-1.7.1.min.js" type="text/javascript"/>
</HEAD>
<BODY>
...
toto42
...
</BODY>

我不明白为什么我必须让 sleep(5) 完全加载我的页面,有人知道吗?

还有一个问题,对于 Selenium2TestCase,clickAtAndWait(PHPUnit_Extensions_SeleniumTestCase)的等价物是什么?

提前致谢

【问题讨论】:

    标签: phpunit selenium-webdriver wait assert pageload


    【解决方案1】:

    我找到了答案。 我正在我的页面中寻找一个超时的 HTML 元素,如果它没有出现,我会使用函数implicitWait();

    testDisplay()
    {
    ...
    //I use 25000 for the timeout but anything else works too it depends on your loading page 
    $this->timeouts()->implicitWait(25000);
    $this->assertContains('toto42', $this->source());
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-19
      • 2019-02-10
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多