Dashboard > Selenium > ... > Contributed User-Extensions > waitForCondition
Selenium Log In View a printable version of the current page.
waitForCondition
Added by Dan Fabulich, last edited by Dan Fabulich on Apr 12, 2006  (view change)
Labels: 
(None)

description

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.

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.

download

waitForCondition_1_0

Nice job!I think you can change all "pollUntilConditionIsTrue" into "continueTestWhenConditionIsTrue" in the extension then this command can serve for the latest source.

Thanks for the contribution! Here's a suggestion to make it even easier to use: Allow the function in the middle to be an Element, with all the Selenium element locators available to specify it.

The use case:
I've made an AJAX call, and am waiting for <div id="newly_appeared"> to appear on the page. I should be able to just say "newly_appeared".

Perhaps to specify JavaScript, the standard notation should be used for that: javascript

Unknown macro: {... }
(I hope that's right, I'm going from memory).

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators