Selenide: shouldNotHave(text(EMPTY_STRING)) operator isn't working

Created on 17 Jul 2017  路  5Comments  路  Source: selenide/selenide

My code:
private static final String EMPTY_STRING = "";
SelenideElement Element = $(byClassName("phone-box"))
Element.shouldNotHave(text(EMPTY_STRING));

=> Test failed with message:
Element should not have text '' {By.className: phone-box}
Element: '+7 499 955-56-58'

!!!!BUT!!!!
Operator Assert.assertFalse(Element.text().equals(EMPTY_STRING)); is working fine.

not a bug

All 5 comments

Hi @AlexMMelnikov
could you provide simple html page to reproduce problem?

Hello. Yes, sure - https://aurora-tech.ru/

sholdNotBe(empty) work well

@AlexMMelnikov
I guess it isn't Selenide issue.
Explanation:

  • text(EMPTY_STRING) uses String.contains() and "" occurs between every character and also at start and end of string. That's why shouldNOT assert fails.
  • text().equals(EMPTY_STRING) - uses String.equals() and "" is not equal any non-empty string.

Hope I helped you.

@AlexMMelnikov Exactly. Methods $.shouldHave(text(...)) and $.shouldNotHave(text(...)) mean substring. Both methods are nonsence with empty string parameter.

(Probably they could throw an exception (or at least write warning) when empty parameter is given.)

What you actually need is $.sholdNotBe(empty)

Was this page helpful?
0 / 5 - 0 ratings