If / Else test page


This page tests your use of if/else statements
Each time the page loads, you will be provided with 1 of 5 numbers
You will also be provided with 5 buttons.
Write a script that will click on the button with an id equal to the randomly chosen number
You will have to use an if statment to decide which button to click

You can also use a switch statement !

1



# the first thing to do is get the random number
theRandomNumber = browser.div(:id, "buttonNumber").text

# use an if statement to choose which button to press
if(theRandomNumber == "1")
      browser.div(:id, "formbuttons").button(:index, 1).click
elsif(theRandomNumber == "2")
      browser.div(:id, "formbuttons").button(:index, 2).click
elsif(theRandomNumber == "2")
      browser.div(:id, "formbuttons").button(:index, 3).click
elsif(theRandomNumber == "2")
      browser.div(:id, "formbuttons").button(:index, 4).click
elsif(theRandomNumber == "2")
      browser.div(:id, "formbuttons").button(:index, 5).click
end

# it is better to use the button id instead of index,
# incase there is a change in the system later and a new button is added
browser.div(:id, "formbuttons").button(:name, "5th").click
Later, you can write a test that uses a switch statement, or use a loop to run this test multiple times
You might also want to validate the messages