Ruby on rails 使鬼精灵不区分大小写
我正在使用/用于我的测试:Ruby on rails 使鬼精灵不区分大小写,ruby-on-rails,cucumber,capybara,poltergeist,Ruby On Rails,Cucumber,Capybara,Poltergeist,我正在使用/用于我的测试: Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, { timeout: 60, phantomjs_options: ['--load-images=no'], case_insensitive: true # <-- doesn't work }) end end Capybara.re
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
timeout: 60,
phantomjs_options: ['--load-images=no'],
case_insensitive: true # <-- doesn't work
})
end
end
Capybara.register_驱动程序:poltergeist do|app|
水豚::妖怪::驱动程序。新(应用程序{
超时时间:60,
phantomjs_选项:['--load images=no'],
不区分大小写:true#在比较字符串时可以使用正则表达式
expect(page.body).to match(%r{#{string}}i)
来源:capybara
中的所有搜索都区分大小写,没有全局选项可以更改。如果需要进行不区分大小写的匹配,则必须逐个搜索。因为@eugen提到capybara中的所有搜索默认都区分大小写。您提到的必须重写测试的问题通常是当从不支持/不支持css文本转换的驱动程序移动到不支持/不支持css文本转换的驱动程序时,会发生ally-因此匹配的文本具有或不具有css文本转换(大写/小写/大写/…)如果你想在驱动程序之间来回切换,并且确实需要区分大小写,你可以将正则表达式传递给不同的匹配器
expect(page).to have_text(/case insensitive text/i)
expect(page).to have_selector(:css, '#div1', text: /case insensitive text/i)
好的,这是有道理的。我以前的驱动程序不区分大小写。但是,我想使用
expect(page)。使用内容而不是have text
。这对您的答案有用吗?的确!谢谢您的帮助!