cucumber / webrat:如何测试是否未禁用提交按钮

时间:2011-11-10 11:44:37

标签: capybara webrat

刚开始用webrat黄瓜。我有这些功能步骤:

When /^I choose a DVD$/ do
  #just click the first one we see
  check("optional-dvds[]")
end

Then /^I should be able to place my order$/ do
  #the place my order button should be clickable
end

有问题的按钮有这个html:

<input disabled="disabled" id="submit_button" name="commit" type="submit" value="Please send this DVD">

并且,当用户点击DVD时,某些js会运行并从按钮中删除已禁用的属性。因此,第二步需要在执行上一步后检查它是否没有“禁用”属性。我该如何测试?我可以想到一种方法,使用xpath并检查页面上是否存在禁用的提交按钮,但我宁愿做一些更明确的事情(实际上,更多jquery-esqu)沿着(伪代码)< / p>

$("#submit_button").attr("disabled").should be_false

或沿着这些方向的东西。我知道这是一个可怕的混搭jquery和rspec btw:)

1 个答案:

答案 0 :(得分:2)

试试这个

page.should have_no_xpath "//input[@id='submit_button' and @disabled]"

或者这个

page.should have_no_selector "#submit_button", :disabled => 'disabled'