ActionCable not connecting during capybara-webkit feature spec
Asked Answered
A

2

7

I have a problem using actioncable with feature specs using Capybara-webkit. Actioncable is working perfectly on my development server, but when testing the javascript cant seem to connect.

This is the output from the javascript console which is running during my feature spec

WebSocket connection to 'ws://127.0.0.1:32789/cable' failed: Unexpected response code: 200

This is the output of my test.log at that moment

GET     "/cable"  for 127.0.0.1  at 2017-01-26 13:33:23 +0000
GET     "/cable/"  for 127.0.0.1  at 2017-01-26 13:33:23 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)

Its strange because it seems like Its connecting fine according to the log, but the javascript throws an error and stops executing... Also how is 200 an error code? Doesn't 200 status code always mean OK?

Thanks in advance

Adala answered 26/1, 2017 at 14:9 Comment(1)
WebSocket server should respond with 101 Switching Protocols.Leix
A
13

The default server used by Capybara is :webrick which doesn't support testing ActionCable (it will be changing whenever Capybara 3.0 releases). To switch it to using puma which will support testing with ActionCable you can specify Capybara.server = :puma as part of your Capybara configuration.

Arsenide answered 26/1, 2017 at 19:3 Comment(1)
make sure to require 'puma', and add it your gems file or gemspecEfren
D
0

2023, Rails 7.0.4, capybara 3.39.0, Turbo::StreamsChannel works well with selenium webdriver.

Problem seems to be solved from capybara.

My config, in rails_helper is:

  config.before(:each, type: :system) do
    driven_by :selenium, using: :headless_chrome, screen_size: [1200, 600]
  end
Danette answered 1/5, 2023 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.