I'm using cucumber with RoR (with either webrat or capybara)
How can I write a step to check a radio button? I've tried "choose" or "select" but it can't find my radio button. I'm not sure what to do, as I have in fact 2 inputs with the same name (the 2 radio buttons belonging to the same "group")
Thanks
Example of html
<form name="myform" action="http://www.mydomain.com/myformhandler.cgi" method="POST">
<input type="radio" name="group1" value="Milk"> Milk<br>
<input type="radio" name="group1" value="Butter" checked> Butter<br>
<input type="radio" name="group1" value="Cheese"> Cheese
</form>
The answer is to choose
the id (generated by Rails) of the radio button.
<form name="myform" action="http://www.mydomain.com/myformhandler.cgi" method="POST">
<input type="radio" name="group1" value="Milk" id="group1_milk"> Milk<br>
<input type="radio" name="group1" value="Butter" checked id="group1_butter"> Butter<br>
<input type="radio" name="group1" value="Cheese" id="group1_cheese"> Cheese
</form>
and do
choose("group1_milk").
That will work even if more radio buttons have the same options.
In your step definition add line:
choose('A Radio Button')
Cucumber uses Capybara, you can read more about it here: https://github.com/jnicklas/capybara
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With