问题
I'm trying to test a post request with capybara and cucumber. I can't visit a page and press a link to send the request because it has a confirm dialogue and I haven't made it work with javascript so I'm trying to use the post method and then test if it redirects to the appropriated url but I'm getting:
No response yet. Request a page first. (Rack::Test::Error)
My code is:
page.driver.post url
page.driver.status_code.should be 302
follow_redirect!
It's working fine until follow_redirect!
. I've tried page.driver.follow_redirects!
but it doesn't work either.
Any help?
回答1:
Capybara::Rails::TestCase.class_eval do
def post(url)
page.driver.post url
visit page.driver.response.location
end
end
回答2:
I would recommend you to dismiss the confirm dialogue by using this:
https://stackoverflow.com/a/2609244/560123
That way you wouldn't care about making the post by yourself, and instead trust your application code to do the post request.
Regards
来源:https://stackoverflow.com/questions/12569188/how-to-test-post-request-and-follow-redirects-with-capybara