Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

It depends how you want to use selenium. In selenese suite there are calls for verifyText, etc (just google for selenese suite and verifyText, waitForCondition). If you are using the selenium remote control in e.g. java than you do the assertions in the java code. With the remote control you send scripts to the page and you get back what the evaluation of the code returns. The comparsion/assertion is done in the java client.

eval('asdfklj;'); //Selenium Hits it. Honestly I've never used it myself. Need to learn it soon, but I'm assuming it can bomb do to javascript errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top