在 selenium 模式下,assert_response 不适用于 webrat

发布于 2024-08-17 23:32:44 字数 719 浏览 2 评论 0原文

有人知道如何使用 selenium 让assert_response 与 webrat 一起工作吗?我不断收到

NoMethodError: undefined method `response_code' for nil:NilClass

这是我的测试:

def test_basic_page_load
  visit root_path
  click_link "register"
  assert_response 200
end

这是错误:

==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
E

  1) Error:
test_basic_page_load(UserCrudTest):
NoMethodError: undefined method `response_code' for nil:NilClass
    /test/integration/user_crud_test.rb:11:in `test_basic_page_load'

Finished in 12.269964 seconds.

我确信我错过了一些愚蠢的东西,但我只是没有看到它......有什么想法吗?

Anyone know how to get assert_response to work with webrat using selenium? I keep getting

NoMethodError: undefined method `response_code' for nil:NilClass

Here's my test:

def test_basic_page_load
  visit root_path
  click_link "register"
  assert_response 200
end

Here's the error:

==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
E

  1) Error:
test_basic_page_load(UserCrudTest):
NoMethodError: undefined method `response_code' for nil:NilClass
    /test/integration/user_crud_test.rb:11:in `test_basic_page_load'

Finished in 12.269964 seconds.

I'm sure it's something silly that I'm missing, but I just don't see it.... Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2024-08-24 23:32:44

嗯嗯,目前看来是不可能的。

测试过程从命令行(在 Webrat::Selenium::ApplicationServers::Rails 中)启动一个新的 mongrel 实例,因此无权访问 @controllerActionController::Integration::Session.get 设置的变量。这个@controller变量由assert_response使用。

我想知道使用 fork 而不是 system 启动一个混合服务器需要做多少工作(在 Webrat::Selenium::ApplicationServers::Rails.start 中) )。它可以与 selenium.wait_for_page_to_load 结合使用,以确保测试等待服务器进程完成响应。只是一个想法,我可能不会再研究它了。

对于任何使用 webrat 和 Shoulda 的人来说,这样的东西仍然有效:

setup do
  fill_in :login, :with => Factory.next(:login)
  fill_in :email, :with => Factory.next(:email)
  fill_in "Password", :with => 'asdf'
  fill_in "Password confirmation", :with => 'asdf'
  click_button :Register
  selenium.wait_for_page_to_load(10)
end
should_create :user

干杯,
布莱恩

Hmmm, it looks like it's not possible at the moment.

The testing process starts a new mongrel instance from the command line (in Webrat::Selenium::ApplicationServers::Rails) and therefore doesn't have access to the @controller variable that would be set by ActionController::Integration::Session.get. This @controller variable is used by assert_response.

I wonder how much work it would be to start up a mongrel server using fork instead of system (in Webrat::Selenium::ApplicationServers::Rails.start). It could maybe be combined with selenium.wait_for_page_to_load to ensure the test waits for the server process to finish the response. Just an idea, I probably won't look into it any more.

For anyone using webrat with shoulda, something like this will still work:

setup do
  fill_in :login, :with => Factory.next(:login)
  fill_in :email, :with => Factory.next(:email)
  fill_in "Password", :with => 'asdf'
  fill_in "Password confirmation", :with => 'asdf'
  click_button :Register
  selenium.wait_for_page_to_load(10)
end
should_create :user

Cheers,
Brian

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文