Reputation: 1825
I am using JUnitSoftAssertions and I like it so far. But sometimes, the click on call-to-action button takes longer than the next assertion, so it causes test failed.
For example:
@Rule
public final JUnitSoftAssertions softly = new JUnitSoftAssertions();
@And("he should be on {page} page")
public void gotoPage(String page) {
// current page is A, click to go to page B
toPageBButton.click();
softly.assertThat(driver.getCurrentUrl()).as("Page B").isEqualTo(page);
softly.assertAll();
}
Assertion is failed because getCurrentUrl()
is still on Page A.
If I am in debug mode, then it passes, because I have breakpoint.
If I assert that a button on Page B is displayed before the isEqualTo(page)
, then it also passes, but it is strange that I assert a button before I assert current URL
Is there any way to wait before the click action and assertion? I would not want to use Thread.sleep()
Upvotes: 0
Views: 33
Reputation: 1825
Since I use WebElementFacade
, so I can wait until the button is not visible anymore, after the click:
toPageBButton.click();
element(toPageBButton).waitUntilNotVisible();
Upvotes: 0