Selenium RC WaitForPageToLoad 挂起
我正在尝试启动并运行 Selenium RC,以便在我的网站上进行一些自动化测试。我发现我一直想验证我没有破坏任何功能,而手动测试开始变得令人厌烦。
但是,我似乎无法让 Selenium RC 与 WaitForPageToLoad 一起使用。
我尝试复制他们在 selenium 文档中提供的基本示例,但测试总是卡在: $this->waitForPageToLoad("30000");我可以看到它在窗口中显示了那么远,并且页面似乎已正确加载(我们位于谷歌搜索结果页面)。但测试因超时而失败。
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
/**
* Description of Test
*
* @author brian
*/
class Test extends PHPUnit_Extensions_SeleniumTestCase {
function setUp() {
$this->setBrowser("*safari");
$this->setBrowserUrl("http://www.google.com/");
}
function testMyTestCase() {
$this->open("/");
$this->type("q", "selenium rc");
$this->click("btnG");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isTextPresent("Results * for selenium rc"));
}
}
更有趣的是,如果我在等待时刷新页面,一切都会按预期继续进行。因此, waitForPageToLoad 似乎没有意识到页面已经加载。
I am trying to get Selenium RC up and running for doing some automated testing on my website. I am finding that I constantly want to verify that I haven't broken any features, and manual testing is starting to become tiresome.
However, I can't seem to get Selenium RC to work with WaitForPageToLoad.
I tried copying the basic example that they give in the selenium documentation, but the test always gets stuck at: $this->waitForPageToLoad("30000"); I can see that it gets that far in the window that it brings up and that the page appears to have loaded correctly (we are at a google search result page). But the test fails with a timeout.
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
/**
* Description of Test
*
* @author brian
*/
class Test extends PHPUnit_Extensions_SeleniumTestCase {
function setUp() {
$this->setBrowser("*safari");
$this->setBrowserUrl("http://www.google.com/");
}
function testMyTestCase() {
$this->open("/");
$this->type("q", "selenium rc");
$this->click("btnG");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isTextPresent("Results * for selenium rc"));
}
}
What is even more interesting is that if I refresh the page when it is waiting, everything continues on as expected. So it would appear as though the waitForPageToLoad isn't realizing that the page has already loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Selenium RC 文档中的示例已过时。 Google 很久以前就改变了他们主页的工作方式,它不再是一个简单的 HTML 页面。按搜索按钮现在是一个 AJAX 类型的操作,它发送搜索请求并返回由页面中的 JavaScript 代码处理的 JSON 响应。因此页面永远不会重新加载,并且 WaitForPageToLoad() 最终会超时。
The example in the Selenium RC documentation is obsolete. Google changed the way their home page worked quite a while ago, and it is no longer a simple HTML page. Pressing the search button is now an AJAX-type operation that sends the search request and gets back a JSON response that is processed by the JavaScript code in the page. So the page never is re-loaded, and WaitForPageToLoad() eventually times out.
我刚才遇到的这种情况还有一个可能的原因。根据 文档,如果您调用 在加载页面和调用
waitForPageToLoad
之间的任何 SELENIUM 命令,那么waitForPageToLoad
可能会挂起。 (如果我理解正确的话,从技术上讲,这是测试脚本和selenium服务器之间的竞争条件,所以有时会发生,不一定总是发生)。大多数情况下,页面加载是由点击事件引起的。当您有这样的测试脚本时:
请额外确保没有 selenium 命令意外插入到标记区域中。
虽然这在技术上与OP发布的问题不同,但它具有相同的错误消息,并且我在没有深入挖掘的情况下找不到此信息。希望其他人将来能更容易找到它。
There is also another possible cause of this situation that I ran into just now. According to the documentation, if you call ANY SELENIUM COMMANDS in between loading a page and calling
waitForPageToLoad
, then it is possible thatwaitForPageToLoad
will hang. (If I understand it correctly, it is technically a race condition between the test script and selenium server, so it happens sometimes, not necessarily all the time).In most cases, the page load is caused by a click event. When you have a test script like:
Make extra sure that no selenium commands ever accidentally get inserted into the marked area.
While this is not technically the same problem that the OP posted about, it has the same error message, and I couldn't find this information without digging around quite a bit. Hopefully this is easier to find for other people in the future.
我多次观察到同样的问题。因此,当用户没有离开当前页面时,我没有使用此命令。它有时会挂起并在 while 循环中使用 IsElementPresent 并在返回 true 后退出。
I have observed same problem many times. Hence I did not use this command when user is not navigating away from current page. It hangs at times and using IsElementPresent in while loop and exit after it return true.
“WaitForPageToLoad()”的替代方法是等待元素出现。
An alernative to "WaitForPageToLoad()" Is to wait for an element to be present.