Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby rspec-获取;使用'定位文本区域#文本字段';已弃用;_Ruby_Rspec_Textarea - Fatal编程技术网

Ruby rspec-获取;使用'定位文本区域#文本字段';已弃用;

Ruby rspec-获取;使用'定位文本区域#文本字段';已弃用;,ruby,rspec,textarea,Ruby,Rspec,Textarea,我有一个测试断言:- expect(browser.text_fields[2].id).to eq "new_user_email" 它通过了,但我收到了以下弃用警告消息: Locating textareas with '#text_field' is deprecated. Please, use '#textarea' method instead. 我试着把测试改为 expect(browser.textarea[2].id).to eq "new_user_email" 但

我有一个测试断言:-

expect(browser.text_fields[2].id).to eq "new_user_email"
它通过了,但我收到了以下弃用警告消息:

Locating textareas with '#text_field' is deprecated.  
Please, use '#textarea' method instead.
我试着把测试改为

expect(browser.textarea[2].id).to eq "new_user_email"
但是得到

undefined method `[]' for #<Watir::TextArea:0x00000001c128d8>
得到

 Failure/Error: expect(browser.textareas[2].id).to eq "new_user_email"

   expected: "new_user_email"
        got: ""
我查看了来源,但没有帮助我:-

VALID_TEXT_FIELD_TAGS = %w[input textarea]

def tag_name_matches?(tag_name, _)
  VALID_TEXT_FIELD_TAGS.include?(tag_name)
end

def by_id
  el = super
  el if el and not NON_TEXT_TYPES.include? el.attribute(:type)
end

def validate_element(element)
  if element.tag_name.downcase == 'textarea'
    warn "Locating textareas with '#text_field' is deprecated. Please, use '#textarea' method instead."
  end
  super
end

我怎样才能摆脱弃用警告

我猜您的页面有多个文本字段和多个文本区域

带有
text\u字段的原始代码将捕获文本字段和文本区域,并将它们放在同一个集合中。这有点令人惊讶,可能也是瓦蒂尔不赞成这种行为的原因

使用
textarea
仅返回单个对象,而不是集合。这就是
[]
未定义的原因

使用
textareas
仅返回文本区域,而不是两者的组合。这个文本区域可能是页面上的第一个区域,后面还有一个没有id的区域。如果没有多个,我希望您会收到一个错误,说没有这样的元素

我强烈建议不要依赖你的元素的位置;它往往会使你的测试过于脆弱。相反,您应该根据需要使用选择器(CSS或XPath)。例如,您应该能够使用

browser.textarea(id: 'new_user_email')
browser.textarea(id: 'new_user_email')