Search code examples
scalaplayframeworkplayframework-2.0integration-testingplayframework-2.1

Play! Integration tests hang using WithBrowser


When attempting to run integration tests, I've run into a baffling problem where the JVM will hang, using 100% of the CPU. The test that comes with the new Play application works correctly, but as soon as it requires database interaction, it will hang indefinitely. For all other unit tests, everything runs smoothly connecting to a mysql database on localhost. I'd like to be able to use that same setup with my integration tests.

Here is an example of a test that will hang upon calling browser.goTo("/")

import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._

class TestSpec extends Specification {

  "Application" should {

    "work from within a browser" in new WithBrowser(webDriver = HTMLUNIT, app = FakeApplication()) {

      browser.goTo("/")

      println(browser.pageSource)

      browser.$("#email").text("[email protected]")
      browser.$("#password").text("password")
      browser.$("#loginbutton").click()
      browser.pageSource must not contain("Sign in")
      browser.pageSource must contain("Logout")

    }

  }

}

Solution

  • The issue in my case was the selenium version. Adding this line to appDependencies in Build.scala will upgrade selenium:

    "org.seleniumhq.selenium" % "selenium-java" % "2.35.0" % "test"

    From there I was able to use both HTMLUNIT and FIREFOX for web drivers without any issues.