编写我的Ruby-Watir-黄瓜bdd测试,我得到了:
NoMethodError: undefined method `msg=' for #<Watir::Browser:0x0000558fbcdc0cc0>
./features/support/pages/message_page.rb:27:in `escribir'
./features/step_definitions/message_steps.rb:14:in `/^I'm able to write and send a "([^"]*)" successfully$/'
./features/send_messages.feature:12:in `Then I'm able to write and send a "Robot message" successfully'
./features/send_messages.feature:9:in `Then I'm able to write and send a "<message>" successfully'
1 scenario (1 failed)
4 steps (1 failed, 3 passed)
0m12.939s
Process finished with exit code 1
当我已经定义了方法时:
class MessagePage
include PageObject
@@browser = Watir::Browser.new
page_url 'https://www.linkedin.com/messaging/'
text_field(:searchcontact, name: 'searchTerm')
div(:txtmessage,:role => "textbox")
button(:btnsend,:type => 'submit')
div(:txtfield,:xpath =>"//div//div[@role='textbox']")
text_field(:mensaje,:xpath =>"//div//div[@role='textbox']")
div(:msg,:role => "textbox") /// HERE!!!
def searchcontact contact
self.searchcontact = contact
#searchcontact(contact).send_keys(:enter)
wait 5
end
def buscar contact
wait_until do
searchcontact_element.visible?
self.searchcontact = contact
end
self.searchcontact = contact
end
def escribir (message)
self.msg = message
wait 5
end
def writemessage message
wait_until do
msg_element.visible?
self.msg = message
end
self.msg = message
end
def sendmessage
btnsend
end
end
div(:msg,:role => "textbox")
不会生成#msg=
方法。它仅定义:#msg
-获取div的文本#msg?
-检查div是否存在#msg_element
-获取PageObject :: Elements :: Elementmsg.click然后msg.send_keys('blah')
或者也许是文本框,您可以根据页面的编码方式直接对其进行操作-因此msg.send_keys('blah')可能直接起作用。