-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced useless unit-tests by analogous integration test
- Loading branch information
Showing
3 changed files
with
118 additions
and
102 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
src/test/java/com/codeborne/selenide/collections/TextsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,14 @@ | ||
package com.codeborne.selenide.collections; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
final class TextsTest { | ||
@Test | ||
void applyWithEmptyList() { | ||
assertThat(new Texts("One", "Two", "Three").test(emptyList())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void applyWithWrongSizeList() { | ||
Texts texts = new Texts(asList("One", "Two", "Three")); | ||
assertThat(texts.test(singletonList(element("")))) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void applyWithMatchOnPartialText() { | ||
Texts texts = new Texts(asList("One", "Two")); | ||
assertThat(texts.test(asList(element("OneThing"), element("Two")))).isEqualTo(true); | ||
} | ||
|
||
@Test | ||
void applyWithNoMatchOnPartialText() { | ||
Texts texts = new Texts(asList("One", "Two")); | ||
assertThat(texts.test(asList(element("Three"), element("Selenide")))).isEqualTo(false); | ||
} | ||
|
||
@Test | ||
void testToString() { | ||
assertThat(new Texts(asList("One", "Two"))) | ||
.hasToString("texts [One, Two]"); | ||
} | ||
|
||
private WebElement element(String text) { | ||
WebElement webElement = mock(); | ||
when(webElement.getText()).thenReturn(text); | ||
return webElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package integration.collections; | ||
|
||
import com.codeborne.selenide.ElementsCollection; | ||
import com.codeborne.selenide.ex.ElementNotFound; | ||
import com.codeborne.selenide.ex.TextsMismatch; | ||
import com.codeborne.selenide.ex.TextsSizeMismatch; | ||
import integration.ITest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.NoSuchElementException; | ||
|
||
import static com.codeborne.selenide.CollectionCondition.texts; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class TextsTest extends ITest { | ||
@BeforeEach | ||
void openPage() { | ||
openFile("page_with_list_of_elements.html"); | ||
} | ||
|
||
@Test | ||
void checksTexts() { | ||
$$(".element").shouldHave(texts("One", "Two", "Three")); | ||
$$(".element").shouldHave(texts(asList("One", "Two", "Three"))); | ||
} | ||
|
||
@Test | ||
void checksOrderOfTexts() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(texts("Two", "One", "Three"))) | ||
.isInstanceOf(TextsMismatch.class) | ||
.hasMessageContaining("Actual: [One, Two, Three]") | ||
.hasMessageContaining("Expected: [Two, One, Three]"); | ||
} | ||
|
||
@Test | ||
void ignoresWhitespacesInTexts() { | ||
$$("ol.spaces li").shouldHave( | ||
texts("The \t\n first\n\r", " The second ", "The third") | ||
); | ||
} | ||
|
||
@Test | ||
void acceptsSubstrings() { | ||
$$(".element").shouldHave(texts("On", "Two", "Three")); | ||
$$(".element").shouldHave(texts("One", "wo", "Three")); | ||
$$(".element").shouldHave(texts("One", "Two", "hre")); | ||
} | ||
|
||
@Test | ||
void errorMessage() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(texts("Three", "Two", "One"))) | ||
.isInstanceOf(TextsMismatch.class) | ||
.hasMessageStartingWith("Texts mismatch") | ||
.hasMessageContaining("Actual: [One, Two, Three]") | ||
.hasMessageContaining("Expected: [Three, Two, One]") | ||
.hasMessageContaining("Collection: .element"); | ||
} | ||
|
||
@Test | ||
void ignoresCase() { | ||
$$(".element").shouldHave(texts("one", "two", "three")); | ||
$$(".element").shouldHave(texts("ONE", "TWO", "THREE")); | ||
$$(".element").shouldHave(texts("onE", "twO", "threE")); | ||
} | ||
|
||
@Test | ||
void checksElementsCount() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(texts("One", "Two", "Three", "Four"))) | ||
.isInstanceOf(TextsSizeMismatch.class) | ||
.hasMessageStartingWith("Texts size mismatch") | ||
.hasMessageContaining("Actual: [One, Two, Three], List size: 3") | ||
.hasMessageContaining("Expected: [One, Two, Three, Four], List size: 4") | ||
.hasMessageContaining("Collection: .element"); | ||
} | ||
|
||
@Test | ||
void throwsElementNotFound() { | ||
assertThatThrownBy(() -> $$(".non-existing-elements").shouldHave(texts("content1", "content2"))) | ||
.isInstanceOf(ElementNotFound.class) | ||
.hasMessageStartingWith("Element not found {.non-existing-elements}"); | ||
} | ||
|
||
@Test | ||
void shouldThrow_ElementNotFound_causedBy_IndexOutOfBoundsException_first() { | ||
ElementsCollection elementsCollection = $$("not-existing-locator").first().$$("#multirowTable"); | ||
String description = "Check throwing ElementNotFound for %s"; | ||
|
||
assertThatThrownBy(() -> elementsCollection.shouldHave(texts("any text"))) | ||
.as(description, "texts").isInstanceOf(ElementNotFound.class) | ||
.hasCauseExactlyInstanceOf(NoSuchElementException.class); | ||
} | ||
|
||
@Test | ||
void shouldThrow_ElementNotFound_causedBy_IndexOutOfBoundsException() { | ||
ElementsCollection elementsCollection = $$("not-existing-locator").get(1).$$("#multirowTable"); | ||
String description = "Check throwing ElementNotFound for %s"; | ||
|
||
assertThatThrownBy(() -> elementsCollection.shouldHave(texts("any text"))) | ||
.as(description, "texts").isInstanceOf(ElementNotFound.class) | ||
.hasCauseExactlyInstanceOf(IndexOutOfBoundsException.class); | ||
} | ||
|
||
@Test | ||
void emptyArrayIsNotAllowed() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(texts())) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
|
||
@Test | ||
void emptyListIsNotAllowed() { | ||
assertThatThrownBy(() -> $$(".element").shouldHave(texts(emptyList()))) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("No expected texts given"); | ||
} | ||
} |