How does one test the content of confirm dialogs using poltergeist?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:21:36

问题


The capybara-webkit driver allows you to test the content of any confirm dialog messages that are triggered by the app. Is there a way to do this in poltergeist?


回答1:


It's not supported in poltergeist now but there's a workaround to check the content manually.

In our project we use a helper method to override the javascript confirm function, store the message and check the content.

# helper method
def handle_js_confirm
  page.evaluate_script 'window.confirmMsg = null'
  page.evaluate_script 'window.confirm = function(msg) { window.confirmMsg = msg; return true; }'
  yield
  page.evaluate_script 'window.confirmMsg'
end

# usage
handle_js_confirm do
  click_link 'Trigger javascript confirm'
end.should == 'Are you sure?'

P.S. There is an github issue discussing about this, though it's a 2 years long conversation, you can keep reading on https://github.com/jonleighton/poltergeist/issues/50



来源:https://stackoverflow.com/questions/20485884/how-does-one-test-the-content-of-confirm-dialogs-using-poltergeist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!