Phpunit-Selenium2-等待页面完全加载
我使用phpunit和selenium2(Selenium2TestCase)的扩展来检查我网站的界面。 因此,我的测试页面包含以下内容:Phpunit-Selenium2-等待页面完全加载,phpunit,selenium-webdriver,wait,assert,pageload,Phpunit,Selenium Webdriver,Wait,Assert,Pageload,我使用phpunit和selenium2(Selenium2TestCase)的扩展来检查我网站的界面。 因此,我的测试页面包含以下内容: testDisplay() { ... file_put_contents('/home/toto/www/screenshots/before.html', $this->source()); sleep(5); file_put_contents(/home/toto/www/screenshots/after.html', $this->s
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
在睡眠前(5)和睡眠后,我的页面有2个html文件:
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>
试验
after.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>
试验
...
toto42
...
我不明白为什么我要把睡眠(5)完全加载我的页面,有人有主意吗
还有一个问题,Selenium2TestCase的clickAtAndWait(PHPUnit_Extensions_SeleniumTestCase)的等价物是什么
提前谢谢我找到了答案。
我正在我的页面中寻找一个带有超时的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());
...
}