Tuesday, October 03, 2006

waitForCondition vs. waitForEval in Selenium

waitForCondition vs. waitForEval in Selenium

While testing a web application with Selenium, I found lots of recommnedations to use waitForCondition to test Ajax functionalities, lots of tutorails, discussions about it in Selenium forum... with no mention to a more powerful and elegant command: waitForEval. Here are my concerns about waitForCondition which give the preference to using waitForEval:

  • You have to carefully check for any javascript syntax errors as waitForCondition hangs for any error without any log messages. (waitForEval fires error log messages for syntax problems in your javascript expressions.)
  • Upon condition failure, waitForCondition doesn’t give you diagnostic information in the log about the reason of failure in contrast to waitForEval.
  • If the element you check doesn’t get generated yet by javascript, waitForCondition will fail immediately without completing the timeout period. Hence, you need to waitForTextPresent or waitForElementPresent before waitForCondition. A third drawback that lowers it score opposed to waitForEval.

The only advantage of waitForCondition over waitForEval is that you can write in its target as much javascript statements as you can in opposition to wiatFor eval in which you write one expression to evaluate in the target column and the expected result in the value column; and this itself can be seen as advantage of waitForEval in elegance of writing the command.