-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#148 Added optionalWaitUntilCondition and optionalWaitWhileCondition #191
Changes from 4 commits
4901d96
0289271
295756f
71742cd
c9b8d58
95c566d
f475af5
d22b038
16adc6a
accc4dc
576adf4
7f9248e
e2efd79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,8 @@ | |||||
import static com.codeborne.selenide.Condition.hidden; | ||||||
import static com.codeborne.selenide.Condition.visible; | ||||||
import static com.codeborne.selenide.Selenide.$; | ||||||
import static org.junit.Assert.assertFalse; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the static imports for
Until now we use this scheme at most of our test cases and I would like to have the same approach for similar things. |
||||||
import static org.junit.Assert.assertTrue; | ||||||
|
||||||
import java.time.Duration; | ||||||
import java.util.ArrayList; | ||||||
|
@@ -13,6 +15,7 @@ | |||||
import java.util.List; | ||||||
import java.util.concurrent.atomic.AtomicInteger; | ||||||
|
||||||
import org.apache.commons.lang3.Range; | ||||||
import org.junit.Assert; | ||||||
import org.junit.Test; | ||||||
import org.junit.runner.RunWith; | ||||||
|
@@ -640,4 +643,37 @@ public void testOpenHtmlContentWithCurrentWebDriver() | |||||
SelenideAddons.openHtmlContentWithCurrentWebDriver(textHtml); | ||||||
Assert.assertEquals(text, $("body").getText()); | ||||||
} | ||||||
|
||||||
@Test | ||||||
public void testOptionalWaitUntil() | ||||||
{ | ||||||
openBlogPage(); | ||||||
SelenideElement privaceDialog = $("#privacy-message"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
boolean isVisible = SelenideAddons.optionalWaitUntilCondition(privaceDialog, visible, Neodymium.configuration().optionalElementRetryTimeout()); | ||||||
assertTrue("the privacy message dialog was not found within the timeframe", isVisible); | ||||||
long startTime = new Date().getTime(); | ||||||
boolean isHidden = SelenideAddons.optionalWaitUntilCondition(privaceDialog, hidden, Neodymium.configuration().optionalElementRetryTimeout()); | ||||||
long endTime = new Date().getTime(); | ||||||
assertFalse("the privacy message dialog was unexpectedly hidden during the timeframe", isHidden); | ||||||
int waitingTime = Neodymium.configuration().optionalElementRetryTimeout() * Neodymium.configuration().optionalElementRetryCount(); | ||||||
Assert.assertTrue("Runtime was shorter than expected", Range.between(waitingTime, waitingTime + Neodymium.configuration().optionalElementRetryTimeout()) | ||||||
.contains(Math.toIntExact(endTime - startTime))); | ||||||
} | ||||||
|
||||||
@Test | ||||||
public void testOptionalWaitWhile() | ||||||
{ | ||||||
openBlogPage(); | ||||||
SelenideElement privaceDialog = $("#privacy-message").shouldBe(visible); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. privacyDialog |
||||||
long startTime = new Date().getTime(); | ||||||
boolean isHidden = SelenideAddons.optionalWaitWhileCondition(privaceDialog, visible, Neodymium.configuration().optionalElementRetryTimeout()); | ||||||
long endTime = new Date().getTime(); | ||||||
assertFalse("the privacy message dialog was unexpectedly during within the timeframe", isHidden); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you agree with the suggested changes? Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, did not see. Should be in now. |
||||||
int waitingTime = Neodymium.configuration().optionalElementRetryTimeout() * Neodymium.configuration().optionalElementRetryCount(); | ||||||
Assert.assertTrue("Runtime was shorter than expected", Range.between(waitingTime, waitingTime + Neodymium.configuration().optionalElementRetryTimeout()) | ||||||
.contains(Math.toIntExact(endTime - startTime))); | ||||||
privaceDialog.find(".btn-link").click(); | ||||||
isHidden = SelenideAddons.optionalWaitWhileCondition(privaceDialog, visible, Neodymium.configuration().optionalElementRetryTimeout()); | ||||||
assertTrue("the privacy message dialog remained visible during the timeframe", isHidden); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we can reuse the
optionalWaitUntilCondition
method here becausenot(condition)
is also a condition