dgi*_*rez 7 html5 webkit rspec ruby-on-rails capybara
我正在尝试使用Rspec和Capybara对表单进行失败的验证,该表单未填写“必需”输入,因此失败。理解HTML5的新导航员提供了内置的验证,我了解Capybara也在使用该验证。以前我在用
page.should have_error
Run Code Online (Sandbox Code Playgroud)
这对我不起作用了。
有人知道现在如何测试吗?
非常感谢!
大卫
fro*_*001 11
HTML5 客户端验证很难找到。我发现这篇文章有一个很好的答案。代码是:
describe "when I leave required field empty" do
it "I get an the correct html5 validation error" do
#Leave the field empty
click_on "Save" # or whichever button triggers the submit
message = page.find("#field_id_attr").native.attribute("validationMessage")
expect(message).to eq "Please fill out this field."
end
end
Run Code Online (Sandbox Code Playgroud)
基本上它的工作方式是 field 元素有一个名为“validationMessage”的属性,过程是:
| 归档时间: |
|
| 查看次数: |
1556 次 |
| 最近记录: |