0

Ok. Either this is actually weird, or there's something fundamental that I'm missing. I have a bit of code that tries to assert the non-existence of a list of WebElements. If I use assert and < 1 for the list size, it works. But my preferred assertion method is assertThat .isLessThan, which does NOT work in the exact same circumstances.

The code:

@FindBy(css = "[data-e2e-selector=soknad-boks-selector]")
private List<WebElement> soknadbokser;

public void forventIngenSoknaderPaMinArbeidsflate() {
    waitForelementNotVisible();

    //assertThat(soknadbokser.size()).isLessThan(1); // DOES NOT WORK
    assert(soknadbokser.size()<1);                   // WORKS
}

private void waitForelementNotVisible() {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("[data-e2e-selector=soknad-boks]")));
}

When using the assertThat above, I get the not-expected assertion error:

java.lang.AssertionError: 
Expecting:
 <1>
to be less than:
 <1> 

How can this be?

It might be worth to mention that the assertThat() has been in use for several years in this code, before the system was upgraded from Angular6 to the latest version. But that shouldn't have anything to do with Java's assertThat() claiming that a size() of zero is 1? Checking the variables naturally reveals that the size() is indeed zero, as proven by the assert < 1. But apparently not according to assertThat().isLessTHan().

  • I created an empty list and tried with `assertThat().isLessThan()`. Assertion passed and it worked perfectly. Did you try printing the list `size()` before `assertThat().isLessThan()`? – kaweesha Jun 25 '20 at 11:15
  • what is `assertThat()`? is that a hamcrest lib or what? – Alexey R. Jun 25 '20 at 12:09
  • @kaweesha Yes, I did. The list size is indeed 0. Also, the assert wouldn't pass if it wasn't. –  Jun 25 '20 at 18:02

0 Answers0