HtmlUnit Development
Prerequisites
Before starting, ensure you have the following installed:
- Java Development Kit (JDK 11) HtmlUnit is JDK 8 but for running the untit test JDK 11 is required
- Eclipse IDE
- Maven 3
- Git use your favorite git client
- Web BrowserChrome / Firefox / Edge to check the compatibility
Repository Setup and first build
Clone the HtmlUnit repository from GitHub
git clone https://github.com/HtmlUnit/htmlunit.git cd htmlunit
Compile the project to ensure everything is working correctly
mvn clean compile
Run some unit tests
do not run the whole test suite because this takes really long
mvn test -Dtest=org.htmlunit.javascript.host.dom.*Test
Eclipse Project Setup
Generate Eclipse project files
use the Maven Eclipse Plugin generate Eclipse project files with source downloads
mvn eclipse:eclipse -DdownloadSources=true
then import the Project in Eclipse
File → Import → Existing Projects into Workspace
Running Tests from Eclipse
Usually you would run only some test from Eclipse.
Please have a look at the section 'Running Test with real browsers' below for more options
IntelliJ IDEA Project
ToDoRunning the Tests from Maven
Run of the full Test Suite requires significant time (several hours) and resources. Therfore some profiles are defined to run different parts of the test suite. These profiels are also used by the various jenkins jobs.
Run Core test suite
Run core tests only (faster (~25min), excludes library and huge tests)
mvn test -P without-library-and-huge-tests -Dgpg.skip -Djava.awt.headless=true
Run Library test suite
Run the test suites from various js libraries (jQuery, prototype, etc.)
mvn test -P only-library-tests -Dgpg.skip -Djava.awt.headless=true
Ports used
Test Port Configuration
Tests currently assume that port 12345 is free on the machine. If you encounter
java.net.BindException: Address already in use: JVM_Bind
, set the
system property htmlunit.test.port
:
mvn test ... -Dhtmlunit.test.port=10101
Running Test with real browsers
The primary goal of HtmlUnit development is to provide the most accurate simulation possible of supported browsers. Since browsers are constantly evolving, we have to adapt our test assumptions with every browser version update. Therefore almost all tests are implemented in such a way that they can be executed with HtmlUnit as well as (with the help of Selenium WebDriver) with the supported real browsers.
This functionality is provided by the superclass org.htmlunit.WebDriverTestCase. Test execution can be switched accordingly with the help of a configuration file.
By default, all tests runking with HtmlUnit, but this behavior can be changed by having a property file named "{@code test.properties}" in the HtmlUnit root directory.
Sample (remove the part not matching your os)
browsers=hu #browsers=hu-ff #browsers=hu-ff, hu-chrome #browsers=ff, chrome, edge # Unix/Linux paths ff.bin=/usr/bin/firefox ff-esr.bin=/usr/bin/firefox-esr geckodriver.bin=/usr/bin/driver/geckodriver chrome.bin=/path/to/chromedriver edge.bin=/path/to/chromedriver # Windows paths geckodriver.bin=C:\\path\\to\\geckodriver.exe ff.bin=C:\\path\\to\\Mozilla Firefox\\firefox.exe ff-esr.bin=C:\\path\\to\\Mozilla Firefox ESR\\firefox.exe chrome.bin=C:\\path\\to\\chromedriver.exe edge.bin=C:\\path\\to\\msedgedriver.exe # optional autofix=false
The file could contain some properties
Configuration Properties
browsers
a comma separated list contains any combination of:
- hu (for HtmlUnit with all browser versions),
- hu-ff,
- hu-ff-esr,
- hu-chrome,
- hu-edge,
- ff, (running tests using real Firefox),
- ff-esr, (running tests using real Firefox ESR),
- chrome (running tests using real Chrome),
- edge (running tests using real Edge),
Browser Binary Paths
- chrome.bin (mandatory if it does not exist in the path): is the location of the ChromeDriver binary (see Chrome Driver downloads)
- geckodriver.bin (mandatory if it does not exist in the path): is the location of the GeckoDriver binary (see Gecko Driver Releases)
- ff.bin (optional): is the location of the FF binary, in Windows use double back-slashes
- ff-esr.bin (optional): is the location of the FF binary, in Windows use double back-slashes
- edge.bin (mandatory if it does not exist in the path): is the location of the MicrosoftWebDriver binary (see Microsoft Edge WebDriver downloads)
Additional Options
- autofix (optional): if {@code true}, try to automatically fix the real browser expectations, or add/remove {@code @NotYetImplemented} annotations, use with caution!