Coder Social home page Coder Social logo

alainlompo / fluentlenium Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fluentlenium/fluentlenium

0.0 3.0 0.0 5.63 MB

FluentLenium helps you writing readable, reusable, reliable and resilient UI functional tests for the browser.

Home Page: http://fluentlenium.org

License: Other

Java 89.81% HTML 9.73% JavaScript 0.01% Gherkin 0.09% Groovy 0.36%

fluentlenium's Introduction

What is FluentLenium ?

Travis Coveralls codebeat badge Maven Central Website

FluentLenium helps you writing readable, reusable, reliable and resilient UI functional tests for the browser.

FluentLenium provides a Java fluent interface to Selenium, and brings some magic to avoid common issues faced by Selenium users.

FluentLenium is shipped with adapters for JUnit, TestNG and Cucumber, but it can also be used standalone.

FluentLenium best integrates with AssertJ, but you can also choose to use the assertion framework you want.

Choose the right version

FluentLenium 3.x is still in development and includes latest enhancements and features, but Selenium 3 and Java 8 are required to run it.

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.

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.

Quickstart with JUnit and AssertJ

  • Add dependencies to your pom.xml.
<dependency>
    <groupId>org.fluentlenium</groupId>
    <artifactId>fluentlenium-junit</artifactId>
    <version>3.4.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.fluentlenium</groupId>
    <artifactId>fluentlenium-assertj</artifactId>
    <version>3.4.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>htmlunit-driver</artifactId>
    <version>2.25</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
    <scope>test</scope>
</dependency>
  • Basic FluentLenium test
import org.fluentlenium.adapter.junit.FluentTest;
import org.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();
        await().atMost(5, TimeUnit.SECONDS).until(el("#search_form_homepage")).not().present();
        assertThat(window().title()).contains("FluentLenium");
    }
}
  • A little bit more advanced version of the same FluentLenium test
import org.fluentlenium.adapter.junit.FluentTest;
import org.fluentlenium.core.annotation.Page;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DuckDuckGoTest extends FluentTest {
    @Page
    DuckDuckMainPage duckDuckMainPage;

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

        goTo(duckDuckMainPage)
                .typeSearchPhraseIn(searchPhrase)
                .submitSearchForm()
                .assertIsPhrasePresentInTheResults(searchPhrase);
    }
}
import static org.assertj.core.api.Assertions.assertThat;

import java.util.concurrent.TimeUnit;

import org.fluentlenium.core.FluentPage;
import org.fluentlenium.core.annotation.PageUrl;
import org.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;
    }
}
  • Run as a JUnit test.

More FluentLenium examples are available on github.

Documentation

Full documentation is available on fluentlenium.org, or in the docs sources directory.

Contact Us

If you have any comment, remark or issue, please open an issue on FluentLenium Issue Tracker

fluentlenium's People

Contributors

toilal avatar mathildelemee avatar filipcynarski avatar pierreleresteux avatar dgageot avatar romainlouvet avatar twillouer avatar jarlehansen avatar nozomiito avatar nurkiewicz avatar jroper avatar jcsirot avatar jetoile avatar benmccann avatar framiere avatar yannmoisan avatar pascalschumacher avatar michaelbitard avatar brantb avatar mchataigner avatar kolorobot avatar jblemee avatar cexbrayat avatar wwerner avatar poohsunny avatar zepag avatar nfrancois avatar michal-lipski avatar mamachanko avatar markymarkmcdonald avatar

Watchers

Alain Lompo avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.