ruby-on-rails - 检查选择框是否具有 capybara 的某些选项

标签 ruby-on-rails selenium cucumber capybara

如何使用 Capybara 检查选择框是否具有列为选项的某些值? 它必须与 Selenium 兼容...

这是我的 HTML:

<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 = {})相反:

#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

关于ruby-on-rails - 检查选择框是否具有 capybara 的某些选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5394799/

相关文章:

java - 使用 Cucumber 数据表注册 LocalDateTime xstream 转换器

ruby - 如何标记用于 VCR 盒式磁带的 cucumber 场景大纲示例?

ruby-on-rails - 找不到ID时如何处理错误?

ruby-on-rails - 如何从 Rails 应用程序中完全删除 Yarn?

ruby-on-rails - 使用 Rspec stub File.open

ruby-on-rails - 如何从 Rails 获取 HTTP_HOST?

python - 从 python 中的 selenium 导入 webdriver 时出错

java - 对于参数类型 int、String,运算符 < 未定义

java - Jenkins Cucumber 报告作为电子邮件附件发送

java - WebDriver 不接受 Chrome 中的 js 警报