HtmlUnitDriver for the WebDriver plugins

1,226 views
Skip to first unread message

MeBrewMan

unread,
Sep 5, 2013, 4:32:34 AM9/5/13
to jmeter-...@googlegroups.com
Greetings,

I'm getting quite excited about integrating JMeter and Selenium to run more realistic, javascript-based tests.

However, I'm wondering if there is a driver that can be used headless within JMeter.  I've seen some discussion about using HtmlUnitDriver as headless but the current versions of JMeter-Plugins webdriver package do not seem to include this driver.

What would driver should I use for headless operation (I'm planning on running JMeter from the command line)

Regards,
Mark

Cheen-Pin Lim

unread,
Sep 5, 2013, 5:00:14 AM9/5/13
to jmeter-...@googlegroups.com
Hi Mark,

I think if you're interested in headless selenium/webdriver the closest thing it possibly GhostDriver (https://github.com/detro/ghostdriver) which uses headless webkit behind the scenes. Seeing how it uses the Selenium API, it is possible to create a driver that uses GhostDriver instead.

However, nobody has worked on this implementation yet. It should be trivial to do and we're open to accepting contributions from members. If you have a look at the AndroidDriver it was contributed by others.

PS. If you do provide pull requests, please include tests. :)

regards,
CP


--
You received this message because you are subscribed to the Google Groups "jmeter-plugins" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jmeter-plugin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

vdab...@gmail.com

unread,
Sep 9, 2013, 6:01:37 AM9/9/13
to jmeter-...@googlegroups.com
Hi,

The HtmlUnit Driver seems to be the most natural no GUI driver.
 http://docs.seleniumhq.org/docs/03_webdriver.jsp#htmlunit-driver

Pros

  • Fastest implementation of WebDriver
  • A pure Java solution and so it is platform independent.
  • Supports JavaScript

Cons

  • Emulates other browsers’ JavaScript behaviour (see below)
I think add this driver is easy and natural for java user.

Usually I use the Selenium IDE to record commande and i export the script in JUnit 4 WebDriver format.

I look the source code in the GIT repository and i look easy to add the HtmlUnit Driver.

Why this driver is important?
Because it allows
to use the same API Selenium but with a lower CPU consumption and greater speed than real browsers (Firefox and Chrome) this criterias are importants for a Performance Testing tool.



Vincent D.

Cheen-Pin Lim

unread,
Sep 9, 2013, 6:39:42 PM9/9/13
to jmeter-...@googlegroups.com

Hi

There seems to be a desire in the community to provide an implementation that makes use of HtmlUnitDriver as this is not the first request for it.

I think providing support for it is possible but I think we should be clear on its intended use cases. For example it wouldn't be used for measuring the client side browser performance as nobody uses HtmlUnit as their primary browser. :)

Would the use case be to simulate tens or hundreds of JavaScript enabled browsers connecting to a server? Hence the need for a browser that has low CPU overhead? If so then we should be clear in the documentation of (1) the scenarios or use cases and (2) the setup of these tens or hundreds of browsers.

If I have misunderstood some thing please feel free to correct me. But as a first step can someone provide feedback on whether or not my understanding is correct?

Regards
CP

Mark Brewster

unread,
Sep 9, 2013, 7:16:57 PM9/9/13
to jmeter-...@googlegroups.com
Hi Cheen-Pin, 

I think your understanding of the purpose for it is correct.   The goal is to have a headless solution that is representative of an actual end-user experience.

Thank you for interest in the request.

vdab...@gmail.com

unread,
Sep 10, 2013, 11:10:43 AM9/10/13
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hi,

I developed the HtmlUnit Driver.

I create a test with 50 vusers (htmlUnit driver).
For 15 pages/sec JMeter consumme less 8% CPU.

This script is not difficult and the web application have few javascript. I controle for each page if the title corresponds to the page excepted.

50 vusers htmlunit, 15 pages/sec, less 8% CPU : really interesting to realize performance tests with a reasonable load.

You need to add this libraries (from selenium-java-2.33.0.jar) to run htmlunit driver
  • cssparser-0.9.9.jar
  • htmlunit-2.12.jar
  • htmlunit-core-js-2.12.jar
  • nekohtml-1.9.17.jar
  • sac-1.3.jar
  • xercesImpl-2.10.0.jar (not sure)
  • xml-apis-1.4.01.jar

