Serenity with htmlunit driver

573 views
Skip to first unread message

Sampath S

unread,
Oct 5, 2015, 5:28:30 AM10/5/15
to Serenity BDD Users Group
I am trying to execute my scripts with Serenity I am getting the below exception.

"java.lang.ClassCastException: net.thucydides.core.webdriver.WebdriverFacade cannot be cast to org.openqa.selenium.htmlunit.HtmlUnitDriver"

My Code is like..
        if (System.getProperty("webdriver.driver").contains("htmlunit")) {
                   String currentURLh = getDriver().getCurrentUrl();
                  ((HtmlUnitDriver)getDriver()).setJavascriptEnabled(true);
                  java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
                  java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);

My POM.xml is like..

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<thucydides.version>0.9.275</thucydides.version>
<thucydides.jbehave.version>0.9.275</thucydides.jbehave.version>
<webdriver.firefox>firefox</webdriver.firefox>
<webdriver.ie>webdrivers\IEDriverServer.exe</webdriver.ie>
<webdriver.chrome>webdrivers\chromedriver.exe</webdriver.chrome>
<webdriver.htmlunit>htmlunit</webdriver.htmlunit>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<!-- <sonar.skip>true</sonar.skip> -->
</properties>
<build>
........
                               <systemPropertyVariables>
<webdriver.driver>${webdriver.firefox}</webdriver.driver>  
<!-- <webdriver.firefox.bin>C:\Program Files (x86)\Mozilla Firefox\firefox.exe</webdriver.firefox.bin> -->
<webdriver.ie.driver>${webdriver.ie}</webdriver.ie.driver>
<webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
<webdriver.htmlunit.driver>${webdriver.htmlunit}</webdriver.htmlunit.driver>
</systemPropertyVariables>



Can any one help me on this?

Thank you!

Sampath

Sampath S

unread,
Oct 5, 2015, 5:33:41 AM10/5/15
to Serenity BDD Users Group
I forget to mention, the command used to run the tests
"mvn clean test -Dwebdriver.driver=htmlunit"

John Smart

unread,
Oct 5, 2015, 6:29:30 PM10/5/15
to Sampath S, Serenity BDD Users Group
Out of curiosity, what are you trying to do here? JavaScript is automatically enabled when you choose the HTMLUnit driver, so you shouldn't need to do it by hand.

If you need to access the actual driver (which in most cases you don't), cast the driver to a WebDriverFacade and use the getProxiedDriver() method.

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +61 407 247 642
Optimizing your software development process
http://www.wakaleo.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Requirements Discovery, Behaviour Driven Development, Agile Development Practices, and Test Automation!
___________________________________________________

Sampath S

unread,
Oct 6, 2015, 3:16:40 AM10/6/15
to Serenity BDD Users Group, sampat...@gmail.com

Sampath S 




Thanks much John.. PhantomJS throwing stale element reference errors most of the time, so I tried HTMLUnit.
I will modify my scripts to work with PhantomJS.


Regards,
Sampath S


John Smart

If you need a headless browser I would recommend PhantomJS, as HtmlUnitDriver doesn't cope very well with modern web apps.

John Smart
And as I mentioned, Javascript is activated by default in Serenity with HtmlUnit, so if you are having issues, it is more likely that HtmlUnit itself doesn't support the javascript operations on the site (which is very common).

Sampath S 




Thank you John for the response.
All my tests are successful in Firefox browser, Now I am trying to execute the same tests using HTMLUnitDriver (head less browser).

Let me try with getProxiedDriver() method.

Regards,
Sampath S
Reply all
Reply to author
Forward
0 new messages