From af05aae518a82a653f6d6ec91241b8defd3c6f5b Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Sun, 9 Jul 2023 18:18:15 +0100 Subject: [PATCH] BAEL-6696: Introduction to Selenide (#14379) * BAEL-6210: Examples for RethinkDB article * BAEL-6696: Introduction to Selenide --- testing-modules/pom.xml | 3 +- testing-modules/selenide/pom.xml | 63 +++++++++++++++++++ .../selenide/PageObjectsLiveTest.java | 60 ++++++++++++++++++ .../com/baeldung/selenide/SearchLiveTest.java | 39 ++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 testing-modules/selenide/pom.xml create mode 100644 testing-modules/selenide/src/test/java/com/baeldung/selenide/PageObjectsLiveTest.java create mode 100644 testing-modules/selenide/src/test/java/com/baeldung/selenide/SearchLiveTest.java diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index e29aa26f45..249be5c7c4 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -39,6 +39,7 @@ powermock rest-assured rest-testing + selenide selenium selenium-2 spring-mockito @@ -57,4 +58,4 @@ gatling-java - \ No newline at end of file + diff --git a/testing-modules/selenide/pom.xml b/testing-modules/selenide/pom.xml new file mode 100644 index 0000000000..99538d2d14 --- /dev/null +++ b/testing-modules/selenide/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + selenide + 0.0.1-SNAPSHOT + selenide + + + com.baeldung + testing-modules + 1.0.0-SNAPSHOT + + + + + com.codeborne + selenide + 6.15.0 + test + + + org.junit.platform + junit-platform-engine + ${junit-platform.version} + test + + + org.junit.platform + junit-platform-console-standalone + ${junit-platform.version} + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + ${junit-jupiter.version} + test + + + + + + + src/main/resources + true + + + src/test/resources + true + + + + + + 6.10 + 4.8.3 + 5.3.2 + + + + diff --git a/testing-modules/selenide/src/test/java/com/baeldung/selenide/PageObjectsLiveTest.java b/testing-modules/selenide/src/test/java/com/baeldung/selenide/PageObjectsLiveTest.java new file mode 100644 index 0000000000..4a7a0c37df --- /dev/null +++ b/testing-modules/selenide/src/test/java/com/baeldung/selenide/PageObjectsLiveTest.java @@ -0,0 +1,60 @@ +package com.baeldung.selenide; + +import com.codeborne.selenide.Selenide; +import com.codeborne.selenide.SelenideElement; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Condition.visible; +import static com.codeborne.selenide.Selenide.$; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PageObjectsLiveTest { + @Test + public void searchBaeldung() { + SearchFormPage searchFormPage = new SearchFormPage(); + searchFormPage.open(); + searchFormPage.search("Baeldung"); + + SearchResultsPage results = new SearchResultsPage(); + + SearchResult firstResult = results.getResult(0); + assertTrue(firstResult.getText().contains("Baeldung")); + assertTrue(firstResult.getText().contains("In-depth, to-the-point tutorials on Java, Spring, Spring Boot, Security, and REST.")); + } + + public class SearchFormPage { + public void open() { + Selenide.open("http://duckduckgo.com/"); + } + + public void search(String term) { + SelenideElement searchbox = $(By.id("searchbox_input")); + searchbox.click(); + searchbox.sendKeys(term); + searchbox.pressEnter(); + } + } + + public class SearchResultsPage { + public SearchResult getResult(int index) { + SelenideElement result = $(By.id("r1-" + index)); + + result.shouldBe(visible); + + return new SearchResult(result); + } + } + + public class SearchResult { + private SelenideElement result; + + public SearchResult(SelenideElement result) { + this.result = result; + } + + public String getText() { + return result.getText(); + } + } +} diff --git a/testing-modules/selenide/src/test/java/com/baeldung/selenide/SearchLiveTest.java b/testing-modules/selenide/src/test/java/com/baeldung/selenide/SearchLiveTest.java new file mode 100644 index 0000000000..d29dd967d6 --- /dev/null +++ b/testing-modules/selenide/src/test/java/com/baeldung/selenide/SearchLiveTest.java @@ -0,0 +1,39 @@ +package com.baeldung.selenide; + +import com.codeborne.selenide.SelenideElement; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.*; +import static com.codeborne.selenide.Condition.*; + +public class SearchLiveTest { + + @Test + public void searchBaeldung() throws Exception { + open("https://duckduckgo.com/"); + + SelenideElement searchbox = $(By.id("searchbox_input")); + searchbox.click(); + searchbox.sendKeys("Baeldung"); + searchbox.pressEnter(); + + SelenideElement firstResult = $(By.id("r1-0")); + firstResult.shouldHave(text("Baeldung")); + firstResult.shouldHave(text("In-depth, to-the-point tutorials on Java, Spring, Spring Boot, Security, and REST.")); + } + + @Test + public void searchBaeldungFailing() throws Exception { + open("https://duckduckgo.com/"); + + SelenideElement searchbox = $(By.id("searchbox_input")); + searchbox.click(); + searchbox.sendKeys("Something Else"); + searchbox.pressEnter(); + + SelenideElement firstResult = $(By.id("r1-0")); + firstResult.shouldHave(text("Baeldung")); + firstResult.shouldHave(text("In-depth, to-the-point tutorials on Java, Spring, Spring Boot, Security, and REST.")); + } +}