dB'*_*dB' 18 ruby-on-rails cucumber capybara
使用Cucumber和Capybara,有没有办法验证页面上是否存在字符串?
例如,我将如何编写与此步骤相反的内容:
Then /^I should see "(.*?)"$/ do |arg1|
page.should have_content(arg1)
end
Run Code Online (Sandbox Code Playgroud)
如果arg1存在则通过.
如果找到,我怎么写一个失败的步骤arg1?
Pio*_*ski 29
has_no_contentCapybara 有一个匹配器.所以你可以写
Then /^I should not see "(.*?)"$/ do |arg1|
page.should have_no_content(arg1)
end
Run Code Online (Sandbox Code Playgroud)
Mic*_*cah 13
在目前(2016年)的Rspec 3.4中,这是测试没有内容的推荐方法:
expect(page).not_to have_content(arg1)
Run Code Online (Sandbox Code Playgroud)
如果你想让它读得更好,你也可以使用should_not:
Then /^I should not see "(.*?)"$/ do |arg1|
page.should_not have_content(arg1)
end
Run Code Online (Sandbox Code Playgroud)
更多信息:https://www.relishapp.com/rspec/rspec-expectations/docs
| 归档时间: |
|
| 查看次数: |
30975 次 |
| 最近记录: |