- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用以下命令测试该页面包含<title>My Title</title>
:
# spec/features/reports_spec.rb
require 'spec_helper'
feature "Archive Management" do
subject { page }
describe "Index Page" do
before(:all) { 10.times { FactoryGirl.create(:randomreport) } }
after(:all) { Report.delete_all }
describe "when no search terms present" do
before { visit reports_path }
it { should have_selector('title', text: 'My Title') } # <= Fails w/Capybara 2.0
it { should have_selector('title') } # <= passes
it { should have_text('My Title') } # <= passes
it { should have_selector('h2', text: "Welcome") } # <= passes
end
end
end
Failure/Error: it { should have_selector('title', text: base_title) }
Capybara::ExpectationNotMet:
expected to find css "title" with text "My Title" but there were no matches. Also found "", which matched the selector but not all filters.
<title>
标签不再被视为“选择器”吗?!要么...?!?
<title>My Title</title>
。包含
<h2>Welcome to My Title Project</h2>
并通过的同一page.body!
<title>
...
</title>
标记,但未找到
My Title
。但是稍后会在
My Title
和/或
<a href=\"/\" class=\"brand\">My Title</a>
中的页面中找到
<h2>Welcome to The My Title Project</h2>
:
(rdb:1) p page
#<Capybara::Session>
(rdb:1) p page.body
"<!DOCTYPE html>\n<html>\n<head>\n<title>My Title</title>\n
<meta content='research, report, technology' name='keywords'>\n<meta
content='Some Project' name='description'>\n<link href=\"/assets/application.css\"
...
</head>\n<body>\n<header class='navbar navbar-fixed-top
navbar-inverse'>\n<div class='navbar-inner'>\n<div class='container'>\n
<a href=\"/\" class=\"brand\">My Title</a>\n<div class='pull-right'>\n
<ul class='nav'>\n<li><a href=\"/about\">About</a></li>\n<li><a href=\"/help\">Help</a>
</li>\n</ul>\n<form accept-charset=\"UTF-8\" action=\"/reports\"
class=\"navbar-search\" method=\"get\"><div style=\"margin:0;padding:0;display:inline\">
<input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div>\n
<input class=\"search-query\" id=\"query\" name=\"query\"
placeholder=\"Search\" type=\"text\" />\n</form>\n\n</div>\n</div>\n</div>\n</header>\n\n
<div class='container'>\n<div class='hero-unit center'>\n<h1>My Title</h1>\n
<h2>Welcome to The My Title Project</h2>\n<p>Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
...
最佳答案
升级到Capybara 2.0时遇到了相同的问题,并通过使用 Capybara.string
创建以下自定义RSpec匹配器设法解决了这些问题:
spec / support / utilities.rb
RSpec::Matchers::define :have_title do |text|
match do |page|
Capybara.string(page.body).has_selector?('title', text: text)
end
end
subject { page }
的规范文件中,我可以使用:
it { should have_title("My Title") }
it { should_not have_title("My Title") }
have_selector
(别名为
page.source
)上调用
page.body
来测试不可见的DOM元素:
it "should show the correct title" do
page.source.should have_selector('title', text: 'My Title')
end
subject { page }
所在的位置:
its(:source) { should have_selector('title', text: 'My Title') }
have_title
/
has_title?
匹配器,在此答案中无需自定义RSpec匹配器。此外,更新1中描述的
its(:source) { ... }
测试似乎在Capybara 2.1下无法正常运行。我已经确认
have_title
/
has_title?
可以正常工作,因此如果计划升级,最好使用以下语法:
subject { page }
时:
it { should have_title("My Title") }
it { should_not have_title("My Title") }
expect
/
it
块中使用
scenario
语法时:
expect(page).to have_title("My Title")
expect(page).to_not have_title("My Title")
关于ruby-on-rails - 如何使用Capybara 2.0测试页面标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573525/
我有一个文件字段,其中包含 opacity: 0并且正在重叠一个假按钮。它是一种常见的 css 技术,可以伪造一种在不同浏览器中一致显示的“上传按钮”。 Capybara 不允许我打电话 attach
我正在尝试为我的 ROR 应用程序编写一些 capybara cucumber 脚本,但发现很难通过每次都进行更改并运行完整功能来使脚本正确。 是否有适用于 Capybara 的 REPL(Read
像这样的html 我的代码是 attach_file("ok","./fileset/publisher/upload_pic.jpg") 但我失败了: 失败: Capybara::Element
我想在我的代码中设置不同的 Capybara 等待时间,具体取决于它们通常需要多长时间才能完全加载?我是否必须重复更改 Capybara.default_wait_time 还是有更好的方法? 最佳答
在 Capybara 中,是否可以在新窗口而不是当前窗口中打开链接? 最佳答案 如果此元素是链接,您只需获取其 href 并在新窗口中打开它: url = find('.some_link')[:hr
对于编辑记录的集成测试,我尝试用新文本替换表单输入字段中的现有文本: find("input[@id='course_title']").set("a safer workplace") 但是,每次我
我有一个动态生成的表单,如下所示: Do you like Pizza? [ ] Yes [ ] No HTML 看起来像这样: Do you like Pizza?
我正在尝试填写两个标有 id="admin_passsword"的文本框。我可以轻松访问第一个文本框,但由于除了占位符和上面的标签之外没有任何区别,我不知道如何访问第二个文本框来填写该字段。
我是一个新手,尝试使用 Capybara 测试我的 Rails 项目,但是当我尝试从我的 div 中检测一些字符串时,我对 page 和 page.body 的含义感到困惑:(in :js=>true
我在使用 rspec、capybara、capybara-webkit 和 timecop 的某些集成规范中看到错误。 Capybara::FrozenInTime: time appears
我使用以下 html 堆栈创建了自定义上传表单: 文件字段通过 display: none 的 css 隐藏属性(property)。因此,当她单击标签(自定义样式)时,用户会调用文件
假设我在 Mac OS X 上安装了 PhantomJS,我可以编写一个普通的旧 Ruby 脚本(没有 Cucumber,没有 RSpec)来驱动 Poltergeist 吗?换句话说,我想要一些 g
我希望单击我的测试应用程序上出现的弹出消息(如果存在)。我对 capybara 很陌生,似乎找不到办法做到这一点。我以前有过使用 watir 的经验,如果我使用 watir 的话,会是这样的: if
我目前使用 Watir-webdriver 进行所有前端测试,但开发团队使用 Capybara 在 Jenkins CI 上运行测试。我们都使用相同的 Cucumber 功能。 值得我们进行两次有效的
Capybara的API似乎不支持配置HTTP代理。有没有什么方法可以和它一起使用? 上下文:我使用 capybara 和 cucumber 来测试 Rails 应用程序,并使用 akephalos
我很好奇是否有更好的方法来测试页面中是否存在完整的 URL(包括协议(protocol))。 使用 Capybara 2.10.2 和 Rails 5.0.0.1,我有以下设置: rails_help
我有以下测试: it 'shows the current quantity of items inside cart' do item = create(:item) visit
我正在使用 Capybara 自动截取一些屏幕截图。 我需要 chrome 浏览器最大化运行,但我似乎无法让它工作。 基于 https://sites.google.com/a/chromium.or
下面是两个单选按钮的 html 代码,它们只是“值”属性不同 我想做的是选择“value =2”的单选按钮 我尝试使用“选择(“AmountOption”)”选择第一个单选按钮,但我想选择第二个单
我尝试使用几种变体来检查 Capybara 的 200 Ok HTTP 响应,但没有一个变体不起作用: response.should be_success page.status.should be
我是一名优秀的程序员,十分优秀!