cuprite icon indicating copy to clipboard operation
cuprite copied to clipboard

Replace \t for " " ?

Open rogercampos opened this issue 5 years ago • 2 comments

I've been working recently on adopting cuprite in a big rails app. One thing that triggered many test failures was that the tab char is still present in the page body when asserting, for example:

 Failure/Error: expect(page).to have_text('TOTAL £ 239.18')
   expected to find text "TOTAL £ 239.18" in "Voucher successfully added\n+44 203 5148 622\nAccount\nCart\nCheckout\nOrder finished\nYour order\n10 × Producto num. 1 / en\nMate Big A7\n\t\n£ 197.83\n  £ 181.34\nSubtotal\t\n£ 197.83\n  £ 181.34\nStandard to Spain\t£ 16.33\nVAT 21 %\t£ 41.51\nTOTAL\t£ 239.18\nVoucher: PROMO1\nProceed to checkout\nProducto num. 1 / en\n10 buttons, 1 design\nEdit design\nAdd another design"

Selenium was stripping those chars away, but now the text is "TOTAL\t£ 239.18" instead of "TOTAL £ 239.18".

This is fixed by adding .gsub(/\t+/, " ") in Node#visible_text, as i've patched for now.

This seems like a reasonable thing to do, given that the same method is already transforming other chars. What do you think? i'll submit a PR if you agree with the change.

rogercampos avatar Sep 19 '19 13:09 rogercampos

Hi @rogercampos, completely agree though perhaps it is better to do in index.js on JS. Sure go ahead!

route avatar Sep 19 '19 13:09 route

@rogercampos I was able to avoid adding gsub or actually changing the text in the expectations by enabling this setting on rails_helper.rb:

Capybara.default_normalize_ws = true

That setting got rid of all of the extra whitespace characters.

mauro-oto avatar Dec 09 '20 15:12 mauro-oto