create a post request using poltergeist and capybara

杀马特。学长 韩版系。学妹 提交于 2020-02-24 12:01:32

问题


I'm transitioning from Capybara backed by the default Rack driver to Capybara backed by Poltergeist.

For frustrating reasons, I need to manipulate session data before loading a page. But I couldn't figure out how to manipulate the session directly with the Rack driver, so I

Capybara.current_session.driver.submit :post, "/current_search", {:session => :data }

Unfortunately, the Poltergeist driver object has no submit method, as the Rack driver had.

There are three possibilities:

  • How do I submit a POST request with poltergeist/phantomjs? (Implementing this seems the easiest)
  • How can I manipulate session data directly with poltergeist/phantomjs?
  • I can restructure the code so that manipulating session data directly is no longer necessary. This would be time-consuming and is low-priority.

PS: due to being on Ruby 1.8, we are stuck on Poltergeist v1.0.2


回答1:


The idea of capybara is to test user interaction, so you can do the POST request in the same way a user would do.

On your case it would be something like:

visit '/search'
fill_in '.search-box', :with => "search query"
click_on "Submit"

Is there any reason to not do it this way?



来源:https://stackoverflow.com/questions/16803831/create-a-post-request-using-poltergeist-and-capybara

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