Is there a way for js code to force Selenium testing to fail? For (a probably bad) example, if I had the following:
return document.getElementById('foo').innerHTML == 'hello'
is there a way I could make the 'runScript' command fail depending on if the js code returned true or false? (I know that example could be used by other Selenium commands, but I wanted a more general solution.)
Do I need to learn how to extend Selenium to add another command?
I'm also relatively new to Selenium so is this something that using Selenium-rc will solve?
assertExpression
will give you what you're asking for.
For instance, the following line would cause your test to fail if the JavaScript expression you mention did not evaluate to true.
<tr>
<td>assertExpression</td>
<td>javascript{this.browserbot.getCurrentWindow().document.getElementById('foo').innerHTML == 'hello'}</td>
<td>true</td>
</tr>