BAEL-6696: Introduction to Selenide (#14379)

* BAEL-6210: Examples for RethinkDB article

* BAEL-6696: Introduction to Selenide
This commit is contained in:
Graham Cox 2023-07-09 18:18:15 +01:00 committed by GitHub
parent b19e44baef
commit af05aae518
4 changed files with 164 additions and 1 deletions

View File

@ -39,6 +39,7 @@
<module>powermock</module>
<module>rest-assured</module>
<module>rest-testing</module>
<module>selenide</module>
<module>selenium</module>
<module>selenium-2</module>
<module>spring-mockito</module>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>selenide</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>selenide</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>testing-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>6.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<properties>
<testng.version>6.10</testng.version>
<selenium-java.version>4.8.3</selenium-java.version>
<webdrivermanager.version>5.3.2</webdrivermanager.version>
</properties>
</project>

View File

@ -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();
}
}
}

View File

@ -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."));
}
}