thefrontside / interactors

Composable page objects for components
https://frontside.com/interactors
MIT License
28 stars 3 forks source link

Trim selector text by default? #25

Open cowboyd opened 3 years ago

cowboyd commented 3 years ago

Safari includes up to one newline in its innerText property for elements. Why, I'm not sure, but it ends up that you don't match your selectors on different platforms:

image showing search for selector DEFAULT, but no match because the actual selector is DEFAULT + newline

Should we trim the selector before matching against it?

cowboyd commented 3 years ago

One posible strategy would be instead of trimming the element locator, to always wrap the locator in a matcher. The default would be trimmed, but we could also have a strictEquals locator that that did a === as its match. So that if it was what you really wanted you could match that.

jnicklas commented 3 years ago

Ugh, this is annoying. IIRC Capybara does trim the text, which seems reasonable since whitespace is very rarely relevant in HTML documents anyway. I think the HTML interactor could do this, that way it'd still be overridable if someone really wants to.

wKich commented 3 years ago

Most interactors override the locator method. So I think we should implement trimming on the internal level, like adding the special trim matcher.