Automated UI testing in a Play Scala Application using FluentLenium

In this blog I am going to demonstrate how to do automated testing of UI of a Play Scala application using FluentLenium.

FluentLenium is a framework that helps to write Selenium tests. FluentLenium provides us a fluent interface to the Selenium Web Driver. FluentLenium allows us use the assertion framework we like, either jUnit assertions or Fest-assert.

To start building testcases using FluentLenium follow the below steps:

1) Add following dependencies in build.sbt file.

"org.seleniumhq.selenium" % "selenium-java" % "2.41.0" % "test",
"org.fluentlenium" % "fluentlenium-core" % "0.9.2" % "test",
"org.fluentlenium" % "fluentlenium-festassert" % "0.9.2" % "test"

2) Make an object of the page which is to be tested. For example :-

In test folder add a file IndexPage.scala of index.scala.html page & add following code to it:

import org.fluentlenium.core.FluentPage
import org.openqa.selenium.WebDriver
import org.fluentlenium.core.filter.FilterConstructor.withText
import org.fluentlenium.core.filter.FilterConstructor.withId

object IndexPage extends FluentPage {
 var URL = ""

 def IndexPage (webDriver: WebDriver, port: Int) {
  this.URL = "http://localhost:" + port

 override def getUrl(): String = {

 override def isAt() {
  assert(title().equals("Sign Up"))


This will create an Object of the Index page which can be used anywhere while making the testcases for the Application.

3) Now we can write testcases to test UI of Application. For example :-

In IntegrationTest.scala  remove anything that is written previously & add following code to test Index page in it:

import org.junit.Test
import play.test.TestBrowser
import play.libs.F.Callback
import play.test.Helpers.FIREFOX
import play.test.Helpers.inMemoryDatabase
import play.test.Helpers.fakeApplication
import play.test.Helpers.testServer
import play.test.Helpers.running
import org.fest.assertions.Assertions.assertThat

class IntegrationTest {

 def test() {
  running(testServer(9000, fakeApplication(inMemoryDatabase())), FIREFOX,
   new Callback[TestBrowser]() {
   def invoke(browser: TestBrowser) {
    val indexPage = IndexPage.IndexPage(browser.getDriver(), 9000)
    val email = ""
    val password = "123456"
    val confirm_password = "123456"

For Code & Live Example click here :- FluentLenium Play Scala Example

After downloading the code just run this command :- play test

Then you can see how it runs the application on its own.

This entry was posted in Play Framework, Scala, Web and tagged , , , . Bookmark the permalink.

3 Responses to Automated UI testing in a Play Scala Application using FluentLenium

  1. Uttej G says:

    Is there any specific reason why you chose junit instead of specs2?

    • There is no specific reason to use jUnit instead of Specs2. This is just an example to show how FluentLenium works. You can use either jUnit or Specs2 for testing your application.

  2. Reblogged this on Play!ng with Scala and commented:

    This is best implementation for testing application in Play Framework.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s