Capybara Webkit不会传递来自angular的参数 [英] Capybara webkit doesn't pass params from angular

查看:62
本文介绍了Capybara Webkit不会传递来自angular的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将硒测试套件移植到capybara-webkit.Rails应用程序在Rails视图中嵌入了一个角度应用程序,并且与 webkit 的行为不符.

I am trying to port a selenium test suite to capybara-webkit. The Rails app has an angular app embedded in the rails views and is not behaving as expected with webkit.

像这样的测试:

需要"spec_helper"

require 'spec_helper'

feature 'Editing company profiles' do
  before do
    @user = create(:employee)
    @company = Company.find(@user.employer.id)
    sign_in_as! @user
  end

  scenario 'successfully', js: true do
    click_link 'Dashboard'
    click_link @company.name
    click_button 'Edit'
    fill_in 'company_name', with: 'new name'
    click_button 'Save'

    expect(page).to have_content "Your company profile has been updated!"
  end
end

将通过硒测试,但通过 webkit 我会收到错误消息

Will pass without issue in selenium, but with webkit I get the error

 Failure/Error: Unable to find matching line from backtrace
 ActionController::ParameterMissing:
   param is missing or the value is empty: company
 # ./app/controllers/api/v1/companies_controller.rb:23:in `company_params'
 # ./app/controllers/api/v1/companies_controller.rb:10:in `update'

缺少踪迹,可能是因为它来自有角度的土地,但是错误报告说客户端没有参数.我已经尝试过 capybara-angular gem,但是它没有帮助.我也尝试过使用capybara保存该页面,并且在那里看起来没有什么不正常的地方,是否有任何方法可以访问在此测试中生成的webkit内的 PATCH 请求?我也遇到了 poltergeist 类似的错误.

The trace is missing, maybe because it's from angular land, but the error is reporting that no params are coming from the client. I've tried the capybara-angular gem, but it has not helped. I've also tried saving the page with capybara and nothing looks out of place there, are there any ways to access the PATCH request inside of webkit that's being generated in this test? I've also gotten similar errors with poltergeist.

有人用角度+导轨设置无头rspec测试吗?关于如何调试为什么不从客户端发送数据的任何提示?

Has anyone setup headless rspec testing with angular + rails? Any tips on how to debug why data isn't being sent over from the client?

推荐答案

如果没有看到您的所有代码,就好像是与 capybara-webkit gem 中的capybara-webkit/issues/553>已知问题正文到服务器.

Without seeing all of your code, this feels like it could be a problem associated with a known issue in the capybara-webkit gem is unable to pass entity bodies to the server.

我怀疑更新请求是作为 PATCH 请求发送的(适当的),但是gem的问题导致测试失败.

I suspect that the update request is being sent as a PATCH request (which is appropriate), but the issue with the gem results in failure for your tests.

您的问题的一种解决方法是将请求的方法更改为 PUT POST ,上面链接的问题显示了一些选项.您将能够使测试通过,但是由您决定更改请求类型是否值得通过测试.

A workaround to your problem is to change the method of the request to PUT or POST, the issue linked above shows some options. You will be able to get your test to pass, but it's up to you to decide if changing the request type is worth getting your test to pass.

注意:实际上,实际上不使用 PATCH 可能并不重要,因为从技术上讲,您可以使用(其中的 个)其他http方法可以互换使用-但请谨慎使用,因为在给定情况下有使用特定http方法的原因.请参阅此 ruby​​onrails.org几年前的帖子,了解一些详细信息.

Note: In practice it may not matter if you don't actually use PATCH, as you could technically use (some of) the other http methods interchangeably -- but use caution as there are reasons to use a specific http method for a given situation. See this rubyonrails.org post from a few years ago for some details.

这篇关于Capybara Webkit不会传递来自angular的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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