Table of Contents

Choose the right version

FluentLenium 5.x is the newest version of FluentLenium it is based on JDK 11 it includes latest enhancements and features, but Selenium 4 is required to run it.

FluentLenium 4.x is based on JDK 11. Selenium 3 is required to run it.

FluentLenium 3.x is based on JDK 1.8 - we are not going to add new features to this version but still planning work on bugfixes.

FluentLenium 1.x is in maintenance state, and no new feature will be added anymore. It requires Selenium 2 and Java 7, but can also be used with Java 8. Selenium 3 is not supported in this version though.

Starting from FluentLenium 3.1.0 you can use all sparks of Java 8, including lambdas. It is a nice extension in comparison to Selenium 3 which is still basing on Guava objects. Please take a look on documentation to find await lambda usage example.

For Java 1.8 you need to pick Fluentlenium 5.x, the support was dropped since 6.x release

If you want to keep up to date please choose FluentLenium 6.x

Maven pom configuration

Assuming you want to use Java 11, Junit and AssertJ please add the following dependencies into your pom.xml file.


<properties>
    <fluentlenium.version>6.0.0</fluentlenium.version>
    <selenium.version>4.9.0</selenium.version>
</properties>

<dependency>
<groupId>io.fluentlenium</groupId>
<artifactId>fluentlenium-junit</artifactId>
<version>${fluentlenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fluentlenium</groupId>
<artifactId>fluentlenium-assertj</artifactId>
<version>${fluentlenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>

Basic FluentLenium test

To see FluentLenium in action run this test as Junit.

import io.fluentlenium.adapter.junit.FluentTest;
import io.fluentlenium.core.hook.wait.Wait;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

@Wait
public class DuckDuckGoTest extends FluentTest {
    @Test
    public void titleOfDuckDuckGoShouldContainSearchQueryName() {
        goTo("https://duckduckgo.com");
        $("#search_form_input_homepage").fill().with("FluentLenium");
        $("#search_button_homepage").submit();
        assertThat(window().title()).contains("FluentLenium");
    }
}

Page Object Pattern example

In order to take advantage of FluentLenium magic please use Page Object Pattern. Here is more advanced example of the same test as above.

Test:

import io.fluentlenium.adapter.junit.FluentTest;
import io.fluentlenium.core.annotation.Page;
import org.junit.Test;

public class DuckDuckGoTest extends FluentTest {
    @Page
    DuckDuckMainPage duckDuckMainPage;

    @Test
    public void titleOfDuckDuckGoShouldContainSearchQueryName() {
        String searchPhrase = "searchPhrase";

        goTo(duckDuckMainPage)
                .typeSearchPhraseIn(searchPhrase)
                .submitSearchForm()
                .assertIsPhrasePresentInTheResults(searchPhrase);
    }
}

Page Object:

import static org.assertj.core.api.Assertions.assertThat;

import java.util.concurrent.TimeUnit;

import io.fluentlenium.core.FluentPage;
import io.fluentlenium.core.annotation.PageUrl;
import io.fluentlenium.core.domain.FluentWebElement;
import org.openqa.selenium.support.FindBy;

@PageUrl("https://duckduckgo.com")
public class DuckDuckMainPage extends FluentPage {
    private static final String SEARCH_FORM_HOMEPAGE = "#search_form_homepage";

    @FindBy(css = "#search_form_input_homepage")
    private FluentWebElement searchInput;

    @FindBy(css = "#search_button_homepage")
    private FluentWebElement searchButton;

    public DuckDuckMainPage typeSearchPhraseIn(String searchPhrase) {
        searchInput.write(searchPhrase);
        return this;
    }

    public DuckDuckMainPage submitSearchForm() {
        searchButton.submit();
        awaitUntilSearchFormDisappear();
        return this;
    }

    public void assertIsPhrasePresentInTheResults(String searchPhrase) {
        assertThat(window().title()).contains(searchPhrase);
    }

    private DuckDuckMainPage awaitUntilSearchFormDisappear() {
        await().atMost(5, TimeUnit.SECONDS).until(el(SEARCH_FORM_HOMEPAGE)).not().present();
        return this;
    }
}

More examples

More FluentLenium examples are available on github . Enable them by activating examples Maven profile.

Assuming you want to use only one browser please choose:

If you are more experienced user please choose Spring based example which has ready to use framework supporting every browser.

If you want to use BDD please take a look into Cucumber example

If you want to write in Groovy please take a look into Spock example

If you want to use Kotest (Kotlin) please take a look into Kotest example

Hook example show this feature in action.