简体   繁体   English

Selenium::WebDriver::Error::UnknownError: 无效的内容类型

[英]Selenium::WebDriver::Error::UnknownError: Invalid Content-Type

In my Ruby on Rails 5 app I have the following test that started failing without any changes to the code:在我的 Ruby on Rails 5 应用程序中,我有以下测试开始失败,无需对代码进行任何更改:

require 'rails_helper'

RSpec.describe 'Agent Groups Index Page' do
  let(:active_user) {FactoryBot.create(:agent)}
  let(:user_group) {FactoryBot.create(:group, servicing_agent_id: active_user.id)}
  let(:other_user) {FactoryBot.create(:agent, :other_agent)}
  let(:other_group) {FactoryBot.create(:group, servicing_agent_id: other_user.id)}
  let(:zip_code) {FactoryBot.create(:zip_code)}

  before do
    visit new_user_session_path
    fill_in 'user_email', with: active_user.email
    fill_in 'user_password', with: active_user.password
    click_button 'Login'
  end

  context 'has no groups' do
    before do
      other_user
      other_group
      visit groups_path()
    end

    scenario 'sees empty list', js: true do
      expect(page).to have_content 'No data available in table'
    end
  end
end

it returns the following error:它返回以下错误:

Failure/Error: click_button 'Login'
 Selenium::WebDriver::Error::UnknownError:
   Invalid Content-Type
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:81:in `new'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:81:in `create_response'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/bridge.rb:164:in `execute'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/w3c/bridge.rb:535:in `execute'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/remote/w3c/bridge.rb:358:in `click_element'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/element.rb:72:in `click'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/selenium/node.rb:94:in `click'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/node/element.rb:133:in `block in click'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/node/base.rb:83:in `synchronize'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/node/element.rb:133:in `click'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/node/actions.rb:58:in `click_button'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/session.rb:740:in `block (2 levels) in <class:Session>'
 # /Users/override23/.rvm/gems/ruby-2.5.1@-global/gems/capybara-3.0.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
 # ./spec/support/helpers/session_helpers.rb:7:in `signin'
 # ./spec/features/agents/groups/groups_index_spec.rb:11:in `block (2 levels) in <top (required)>'

Any ideas what can cause this strange behavior?有什么想法会导致这种奇怪的行为吗?

I had the same problem with our Docker-based CI setup.我在基于 Docker 的 CI 设置中遇到了同样的问题。 I was able to fix it by specifying the version of the Selenium image that Capybara talks to.我可以通过指定 Capybara 与之交谈的 Selenium 图像的版本来修复它。

So in the docker-compose.yml our configuration went from:所以在docker-compose.yml我们的配置来自:

  firefox:
    image: selenium/standalone-firefox
    volumes:
      - /dev/shm:/dev/shm

To:至:

  firefox:
    image: selenium/standalone-firefox:3.11
    volumes:
      - /dev/shm:/dev/shm

In addition to the above, we specified the versions of capybara and selenium-webdriver in the Gemfile for this project to give us certainty about compatibility.除了上述之外,我们在此项目的Gemfile中指定了capybaraselenium-webdriver的版本,以便我们确定兼容性。 We will upgrade them all in lockstep in the future, but this is a good way to keep things working in the meantime.我们将在未来同步升级它们,但这是同时保持工作正常的好方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium::WebDriver::Error::UnknownError: 未知错误: Chrome 启动失败: 异常退出 - Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally 如何在Amazon Linux上使用带有chrome驱动程序的selenium。 错误:Selenium :: WebDriver :: Error :: UnknownError:未知错误:找不到Chrome二进制文件 - How to use selenium with chrome driver on Amazon Linux. error: Selenium::WebDriver::Error::UnknownError: unknown error: cannot find Chrome binary Net :: ReadTimeout:Net :: ReadTimeout和Selenium :: WebDriver :: Error :: UnknownError:未知错误:Chrome无法启动Rails 5.1.beta系统测试 - Net::ReadTimeout: Net::ReadTimeout and Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start on Rails 5.1.beta System Test Selenium WebDriver 错误:session id 无效 - Selenium WebDriver Error: invalid session id 如何查找从nginx返回的无效内容类型? - How to find an invalid content-type being returned from nginx? Elasticsearch Ruby on Rails Content-Type 标头错误 - Elasticsearch Ruby on Rails Content-Type header error 覆盖默认的Content-Type - Overriding the default Content-Type 在rails中不需要Content-Type“application / json” - Content-Type “application/json” not required in rails 使用 HTTParty 将 Content-Type 更改为 JSON - Changing Content-Type to JSON using HTTParty RSpec-如何添加默认内容类型? - RSpec - How to add default content-type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM