gpt4 book ai didi

checkbox - 当表单中出现多个相似字段时,更好的 cucumber (基于 capybara )选择

转载 作者:行者123 更新时间:2023-12-04 23:08:11 24 4
gpt4 key购买 nike

(Some background if it helps: our Rails app has a bunch of potentially repetitive dynamically-generated forms using double-nested fields, with ids in the pattern foo_attributes_0_bar_attributes_0_bat_12, where basically the first two numbers increment based on how many repetitions of the nested form there are, and the last number is the id of the particular "bat" object. This makes selection in Cucumber for testing difficult!)


我正在尝试编写一些这样的步骤:
When I check the 1st checkbox with the value "Bat 12"

或者
When I check the 3rd checkbox with id matching "bar_attributes_bat"

我有以下工作,但我查找复选框(或字段)的方法对我来说似乎非常糟糕和低效:
When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |number, junk, value|
check(page.all("input").select {|el| el.node['value'] == value}[(number.to_i-1)].node['id'])
end

When /^I check the (\d+)(st|nd|rd|th) checkbox with id matching "([^"]*)"$/ do |number, junk, id_string|
check(page.all("input").select {|el| el.node['id'] && el.node['id'].match(/#{id_string}/)}[(number.to_i-1)].node['id'])
end

有没有更好的方法来选择这些输入元素?

最佳答案

When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |index, junk,   value|
page.all("input[value='#{value}']")[index.to_i-1].check
end

关于checkbox - 当表单中出现多个相似字段时,更好的 cucumber (基于 capybara )选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6161895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com