Capybara: Possible regression in has_text? between 2.18.0 and 3.0.0

Created on 6 Apr 2018  路  6Comments  路  Source: teamcapybara/capybara

Meta

Capybara Version: 3.0.0
Driver Information (and browser if relevant): N/A

Behavior in 2.18.0

2.18.0 normalizes whitespace, as documented above def has_text?

require 'capybara'
page = Capybara::Node::Simple.new("<p>foo\nbar</p>")
page.has_text?("foo bar")
#=> true

Behavior in 3.0.0

Normalization of whitespace in 3.0.0 does not match documentation above def has_text?

require 'capybara'
page = Capybara::Node::Simple.new("<p>foo\nbar</p>")
page.has_text?("foo bar")
#=> false

My question

Is this an intended breaking change in 3.0.0 (and the documentation above def has_text? needs to be updated) or is it a regression? I don't see a mention of it in the changelog.

Documentation

Most helpful comment

Thanks for the quick reply Thomas. I think this change should be highlighted in UPGRADING.md, and I will open a PR for that.

All 6 comments

It is a breaking change in 3.0.0 so the documentation probably needs to be fixed. It is mentioned in the changelog as "Drivers are now expected to return visible text more in line with the WebDriver spec for visible text" which probably could have been clearer, but is intended to return text that is formatted more like the browser displays it.

Fixed via 0c2bf584ca0fcec5a412289b840388955e7fb2c6

Thanks for the quick reply Thomas. I think this change should be highlighted in UPGRADING.md, and I will open a PR for that.

I've got a test for a downloadable CSV, where the newline is actually being stripped _away_ with Capybara 3:

Failure/Error: expect(page).to have_content(User.csv_headers.to_csv) expected to find text "First name,Last name,Email,Telephone,Company,Admin account?,Trial account?,Confirmed?,Locked?,Account expiry,Latest sign in,Sign in count,Status,Created at,Confirmed at\n" in "First name,Last name,Email,Telephone,Company,Admin account?,Trial account?,Confirmed?,Locked?,Account expiry,Latest sign in,Sign in count,Status,Created at,Confirmed at Felisha,Mante,[email protected],(795)950-5861 x434,Bernhard-Mills,false,true,true,false,2018-05-31,,0,Complete,2018-05-01 06:56:43 +0100,2018-05-01 06:56:43 +0100 Carmel,Hilpert,[email protected],1-701-432-1106,Glover-Predovic,true,false,true,false,2018-05-31,2018-05-01 06:56:43 +0100,1,Complete,2018-05-01 06:56:43 +0100,2018-05-01 06:56:43 +0100"

(Data is from Faker)

But it sounds like if anything, the opposite should've been the case. Does anyone have any suggestions as to what's happening here?

@jalada What driver (and version) are you using? Also what is the raw html?

It's RackTest, Capybara 3.0.3. Running page.html shows the newline:

(byebug) page.text
"First name,Last name,Email,Telephone,Company,Admin account?,Trial account?,Confirmed?,Locked?,Account expiry,Latest sign in,Sign in count,Status,Created at,Confirmed at Edna,Gleichner,[email protected],361.428.8441,\"Borer, Mayert and Eichmann\",false,true,true,false,2018-06-01,,0,Complete,2018-05-02 11:47:01 +0100,2018-05-02 11:47:01 +0100 Nadine,Hegmann,[email protected],1-731-717-6255 x0134,Effertz Group,true,false,true,false,2018-06-01,2018-05-02 11:47:02 +0100,1,Complete,2018-05-02 11:47:01 +0100,2018-05-02 11:47:01 +0100"
(byebug) page.html
"First name,Last name,Email,Telephone,Company,Admin account?,Trial account?,Confirmed?,Locked?,Account expiry,Latest sign in,Sign in count,Status,Created at,Confirmed at\nEdna,Gleichner,[email protected],361.428.8441,\"Borer, Mayert and Eichmann\",false,true,true,false,2018-06-01,,0,Complete,2018-05-02 11:47:01 +0100,2018-05-02 11:47:01 +0100\nNadine,Hegmann,[email protected],1-731-717-6255 x0134,Effertz Group,true,false,true,false,2018-06-01,2018-05-02 11:47:02 +0100,1,Complete,2018-05-02 11:47:01 +0100,2018-05-02 11:47:01 +0100\n"

Thinking about it; if it's trying to be 'closer to how a browser will render it', and it thinks its HTML, then it makes sense that it's going to strip away the newline. I'm not exactly using it as its intended (inspecting CSV data instead)

Was this page helpful?
0 / 5 - 0 ratings