The click_button () method, which Cucumber uses for "When I press ...", takes one of three parameters (text, name, identifier). You can simply distinguish buttons using the id or name attribute to indicate either.
<input type="submit" value="Save and close" name="commit" id="close_after_save"/> <input type="submit" value="Save" name="commit" id="save"/>
Then say:
When I press "save" When I press "close_after_save"
Alternatively, you can use each button in a div.
<div id="save_and_close"> <input type="submit" value="Save and close" name="commit"/> </div> <div id="save"> <input type="submit" value="Save" name="commit" id="save"/> </div>
Then you can specify the click_button () method:
When /^I press "([^\"]*)" within "([^\"]*)"$/ do |button,scope_selector| within(scope_selector) do click_button(button) end end
source share