Skip to content

Commit

Permalink
selenide#1136 add tests with different samples of Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev authored and Andrei Koira committed Jun 13, 2021
1 parent fe5d22a commit 8fe2c5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/codeborne/selenide/SelenideElement.java
Expand Up @@ -347,6 +347,13 @@ public interface SelenideElement extends WebElement, WrapsDriver, WrapsElement,
@CanIgnoreReturnValue
SelenideElement should(Condition... condition);

/**
* Wait until given element meets given condition (with given timeout)
*/
@Nonnull
@CanIgnoreReturnValue
SelenideElement should(Condition condition, Duration timeout);

/**
* <p>Synonym for {@link #should(com.codeborne.selenide.Condition...)}. Useful for better readability.</p>
* <p>For example: {@code
Expand Down
11 changes: 11 additions & 0 deletions statics/src/test/java/integration/SelenideMethodsTest.java
Expand Up @@ -20,6 +20,8 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import java.time.Duration;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.attribute;
import static com.codeborne.selenide.Condition.be;
Expand Down Expand Up @@ -107,13 +109,22 @@ void userCanCheckIfElementExistsAndVisible() {

$("#theHiddenElement").shouldBe(hidden);
$("#theHiddenElement").should(disappear);
$("#theHiddenElement").should(disappear, Duration.ofSeconds(2));
$("#theHiddenElement").waitUntil(disappears, 1000);
$("#theHiddenElement").should(exist);

$(".non-existing-element").should(Condition.not(exist));
$(".non-existing-element").shouldNot(exist);
}

@Test
void shouldMethodCanUseCustomTimeout() {
$("#theHiddenElement").should(exist, Duration.ofNanos(3_000_000_000L));
$("#theHiddenElement").shouldBe(hidden, Duration.ofMillis(3_000));
$("#theHiddenElement").shouldHave(exactText(""), Duration.ofSeconds(3));
$("#theHiddenElement").shouldNotHave(text("no"), Duration.ofHours(3));
}

@Test
void userCanUseCustomPollingInterval() {
$("#theHiddenElement").waitUntil(disappears, 1000, 10);
Expand Down
Expand Up @@ -50,13 +50,13 @@ void should_be_with_timeout() {
SelenideElement element = $$("ul .nonexistent").get(1);

try {
element.shouldBe(visible, Duration.ofMillis(44));
element.shouldBe(visible, Duration.ofSeconds(0, 1_000_000));
fail("Expected ElementNotFound");
}
catch (ElementNotFound expected) {
assertThat(expected).hasMessageStartingWith("Element not found {ul .nonexistent[1]}");
assertThat(expected).hasMessageContaining("Expected: visible");
assertThat(expected).hasMessageContaining("Timeout: 44 ms.");
assertThat(expected).hasMessageContaining("Timeout: 1 ms.");
}
}

Expand All @@ -80,12 +80,12 @@ void should_not_have_with_timeout() {
SelenideElement element = $(".detective").shouldBe(visible);

try {
element.shouldNotHave(text("Miller"), Duration.ofMillis(45));
element.shouldNotHave(text("Miller"), Duration.ofNanos(20001000));
fail("Expected ElementNotFound");
}
catch (ElementShouldNot expected) {
assertThat(expected).hasMessageStartingWith("Element should not have text 'Miller' {.detective}");
assertThat(expected).hasMessageContaining("Timeout: 45 ms.");
assertThat(expected).hasMessageContaining("Timeout: 20 ms.");
}
}
}

0 comments on commit 8fe2c5e

Please sign in to comment.