检查选择框与 Capybara 有某些选项 [英] Check select box has certain options with Capybara
本文介绍了检查选择框与 Capybara 有某些选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Capybara 检查选择框是否将某些值列为选项?它必须与 Selenium 兼容...
How do I use Capybara to check that a select box has certain values listed as options? It has to be compatible with Selenium...
这是我拥有的 HTML:
This is the HTML that I have:
<select id="cars">
<option></option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
这就是我想做的:
Then the "cars" field should contain the option "audi"
推荐答案
尝试使用 capybara rspec 匹配器 have_select(locator, options = {}) 改为:
Try using the capybara rspec matcher have_select(locator, options = {}) instead:
#Find a select box by (label) name or id and assert the given text is selected
Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |selected_text, dropdown|
expect(page).to have_select(dropdown, :selected => selected_text)
end
#Find a select box by (label) name or id and assert the expected option is present
Then /^"([^"]*)" should contain "([^"]*)"$/ do |dropdown, text|
expect(page).to have_select(dropdown, :options => [text])
end
这篇关于检查选择框与 Capybara 有某些选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文