Monday, March 5, 2012

Selenium IDE Conditional commands

Using the flowControl extension, you can include conditional commands in Selenium IDE.  The conditional statements do not export to WebDriver (Selenium 2) C# scripts; but it's still a very handy tool for IDE.

I used javascript to define conditions.  In the following example, if the variable, aVar, is greater than 550, the script moves to the line that is labeled 'target1'.  If the variable is 550 or less, the verifyText command executes.

gotoIf storedVars.aVar > 550 target1
verifyText css=span.amount $500.00
label target1

Here's an example of javascript checking if the variable is less than 550 or greater than 599, the script skips to the line labeled "target2". If the variable is between 550 and 599, the verifyText command executes.

gotoIf storedVars.aFico < 550 || storedVars.aFico > 599 target2
verifyText css=span.current-amount $500.00
label target2

One thing to keep in mind is that each "label" value has to be unique throughout the script. In other words, you cannot have two "target1" labels.