I just add in HtmlUnitDriverConfig.java the Capability("javascriptEnabled","true")

Capabilities createCapabilities() {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, createProxy());
        capabilities.setCapability("javascriptEnabled", "true");
        return capabilities;
    }

Regards.
Vincent D.
HtmlUnitDriverConfig.java
HtmlUnitDriverConfigGui.java

Cheen-Pin Lim

unread,
Sep 10, 2013, 9:04:06 PM9/10/13
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hi Vincent,

Thanks for doing some analysis on it, its good to know that it does work for a big number of vUsers. 

I am open to accepting pull requests, but would require tests to go along with it. Vincent, are you ok to do this for us?

regards,
CP

vdab...@gmail.com

unread,
Sep 11, 2013, 9:43:58 AM9/11/13
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hi,

I try to import the JMeter Plugin 1.1.1 in my Eclipse IDE as a maven projet but i can't compile.

I doesn't find a public repository with pom and libraries version 1.1.1.

I find only version 1.0.0 at
http://repo1.maven.org/maven2/kg/apc/jmeter-plugins/
or
https://oss.sonatype.org/index.html#nexus-search;quick~jmeter-plugins
not in the repositories list in the jmeter-plugin pom.xml.
<repositories>
    <repository>
      <id>cloudera repository</id>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>

