FluentLenium ã使ã£ã¦ããã©ã¦ã¶ã®ãã¹ããèªååããæ¹æ³ãæ¸ãã¦ããã¾ãã
â» FluentLenium 㯠Selenium ã使ç¨ãã¦ãã¾ãã
ãã¼ã¸ã§ã³
åä½ç¢ºèªã§ä½¿ç¨ãã製åã®ãã¼ã¸ã§ã³ã¯ä»¥ä¸ã®éãã§ãã
1. ãã«ããã¡ã¤ã«ã®ä½æ
Maven ã®ãã«ããã¡ã¤ã«ã使ãã¦ãã©ã¤ãã©ãªã®ä¾åé¢ä¿ã追å ãã¾ãã
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>test-fluentlenium</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.fluentlenium</groupId>
<artifactId>fluentlenium-assertj</artifactId>
<version>5.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fluentlenium</groupId>
<artifactId>fluentlenium-junit-jupiter</artifactId>
<version>5.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
</plugin>
</plugins>
</build>
</project>
2. ãã¹ãã±ã¼ã¹ã®ä½æ
以ä¸ã®ãã¹ãã¯ã©ã¹ã使ãã¾ãã
src/test/java/org/example/DuckDuckGoTest.java
package org.example; import static org.assertj.core.api.Assertions.assertThat; import java.util.concurrent.TimeUnit; import org.fluentlenium.adapter.junit.jupiter.FluentTest; import org.junit.jupiter.api.Test; class DuckDuckGoTest extends FluentTest { @Test void titleOfDuckDuckGoShouldContainSearchQueryName() { // DuckDuckGoã®ãã¼ã¸ã«ç§»å goTo("https://duckduckgo.com"); // æ¤ç´¢æ¬ã«å ¥å $("#search_form_input_homepage").fill().with("FluentLenium"); // ãµãããã $("#search_button_homepage").submit(); // ãµãããããããã©ã¼ã ãæ¶ããã¾ã§å¾ æ© await().atMost(5, TimeUnit.SECONDS).until( el("#search_form_homepage") ).not().present(); // ã¿ã¤ãã«ã«æ¤ç´¢æè¨ãå«ã¾ãã¦ãããã¨ãç¢ºèª assertThat(window().title()).contains("FluentLenium"); } }
3. ãã¹ãã®å®è¡
IDEã§ãã¹ãã¯ã©ã¹ãå®è¡ããããã³ãã³ãã©ã¤ã³ã§ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
mvn test
ãã¹ããå®è¡ããã¨ãFireFox ãèµ·åãã¦æä½ãè¡ããã¾ãã