使用poltergeist和capybara创建发布请求 [英] create a post request using poltergeist and capybara

查看:85
本文介绍了使用poltergeist和capybara创建发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从默认Rack驱动程序支持的Capybara过渡到Poltergeist支持的Capybara。

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

出于令人沮丧的原因,我需要在加载页面之前处理会话数据。但是我不知道如何直接使用Rack驱动程序来操纵会话,所以我

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 }

不幸的是,Poltergeist 司机对象没有像机架驱动程序那样的 submit 方法。

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

有三种可能:


  • 如何使用poltergeist / phantomjs提交POST请求?(实施这似乎是最简单的方法)

  • 如何直接使用poltergeist / phantomjs操作会话数据?

  • 我可以重组代码,从而不再需要直接操作会话数据。

  • 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:由于使用的是Ruby 1.8,因此我们只能使用 Poltergeist v1.0.2

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

推荐答案

capybara的想法是测试用户交互,因此您可以用与用户相同的方式执行POST请求。

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?

这篇关于使用poltergeist和capybara创建发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