I have the html source:
<ul>
<li>
<input checked="checked" class="chb_tester" id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="1" />
<span class="role_item_text">T开发者_开发百科ester</span>
</li>
</ul>
How can i check this checkbox in my cucumber scenario?
If you're using Capybara and RSpec:
To check it:
check('#user_role_ids_')
To verify that it's checked:
find('#user_role_ids_').should be_checked
#used to check that a checkbox is checked
Then /^the "([^"]*)" checkbox should be checked$/ do |id|
find_field(id)[:value].should eq "true"
end
And use it for Uncheck also by making assertion as false
Another way to check your checkbox is:
# When I select checkbox "report_type_summary"
When(/^I select checkbox "(.*?)"$/) do |cb|
check(cb)
end
You can only select a checkbox name which is used for finding and checking the element. You can check this article for more details.
精彩评论