I try url  https://oss.sonatype.org/service/local/staging/deploy/maven2/ but i need a login ...
Error :
=================================
[DEBUG] Project:       kg.apc:jmeter-plugins-webdriver:1.1.1
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [compile]
[DEBUG] Repositories (dependencies): [cloudera repository (https://repository.cloudera.com/artifactory/cloudera-repos/, releases+snapshots), central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] Repositories (plugins)     : [central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] -----------------------------------------------------------------------
...
Failed to execute goal on project jmeter-plugins-webdriver: Could not resolve dependencies for project kg.apc:jmeter-plugins-webdriver:jar:1.1.1: Failure to find kg.apc:jmeter-plugins-common:jar:1.1.1 in https://repository.cloudera.com/artifactory/cloudera-repos/ was cached in the local repository
====================================

How compile the JMeter Plugin ? With Maven or wtih Ant tools (build.xml) ?

But i can write test classes (like FirefoxDriverConfigTest.java or FirefoxDriverConfigGuiTest.java) but not in the true maven way .

Regards.
Vincent D.

vdab...@gmail.com

unread,
Sep 11, 2013, 10:09:04 AM9/11/13
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hi,
I try to compile with the JMeter Plugins pom.xml but i have errors from common package.

[INFO] ------------------------------------------------------------------------
[INFO] Building JMeter Plugins - Parent 1.1.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ jmeter-plugins ---
[INFO] Installing D:\usr\vdaburon\dev\github\jmeter-plugins-master\pom.xml to D:\m2repo\kg\apc\jmeter-plugins\1.1.1\jmeter-plugins-1.1.1.pom
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building JMeter Plugins - Common Classes 1.1.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ jmeter-plugins-common ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 19 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ jmeter-plugins-common ---
[INFO] Compiling 42 source files to D:\usr\vdaburon\dev\github\jmeter-plugins-master\common\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \usr\vdaburon\dev\github\jmeter-plugins-master\common\src\kg\apc\io\DatagramChannelWithTimeouts.java:[14,7] error: DatagramChannelWithTimeouts is not abstract and does not override abstract method <T>setOption(SocketOption<T>,T) in DatagramChannel
[ERROR] \usr\vdaburon\dev\github\jmeter-plugins-master\common\src\kg\apc\io\SocketChannelWithTimeouts.java:[22,7] error: SocketChannelWithTimeouts is not abstract and does not override abstract method shutdownOutput() in SocketChannel
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] JMeter Plugins - Parent ........................... SUCCESS [0.770s]
[INFO] JMeter Plugins - Common Classes ................... FAILURE [5.415s]
[INFO] JMeter Plugins - Standard Set ..................... SKIPPED
[INFO] JMeter Plugins - Extras Set ....................... SKIPPED
[INFO] JMeter Plugins - Extras with Libs Set ............. SKIPPED
[INFO] JMeter Plugins - Hadoop Set ....................... SKIPPED
[INFO] JMeter Plugins - WebDriver Set .................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.415s
[INFO] Finished at: Wed Sep 11 16:01:27 CEST 2013
[INFO] Final Memory: 19M/174M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project jmeter-plugins-common: Compilation failure: Compilation failure:
[ERROR] \usr\vdaburon\dev\github\jmeter-plugins-master\common\src\kg\apc\io\DatagramChannelWithTimeouts.java:[14,7] error: DatagramChannelWithTimeouts is not abstract and does not override abstract method <T>setOption(SocketOption<T>,T) in DatagramChannel
[ERROR] \usr\vdaburon\dev\github\jmeter-plugins-master\common\src\kg\apc\io\SocketChannelWithTimeouts.java:[22,7] error: SocketChannelWithTimeouts is not abstract and does not override abstract method shutdownOutput() in SocketChannel
[ERROR]

Vincent D.


Cheen-Pin Lim

unread,
Sep 11, 2013, 11:33:31 PM9/11/13
to jmeter-...@googlegroups.com, vdab...@gmail.com

Are you using java 7? The build only works with java 6 at the moment

vdab...@gmail.com

unread,
Sep 13, 2013, 3:44:39 AM9/13/13
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hi,

You're right, i used the JDK7 in my new Eclipse Kepler environment.
This works successfully in jdk 6...

Vincent D.

Anuja Rokade

unread,
Jun 24, 2014, 4:17:14 PM6/24/14
to jmeter-...@googlegroups.com, vdab...@gmail.com
Hello,

I have been trying to do stress testing using htmlunit driver. but facing many issues.

If you could tell me where to keep in which folder of jmeter, these 'HtmlUnitDriverConfig.java' and HtmlUnitDriverConfigGui.java' files.

Thanks.

saching...@gmail.com

unread,
Dec 24, 2016, 12:16:17 AM12/24/16
to jmeter-plugins
Hi Vincent, 

Getting same error when trying to run my script with "htmlUnit Driver" of "jmeter-webdriver plugin- Webdriver sampler" whereas on other browsers it works perfectly.  
        
  I am using Jmeter-- 3.0 version. 

Also included below in Jmeter_home/lib directory.  
  • cssparser-0.9.16.jar

  • htmlunit-2.18.jar

  • htmlunit-core-js-2.17.jar

  • nekohtml-1.9.22.jar

  • sac-1.3.jar

  • xercesImpl-2.11.0.jar

  • xml-apis-1.4.01.jar

  • httpmime-4.5.2.jar


Error :-

2016/12/24 10:43:39 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object Window].
 
Thanks ,
sachin

saching...@gmail.com

unread,
Dec 24, 2016, 12:26:21 AM12/24/16
to jmeter-plugins, saching...@gmail.com

Hi Vincent, 

I am getting same error when trying to run my script with "htmlUnit Driver" of "jmeter-webdriver plugin- Webdriver sampler" whereas on other browsers it works perfectly.  
        
  I am using Jmeter-- 3.0 version. 

Also included below in Jmeter_home/lib directory.  
  • cssparser-0.9.16.jar

  • htmlunit-2.18.jar

  • htmlunit-core-js-2.17.jar

  • nekohtml-1.9.22.jar

  • sac-1.3.jar

  • xercesImpl-2.11.0.jar

  • xml-apis-1.4.01.jar

  • httpmime-4.5.2.jar


Error :-

2016/12/24 10:43:39 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object Window].
 

Here is my part of  script:-

var pkg = JavaImporter(org.openqa.selenium)
var pkg1 = JavaImporter(org.openqa.selenium.interactions.Actions)
var wait = JavaImporter(java.util.concurrent.TimeUnit)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, 50000)

WDS.sampleResult.sampleStart()
        WDS.browser.get('http://pts.com')
        WDS.browser.findElement(pkg.By.id('CenUser')).sendKeys(['DISS'])  
Reply all
Reply to author
Forward
0 new messages