Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: how to setup htmlunit

Tags:

java

htmlunit

I'm a pretty big noob to Java, but I would like try out htmlunit. I'm using netbeans as my IDE and I've created a project folder "hu1". Here is the structure for that folder:

hu1
 > nbproject
 > src 
   > hu1
 > test

Now, I download htmlunit 2.7 and unzipped the folder, which contains a "lib" folder with a bunch of jar files in it. Where do I put that lib folder in my netbeans project folder so that I can use htmlunit?

Also, once I have figured that out, what paths do I use for my imports. A lot of examples I've seen on the web use something like this:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;

Where do the the com.gargoylesoftware come from?

I know this is a beginner questions, and I really should just read up on how to program with java more, but I would appreciate some advice from the experts here.


UPDATE: Here is a picture of my setup.

like image 563
Joe Avatar asked Jul 18 '10 22:07

Joe


People also ask

Which engine is used to run JavaScript code in HtmlUnit?

2. About HtmlUnit. HtmlUnit is a GUI-less browser – a browser intended to be used programmatically and not directly by a user. The browser supports JavaScript (via the Mozilla Rhino engine) and can be used even for websites with complex AJAX functionalities.

Can we take screenshot in HtmlUnitDriver?

htmlunit driver does not support screenshots · Issue #1361 · SeleniumHQ/selenium-google-code-issue-archive · GitHub.

What is HtmlUnit driver in selenium?

HtmlUnitDriver is headless driver providing non-GUI implementation of Selenium WebDriver. It is based on HtmlUnit, fastest and light-weight browser implemented in Java. WebDriver driver = new HtmlUnitDriver();

Is HtmlUnit open source?

HtmlUnit is used as the underlying "browser" by different Open Source tools like WebDriver, WETATOR, jenkins-test-harness, Spring Testing, ... Canoo WebTest, JWebUnit, JSFUnit, Celerity, HtmlUnit was originally written by Mike Bowler of Gargoyle Software and is released under the Apache 2 license.


2 Answers

Now, I download htmlunit 2.7 and unzipped the folder, which contains a "lib" folder with a bunch of jar files in it. Where do I put that lib folder in my netbeans project folder so that I can use htmlunit?

First, register the libraries in the IDE.

  1. In the IDE, choose Tools > Libraries to open the Libraries Manager.
  2. Click New Library and provide a name for the library, e.g. "HTMLUnit"
  3. With the "HTMLUnit" library selected, click on the "Add JAR/Folder..." button and select the jar file that was downloaded earlier and click OK to complete

alt text
(source: netbeans.org)

Then, add the libraries to the project you are working on.

  1. Select the project from the Project view, right-click and select "Properties"
  2. Under the Libraries category, click on the "Add Library..." button and choose the HTMLUnit library and click OK to complete

alt text
(source: netbeans.org)

(...) Where do the the com.gargoylesoftware come from?

From the library you have to add (more precisely, from the htmlunit jars).

like image 52
Pascal Thivent Avatar answered Oct 14 '22 20:10

Pascal Thivent


com.gargoylesoftware.htmlunit

Is a package in one of the jar files you've downloaded. You have to make sure that these jar files are on the "classpath" in order for Java to find the classes inside (Page, BrowserVersion++). If you're using Netbeans dumping the jar's in the lib folder will usually do the trick.

like image 43
Kimble Avatar answered Oct 14 '22 20:10

Kimble