-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more samples of Selenide features
- Loading branch information
Showing
9 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
src/test/java/org/selenide/bs/AnnotatedPageObjectTest.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.selenide.bs; | ||
|
||
import com.codeborne.selenide.ElementsCollection; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.support.FindBy; | ||
|
||
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan; | ||
import static com.codeborne.selenide.CollectionCondition.sizeLessThan; | ||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.Selenide.page; | ||
|
||
public class AnnotatedPageObjectTest { | ||
@BeforeEach | ||
void setUp() { | ||
open("https://selenide.org/users.html"); | ||
} | ||
|
||
@Test | ||
void showsAllKnownSelenideUsers() { | ||
SelenideUsersPage page = page(); | ||
page.users.shouldHave(sizeGreaterThan(40)); | ||
} | ||
|
||
@Test | ||
void canFilterByTag() { | ||
SelenideUsersPage page = page(); | ||
page.filterByTag("usa"); | ||
page.users.shouldHave(sizeLessThan(40)); | ||
} | ||
|
||
private static class SelenideUsersPage { | ||
@FindBy(css = "#selenide-users .user:not(.hidden)") | ||
ElementsCollection users; | ||
|
||
@FindBy(css = "#user-tags .tag") | ||
ElementsCollection userTags; | ||
|
||
public void filterByTag(String tag) { | ||
userTags.stream() | ||
.filter(el -> el.getText().equals(tag)) | ||
.findAny().orElseThrow(() -> new AssertionError("User tag not found: " + tag)) | ||
.click(); | ||
} | ||
} | ||
} |
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,42 @@ | ||
package org.selenide.bs; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.codeborne.selenide.Condition.text; | ||
import static com.codeborne.selenide.Condition.value; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.open; | ||
|
||
public final class DropdownTest { | ||
@BeforeEach | ||
void setUp() { | ||
open("https://selenide.org/test-page/dropdown.html"); | ||
} | ||
|
||
@Test | ||
void canSelectOptionByText() { | ||
$("#hero").selectOption("Sarah Connor"); | ||
$("#hero").getSelectedOption().shouldHave(value("sarah-connor")); | ||
$("#hero-summary").shouldHave(text("Your hero is: Sarah Connor (id: sarah-connor)")); | ||
} | ||
|
||
@Test | ||
void canSelectOptionBySubstring() { | ||
$("#hero").selectOptionContainingText("hn Mc"); | ||
$("#hero").getSelectedOption().shouldHave(text("John McClane")); | ||
$("#hero-summary").shouldHave(text("Your hero is: John McClane (id: john-mcclane)")); | ||
} | ||
|
||
@Test | ||
void canSelectOptionByIndex() { | ||
$("#hero").selectOption(3); | ||
$("#hero-summary").shouldHave(text("Your hero is: Ellen Ripley (id: ellen-ripley)")); | ||
} | ||
|
||
@Test | ||
void canSelectOptionByValue() { | ||
$("#hero").selectOptionByValue("samwise-gamgee"); | ||
$("#hero-summary").shouldHave(text("Your hero is: Samwise Gamgee (id: samwise-gamgee)")); | ||
} | ||
} |
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
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,20 @@ | ||
package org.selenide.bs; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.codeborne.selenide.LocalStorageConditions.item; | ||
import static com.codeborne.selenide.LocalStorageConditions.itemWithValue; | ||
import static com.codeborne.selenide.Selenide.localStorage; | ||
import static com.codeborne.selenide.Selenide.open; | ||
|
||
public class LocalStorageTest { | ||
@Test | ||
void canCheckLocalStorage() { | ||
open("https://selenide.org/test-page"); | ||
localStorage().shouldNotHave(item("event")); | ||
|
||
localStorage().setItem("event", "Testμ 2024"); | ||
localStorage().shouldHave(item("event")); | ||
localStorage().shouldHave(itemWithValue("event", "Testμ 2024")); | ||
} | ||
} |
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,20 @@ | ||
package org.selenide.bs; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.Selenide.sessionStorage; | ||
import static com.codeborne.selenide.SessionStorageConditions.item; | ||
import static com.codeborne.selenide.SessionStorageConditions.itemWithValue; | ||
|
||
public class SessionStorageTest { | ||
@Test | ||
void canCheckSessionStorage() { | ||
open("https://selenide.org/test-page"); | ||
sessionStorage().shouldNotHave(item("event")); | ||
|
||
sessionStorage().setItem("event", "Testμ 2024"); | ||
sessionStorage().shouldHave(item("event")); | ||
sessionStorage().shouldHave(itemWithValue("event", "Testμ 2024")); | ||
} | ||
} |
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,40 @@ | ||
package org.selenide.bs; | ||
|
||
import com.codeborne.selenide.ElementsCollection; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan; | ||
import static com.codeborne.selenide.CollectionCondition.sizeLessThan; | ||
import static com.codeborne.selenide.Selectors.byText; | ||
import static com.codeborne.selenide.Selenide.*; | ||
|
||
public class SimplePageObjectTest { | ||
@BeforeEach | ||
void setUp() { | ||
open("https://selenide.org/users.html"); | ||
} | ||
|
||
@Test | ||
void showsAllKnownSelenideUsers() { | ||
SelenideUsersPage page = new SelenideUsersPage(); | ||
page.users().shouldHave(sizeGreaterThan(40)); | ||
} | ||
|
||
@Test | ||
void canFilterByTag() { | ||
SelenideUsersPage page = new SelenideUsersPage(); | ||
page.filterByTag("usa"); | ||
page.users().shouldHave(sizeLessThan(40)); | ||
} | ||
|
||
private static class SelenideUsersPage { | ||
public ElementsCollection users() { | ||
return $$("#selenide-users .user:not(.hidden)"); | ||
} | ||
|
||
public void filterByTag(String tag) { | ||
$("#user-tags").find(byText(tag)).click(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/org/selenide/bs/WebdriverConditionsTest.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.selenide.bs; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.codeborne.selenide.Selectors.byText; | ||
import static com.codeborne.selenide.Selenide.*; | ||
import static com.codeborne.selenide.WebDriverConditions.title; | ||
import static com.codeborne.selenide.WebDriverConditions.*; | ||
|
||
public class WebdriverConditionsTest { | ||
@Test | ||
void search() { | ||
open("https://selenide.org"); | ||
$(".main-menu-pages").find(byText("Users")).click(); | ||
|
||
webdriver().shouldHave(url("https://selenide.org/users.html")); | ||
webdriver().shouldHave(urlStartingWith("https://selenide.org")); | ||
webdriver().shouldHave(urlContaining("selenide.org/users")); | ||
webdriver().shouldHave(currentFrameUrl("https://selenide.org/users.html")); | ||
webdriver().shouldHave(numberOfWindows(1)); | ||
webdriver().shouldHave(title("Selenide users")); | ||
webdriver().shouldNotHave(cookie("session", "sid-12345")); | ||
webdriver().shouldNotHave(cookie("session")); | ||
} | ||
} |