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

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

问题描述

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

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查找器。这样的事情:

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

这只是一种方法,我从未使用过茧,但是,这是测试动态输入的一种形式。

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

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

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