如何使用 waitForCondition()

发布于 2024-10-01 09:33:08 字数 1020 浏览 1 评论 0原文

美好的一天,

我是硒的新手,我正在尝试编写一个简单的测试。我想测试我的 AJAX 功能,因此我认为 waitForCondition() 方法非常适合我。问题是,我每次都会收到错误,说“testLoop”未定义。我的测试很简单:

@Test
public void firstTest() 
{
    selenium.open(BASE_URL);
    assertTrue(selenium.isElementPresent("css=a#performAjax"));
    selenium.click("link=Add some content!");
    String script = "selenium.browserbot.getCurrentWindow().document.getElementByClassName('ajaxMessage').length > 0";
    selenium.waitForCondition(script, "10000");
    Assert.assertEquals(selenium.getText("css=div.ajaxMessage"), "You got me with AJAX!");
}

但是每次运行它时,我都会收到错误:

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: testLoop is not defined

我已经搜索了论坛等来寻找此问题的答案,但到目前为止我发现没有任何帮助。任何提示表示赞赏。

关于编写硒测试的更好方法的其他提示也很受欢迎,但我的主要目标是解决这个错误:)

如果有人想知道,是的,我已经验证了在调用 waitForCondition() 期间抛出了错误。

Good day,

I'm new to selenium and I'm trying to write a simple test. I want to test my AJAX functionality so I thought that the waitForCondition() method was the right fit for me. Problem is, I get an error every time, saying that 'testLoop' is not defined. My test is simple:

@Test
public void firstTest() 
{
    selenium.open(BASE_URL);
    assertTrue(selenium.isElementPresent("css=a#performAjax"));
    selenium.click("link=Add some content!");
    String script = "selenium.browserbot.getCurrentWindow().document.getElementByClassName('ajaxMessage').length > 0";
    selenium.waitForCondition(script, "10000");
    Assert.assertEquals(selenium.getText("css=div.ajaxMessage"), "You got me with AJAX!");
}

But every time I run it, I get the error:

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: testLoop is not defined

I've searched forums, etc, for an answer to this but I've found nothing helpful thus far. Any tips are appreciated.

Other tips regarding better ways to write selenium tests are also welcome, but my main goal is to get around this error :)

In case anybody is wondering, yes, I've verified that the error is thrown during my call to waitForCondition().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花海 2024-10-08 09:33:08

更多的搜索就成功了!对于其他想知道的人...

用户评论 这篇文章提到 waitForCondition() 扩展的当前实现与当前版本的 selenium 不同步。必须更新 user-extensions.js 文件以将“testLoop”的所有实例替换为“TestLoop”。

如果您像我一样将 selenium-rc 作为外部 jar 导入到 Eclipse 中,那么只需解压 jar,编辑 js 文件,然后将其重新压缩到 jar 中即可。

更新:

经过进一步研究,似乎 waitForElementPresent() 是执行此操作的首选方法,因为您可以简单地指定定位器而不是评估 JavaScript 表达式。还有 waitForTextPresent() 和其他等效函数。

这些 AJAX 方法不存在于使用 selenium-rc 获得的 .jar 文件中。它们在 Selenium-IDE 中可用,如果将这些测试导出到 Java,您将看到它只是创建一个默认超时为 60 秒的循环并检查 isElementPresent()。

如果您更喜欢严格从 Java 驱动模式工作,您可能可以创建一些帮助程序来为您完成这项工作,因为解压缩 jar、修改用户扩展和重新压缩 jar 变得相当乏味和烦人。

Some more searching did the trick! For anyone else who is wondering...

A user commenting on this post mentions that the current implementation of the waitForCondition() extension is out of sync with the current version of selenium. The user-extensions.js file must be updated to replace all instances of 'testLoop' with 'TestLoop'.

If you've imported selenium-rc as an external jar into Eclipse like I did, this is a matter of decompressing the jar, editing the js file, and re-compressing it into a jar.

Update:

After further research, it seems that waitForElementPresent() is the preferred way to do this, as you can simply specify a locator rather than evaluating a JavaScript expression. There is also waitForTextPresent() and other equivalents.

These AJAX methods are not present in the .jar files that you get with selenium-rc. They are available in Selenium-IDE, and if you export these tests to Java, you will see that it is simply creating a loop with a default timeout of 60 seconds and checking for isElementPresent().

If you prefer to work strictly from Java-driven mode, you can probably create some helpers to do this work for you, since unzipping the jar, modifying user extensions, and re-zipping the jar gets rather tedious and annoying.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文