我正在使用RSpec2和Capybara进行验收测试.
我想断言链接在Capybara中是否被禁用.我怎样才能做到这一点?
我有一个应用程序启用/禁用按钮以响应UI中发生的事情.
我可以轻松地使用水豚来检测按钮是否存在
should have_button 'save'
Run Code Online (Sandbox Code Playgroud)
但我不知道如何验证保存按钮的状态.那是:
我怎样写一个水豚断言检查按钮的存在和它的启用或禁用状态?
我已经一起检查了一个禁用按钮的检查; 对于启用,我想我可以验证是否有匹配的按钮,并且没有匹配的禁用按钮.但至少可以说,这是笨重的.
这似乎是一个基本的UI检查,我相信我已经错过了一些东西,但我似乎无法弄清楚是什么.
根据gregates的回答跟进:
正如我在评论中提到的,Capybara行为取决于潜在的驱动因素.我们正在使用webkit,它返回"true"/"false"字符串结果.显然,其他驱动程序返回true/false.Capybara的人都知道这个问题(github.com/jnicklas/capybara/issues/705),但他们觉得(可能是正确的)解决它并不是他们的问题.
我没有让我的测试依赖于我正在使用的驱动程序,而是最终创建了一个自定义匹配器:
RSpec::Matchers.define :be_enabled do
match do |actual|
driver_result = actual[:disabled]
# nil, false, or "false" will all satisfy this matcher
(driver_result.nil? || driver_result == false || driver_result == "false").should be_true
end
end
RSpec::Matchers.define :be_disabled do
match do |actual|
driver_result = actual[:disabled]
(driver_result == "disabled" || driver_result == true || driver_result == "true").should be_true
end
end
Run Code Online (Sandbox Code Playgroud)
然后你可以输入:
user_license_area.find_button('Save').should be_disabled
Run Code Online (Sandbox Code Playgroud) 在Cucumber中,我正在尝试创建这样的步骤:
Then I should see "Example business name" in the "Business name" input
Run Code Online (Sandbox Code Playgroud)
我想将"商家名称"输入定义为"标签有文字的输入"商业名称."
这是我到目前为止所做的一切:
Then /^I should see "([^"]*)" in the "([^"]*)" input$/ do |content, labeltext|
# Not sure what to put here
end
Run Code Online (Sandbox Code Playgroud)
在jQuery中,我会查找带有该文本的标签,查看其"for"属性,并找到具有该id的输入.但到目前为止我在Cucumber中看到的唯一选择器是这些:
within("input:nth-child(#{pos.to_i}")
Run Code Online (Sandbox Code Playgroud)
和
page.should have_content('foo')
Run Code Online (Sandbox Code Playgroud)
任何人都可以使用Webrat/Capybara选择器语法建议解决方案吗?