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 aim of the development of HtmlUnit is to provide as accurate a simulation of the various browsers as possible. As browsers are constantly evolving, we have to adapt our test assumptions with every 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 behavior is provided by the superclass org.htmlunit.WebDriverTestCase. The test execution can be switched accordingly with the help of a configuration file.
By default, all tests runing 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 ff.bin=/usr/bin/firefox [Unix] ff-esr.bin=/usr/bin/firefox-esr [Unix] geckodriver.bin=/usr/bin/driver/geckodriver [Unix] chrome.bin=/path/to/chromedriver [Unix] edge.bin=/path/to/chromedriver [Unix] geckodriver.bin=C:\\path\\to\\geckodriver.exe [Windows] ff.bin=C:\\path\\to\\Mozilla Firefox\\firefox.exe [Windows] ff-esr.bin=C:\\path\\to\\Mozilla Firefox ESR\\firefox.exe [Windows] chrome.bin=C:\\path\\to\\chromedriver.exe [Windows] edge.bin=C:\\path\\to\\msedgedriver.exe [Windows] autofix=false
The file could contain some properties
- browsers: is 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 test using real Firefox),
- ff-esr, (running test using real Firefox ESR),
- chrome (running test using real Chrome),
- edge (running test using real Edge),
- 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)
- autofix (optional): if {@code true}, try to automatically fix the real browser expectations, or add/remove {@code @NotYetImplemented} annotations, use with caution!