waitForCondition

Waits for any arbitrary condition, by running a JavaScript snippet of your choosing. When the snippet evaluates to "true", we stop waiting.

Use this for your AJAX testing!

  • script: the code to evaluate
  • timeout: the amount of time, in milliseconds, we should wait for your code to run. If the evaluation isn't true after that time, the command will fail.

example of use

waitForCondition var value = selenium.getText("foo"); value.match(/bar/); 3000

This grabs the text out of the "foo" element locator and asserts that it matches a regular expression. If this isn't true within 3 seconds, the test will fail.

using document properties

Since the javascript is executed in the context of the selenium frame/window, you need to use a selenium javascript method to retrieve the original document:

waitForCondition(
   "selenium.browserbot.getCurrentWindow().document.getElementById('btn_forward')",
   10000
)

This code would wait for a maximum of 10 seconds that the HTML element with id "btn_forward" comes into existance.

notes

  • Use this extension with Selenium 0.6.0.
  • This command will fail gracefully if your evaluation throws an exception.
  • This extension overrides part of the selenium-executionloop.js test loop to make the polling method handle thrown exceptions. Ideally, this would get baked into the official next release.

license

This user extension is available under Apache License 2.0. It is Copyright ThoughtWorks, Inc. 2006.

File: 

AttachmentSize
Package icon waitForCondition_1_0.zip1.81 KB

Type: 

User-Extension