简体   繁体   English

让Poltergeist不区分大小写

[英]Make Poltergeist case insensitive

I'm using Poltergeist / Capybara for my tests: 我正在使用Poltergeist / Capybara进行测试:

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

but I noticed that I have to rewrite a lot of tests, as Poltergeists driver seems to be case-sensitive . 但我注意到我必须重写很多测试,因为Poltergeists的驱动程序似乎是case-sensitive Is there anything I can pass to change this? 有什么我可以改变这个吗?

As @eugen mentions all searches in capybara are case sensitive by default. 正如@eugen所提到的,默认情况下,所有在水豚中的搜索都是区分大小写的。 The problem you mention of having to rewrite tests usually occurs when moving from a driver that does/does-not support css text-transform to one that does-not/does - so the text being matched is or is not having the css text-transform (uppercase/lowercase/capitalize/...) applied. 你提到必须重写测试的问题通常发生在从支持css文本转换的驱动程序转移到不支持css文本转换的驱动程序时,所以匹配的文本是否具有css文本 - 应用了transform(uppercase / lowercase / capitalize / ...)。 If you want to be able to swap back and forth between drivers and really need case insensitivity you can pass regexes to the different matchers 如果您希望能够在驱动程序之间来回切换并且确实需要不区分大小写,则可以将正则表达式传递给不同的匹配器

expect(page).to have_text(/case insensitive text/i)
expect(page).to have_selector(:css, '#div1', text: /case insensitive text/i)

You could use a regex when comparing strings 比较字符串时可以使用正则表达式

expect(page.body).to match(%r{#{string}}i)

source: Case insensitive Rspec match 来源: 不区分大小写的Rspec匹配

All searches in capybara are case sensitive, there is no global option to change that. capybara所有搜索都是区分大小写的,没有全局选项来改变它。 If you need to do case insensitive matching, you'll have to do it on a search by search basis. 如果您需要进行不区分大小写的匹配,则必须在搜索基础上进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM