teamcapybara / capybara

Acceptance test framework for web applications

Home Page:http://teamcapybara.github.io/capybara/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

turbo-cable-stream-source element cannot be found

lazylester opened this issue · comments

Meta

Capybara Version: 3.39.2
selenium-webdriver 4.11.0
chrome: 119

Trying to avoid putting 'sleep' in my tests. When first visiting a page that has a turbo stream attached, there is a delay before the stream is connected. I believe that polling the 'connected' attribute on the will serve as a gate, so we can wait for the stream to be connected before generating an action that produces a turbo-stream message.

However capybara does not seem to recognize the element on the page.

Expected Behavior

successfully find the element on the page

Actual Behavior

not found

Steps to reproduce

Rails 7.0 application
View contains the following directive:
<%= turbo_stream_from "messages" %>

where "messages" here is just an arbitrary name given to the channel.

rspec/capybara test command, after the page is rendered:
page.find('turbo-cable-stream-source')

html on the page:
<div id='content'> <turbo-cable-stream-source channel="Turbo::StreamsChannel" signed-stream-name="Im1lc3NhZ2VzIg==--2f5863d2884130157db5e53ce3256fb7ba2defbde6dfae02722f129356fa9c1c"></turbo-cable-stream-source>

I'm sorry but this isn't clear enough to do anything about. You talk about the 'connected' attribute but I don't see anything looking at that in what you've provided. If you want to provide a repo that reproduces the issue you're seeing I'll try to look at it, otherwise I'm not really sure what you're doing.

Sorry I wasn't clear. I've put up a repo of a Rails app that demonstrates the issue. Just run rspec spec and the single assertion will fail b/c the turbo-cable-stream-source element is not found. The repo is here. Do you see the problem? Or am I doing something stupid? You can pause the test for any amount of time and type in the expectation manually into the debug console... it's not a timing problem. Capybara says 'not found' even though you can see the element on the page in the browser debug tools.

I hacked a test for the reported anomaly in spec/basic_node_spec.rb, and the <turbo-cable-stream-source> element was successfully found by expect(string).to have_selector('turbo-cable-stream-source') expectation. So at it's core, capybara can detect the element. I haven't yet figured out how to bring selenium into the test to provide a test that corroborates the rails app that I linked in my previous comment.