我有一个测试断言:-
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>
我试过了
expect(browser.textareas[2].id).to eq "new_user_email"
并得到
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
如何摆脱弃用警告?