3

I am trying to run integration tests in a PlayFramework 2.3.8 application that uses jQuery 2.1.3 and I am getting this error:

[error] Caused by net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function addEventListener in object [object HTMLDocument].

The test code is as following:

import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._

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

@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {

  "Application" should {

    "work from within a browser" in new WithBrowser {

      browser.goTo("http://localhost:" + port)
      browser.pageSource must contain("ScalaTest")
    }
  }
}

And the view is:

@(message: String)

<!DOCTYPE html>
<html>
<h1>ScalaTest</h1>
<p>
  @message
</p>

<!-- vendor -->
<script src="//code.jquery.com/jquery-2.0.0.min.js"></script>

</html>

Is there any way to solve that, apart from downgrading jQuery?

Daniel
  • 4,051
  • 2
  • 28
  • 46
  • What about `Firefox` or other dirvers? Same error? – Nader Ghanbari Apr 03 '15 at 10:46
  • I tried using `WithBrowser(webDriver = WebDriverFactory(FIREFOX))` I get other kinds of errors: "Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows". I also cannot find in the documentation how to modify the configuration of the Selenium shipped with Play... – Daniel Apr 06 '15 at 06:05
  • That one is most probably due to version inconsistency, you can change the version of your `selenium-java` dependency by excluding it if it's transitively brought by other dependencies and add a new explicit dependency to the latest version. You have to check your Firefox version as well. – Nader Ghanbari Apr 06 '15 at 06:19
  • Well, apparently, for some reason HtmlUnit will not work with jQuery 2, but Firefox can perform the integration tests and run all the JavaScript. For the record, in order to update the Firefox WebDriver, I added the following line to build.sbt: `libraryDependencies += "org.seleniumhq.selenium" % "selenium-java" % "2.45.0" % "test"` – Daniel Apr 06 '15 at 07:45
  • 1
    Have you seen [this SO thread](http://stackoverflow.com/questions/20315330/how-to-overcame-htmlunit-scriptexception) concerning `HtmlUnit`? – Nader Ghanbari Apr 06 '15 at 08:17

0 Answers0