Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Running Selenium Test with jQuery v2.0.2 and Play Framework

I'm not an expert in selenium, but I believe I may have uncovered a bug when attempting to use jQuery v2.0.2. When I use jQuery v2.0.2 with my Play Framework 2.2.1 application, instead of the bundled jQuery v.1.9.0, I get the following error when I run "play test":

[error] Driver info: driver.version: HtmlUnitDriver
[error]     at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:367)
[error]     at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:346)
[error]     at org.fluentlenium.core.Fluent.goTo(Fluent.java:228)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:22)
[error]     at IntegrationTest$1.invoke(IntegrationTest.java:20)
[error]     at play.test.Helpers.running(Helpers.java:433)
[error]     at IntegrationTest.test(IntegrationTest.java:20)
[error]     ...
[error] Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://localhost:3333/assets/javascripts/jquery-2.0.2.min.js#4)

I was able to recreate this error by creating a brand new Play Java project using "play new tmp". After creating the project I was able to "play test" just fine. I then copied jquery-2.0.2.min.js into the public/javascripts folder. I then updated the main.scala.html file to use jquery-2.0.2.min.js instead of the bundled jquery-1.9.0.min.js. That was enough to cause this exact error again by running "play test".

I also tried using the FIREFOX WebDriver helper class but again, no luck.

Any insight into how we can get Selenium / Fluentlenium work with the 2.0.2 version of jQuery would be greatly appreciated :) thanks!

like image 678
ossys Avatar asked Feb 21 '14 21:02

ossys


1 Answers

According to the Selenium Wiki, The HtmlUnitDriver emulates the JS behavior of (real) browsers. You may change the behavior by changing the browser it emulates. This might help as a workaround for your problem. As they state, the JS (and DOM) implementation of the HtmlUnitBrowser is not complete and bugs/problems, like the one you encountered may happen.

If possible try to work with another browser (Firefox or chrome?) and check if the Website works correctly when you open it in the browser. Open the javascript console (or Firebug if you use Firefox) and double check if your jQuery version works properly.

like image 105
Peanut Avatar answered Nov 14 '22 23:11

Peanut