cocoon 使用 rspec 和 capybara 动态添加的测试字段 [英] Testing fields added dynamically by cocoon using rspec and capybara

查看:22
本文介绍了cocoon 使用 rspec 和 capybara 动态添加的测试字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人测试由 cocoon 动态添加的字段?

I was wondering whether anybody tests fields that were dynamically added by cocoon?

这是一个很好的节省时间的方法,但是所有动态添加的字段都在 ID 和名称中添加了非常长的数字.这意味着我必须跳过需要页面上多个(一组)字段的测试.

It's a great little time saver but all of the fields that are added dynamically have really long numerics added to the ID and name. This means that I have to skip testing that requires more than one (set of) field(s) on the page.

推荐答案

也许使用 Capybara finders 所有,首先和选择器输入.像这样:

Maybe using Capybara finders all, first and the selector input. Something like this:

visit new_resource_path
click_link "Add a Nested Resource"
first("input[name='nested_resource[name]']").set("Nested Resource")
click_button "submit"

visit new_resource_path
click_link "Add a Nested Resource"
click_link "Add a Nested resource"
all("input[name='nested_resource[name]']").each do |input|
  input.set("Nested Resource")
end
click_button "submit

这只是一种方法,我从未使用过 cocoon.然而,这是一种测试动态输入的表单.

This is only an approach, I've never worked with cocoon. This is however, a form to test dynamic inputs.

这篇关于cocoon 使用 rspec 和 capybara 动态添加的测试字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