问题
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