First assert fail displays twice in report when using soft assertion in TestNG.
FAIL #1: Element should visible {div.text}
Element: '<div class="text" displayed:false></div>'
Screenshot: file:/F:/workspace_csrc/SelenideBoilerplate/build/reports/tests/1592102485210.0.png
Page source: file:/F:/workspace_csrc/SelenideBoilerplate/build/reports/tests/1592102485210.0.html
Timeout: 4 s.
FAIL #2: Element should be visible {div.text}
Element: '<div class="text" displayed:false></div>'
Screenshot: file:/F:/workspace_csrc/SelenideBoilerplate/build/reports/tests/1592102489712.1.png
Page source: file:/F:/workspace_csrc/SelenideBoilerplate/build/reports/tests/1592102489712.1.html
Timeout: 4 s.
```
## Tell us about your environment
* **Selenide Version**: 5.2.4
* **Chrome\Firefox\IE Version**: chrome Version=79.0.3945.79
* **Browser Driver Version**: 79.0.x
* **Selenium Version**: 3.141.59
* **OS Version**: windows 10.0.18363.900
## Code To Reproduce Issue [ Good To Have ]
@Listeners({ SoftAsserts.class})
public class SoftAssertDemoTest {
static Logger logger = LoggerFactory.getLogger(SoftAssertDemoTest.class);
@BeforeMethod(alwaysRun=true)
public void setUp() {
Configuration.assertionMode = SOFT;
}
@Test
public void test1() {
open("http://www.baidu.com");
$("div.text").should(visible).click();
$("div#u").should(visible).click();
}
}
```
Created a MCVE for this issue - https://github.com/s4ik4t/selenide-issue-1201
The second assertion wasn't executed at all.
Hi @s4ik4t !
Thank you for MCVE! It really helps investigate this tricky case.
The second assertion wasn't executed at all.
In fact it is not a bug. I will explain it.
$("div.text").should(visible).click();
Here we have assert(visibility) and action(click). So next assert $("div#u").should(visible) can not be executed because click action fails(element doesn't exist) and it failed test before the second assert will be executed.
But I agree, console output is not obvious. It looks like this:
FAIL #1: Element not found {div.text}
Expected: visible
Screenshot: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979728581.0.png
Page source: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979728581.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.text"}
FAIL #2: Element not found {div.text}
Expected: visible or transparent: visible or have css value opacity=0
Screenshot: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979733090.1.png
Page source: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979733090.1.html
Timeout: 4 s.
Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.text"}
FAIL #2 seems duplication. But it is not from my point of view.
FAIL #2 apprears because underhood selenide always checks element visibility\intractability before all actions and underhood it handles as assert too! That's why it appears in error log.
I am not sure that here we have something to fix.
cc @clobob
So the action to the element will fail and terminal test. soft assertion just affects all 'should*' method. thanks.
This issue can be closed.
Hi @s4ik4t !
Thank you for MCVE! It really helps investigate this tricky case.
The second assertion wasn't executed at all.
In fact it is not a bug. I will explain it.
$("div.text").should(visible).click();
Here we have assert(visibility) and action(click). So next assert$("div#u").should(visible)can not be executed because click action fails(element doesn't exist) and it failed test before the second assert will be executed.But I agree, console output is not obvious. It looks like this:
FAIL #1: Element not found {div.text} Expected: visible Screenshot: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979728581.0.png Page source: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979728581.0.html Timeout: 4 s. Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.text"} FAIL #2: Element not found {div.text} Expected: visible or transparent: visible or have css value opacity=0 Screenshot: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979733090.1.png Page source: file:/C:/Temp/selenide-issue-1201/build/reports/tests/1598979733090.1.html Timeout: 4 s. Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.text"}FAIL #2 seems duplication. But it is not from my point of view.
FAIL #2apprears because underhood selenide always checks element visibility\intractability before all actions and underhood it handles as assert too! That's why it appears in error log.I am not sure that here we have something to fix.
cc @clobob
Makes total sense, thanks mate!
Most helpful comment
Created a MCVE for this issue - https://github.com/s4ik4t/selenide-issue-1201
The second assertion wasn't executed at all.