How to make end-to-end tests in Java being interesting

It is possible write high level end-to-end tests in Java in a simple way

Current scenario of end-to-end testing

The web applications are still the most common applications there are on the market, and also a high percentage of the mobile applications are also based on a web application.

In the past few years the technology used on web applications has been changed allowing the developers to build more powerful applications. The modern front-end applications becomes a big challenge for testing.

The most used tool for testing web applications is Selenium, does not matter the programming language used for the automation tests, basically all of them are using Selenium direct or indirectly.

Ruby and Javascript have been more popular for writing end-to-end tests, probably because those languages offer more tools for making the process of writing tests not so painful. But still there are a big amount of companies that are using Java or some other languages based on JVM, like Groovy or Scala.

Another word that became popular in the automation testing environment is BDD, the abbreviation of Behavior-driven Development, is a technique to write tests using natural language (e.g. English-like sentences). The most famous tools for that are Cucumber and JBehave.

What is the problem?

The end-to-end tests are expensive to write and time consuming to run, that is why they correspond to the less amount of the tests as the Martin Fowler's Test Pyramid. Google also suggests a 70/20/10 split: 70% unit tests, 20% integration tests and 10% end-to-end tests.

The main question is why those tests are so expensive to write? Probably there is not an exact answer for this question, but a possible reason could be the knowledge of the team who are working in those tests. The low level of seniority of the professionals together with the high turnover of the team may cause a big issue: a bad readability of the code what is the cause of a tough maintainability of the project. The root cause behind of such problem is the company who mostly is more interested in earn money than delivery a high quality product.

Another reasonable reason for that is the choice of the technology used for tests. Maybe a framework could promise resolve a single problem, but its require add more complexity than the project needs, making the end-to-end tests even more expensive.

But why Java?

Java is known for being a tough language, it is hard to learn and need many lines of code for doing a simple stuff, what can be easily done in other languages as Javascript or Ruby. But Java is strongly typed and also a Object Oriented language which give a better opportunity for creating a well-structured solution for writing end-to-end tests.

As Java is still used for many companies, create a solution based on Java could be the answer for helping a big amount of the teams around the world.

The solution

The usage of patterns and techniques allow the end-to-end tests for being more robust, well-structured and easy to maintain. But the implementation of those patterns are also costly.

The worst and the most expensive part of the end-to-end tests is the web crawling, find the content in a web page and navigate through the website need a huge effort for making it work properly.

The solution for making the web crawling less expensive is using the flue2ent framework. It is a Java framework responsible for making the end-to-end tests more readable and easy to maintain. The name flue2ent means fluent e2e tests, that brings the DSL (Domain Specific Language) concept from the BDD, making the code itself closer to the natural language.

Another valuable feature from flue2ent is that it implements the boring parts from web crawling, the only thing the developer needs to do is writing the references for the elements of the page. The flue2ent forces the developer to use the Page Object pattern what brings a lot of benefits to the projects.

Theory is enough, how does it work?

Flue2ent is a wrapper of Selenium, the first step is create the Website object from Selenium WebDriver.

Using a Craiglist page for this example, the elements which are more relevant are: title, images, description, post id, posted at, updated at, tags and Google Maps link.

The next step should be create an interface to represent such page. Each element should be represented as a method and the @FindElementBy annotation is the reference for the element at the page.

The last step is extract those information from the page.

In case of navigation, for example, clicking on "Email to Friend" link at the bottom of the page, without getting any other information from page. It could be easily done using a fluent interface.

Flue2ent implements the PropertyPage interface based on the return type of the method. It allows to implement the Page Object pattern in few lines of code.

How to use it in your project?

Flue2ent is a simple API and does not requires any kind of configuration to use. This package is published in the Maven Central repository, it is free and available for everyone.

The complete documentation of flue2ent is available at:

Questions?

Please, feel free to ask your question or leave your feedback about flue2ent in the comments.

Follow us

Do not forget to follow us to get more information about flue2ent or other things that will make your life more easy.