Appendix E. Installing software

This appendix covers

  • Installing HtmlUnit
  • Configuring Cactus with HtmlUnit
  • Installing Selenium
  • Installing RhinoUnit
  • Installing JsUnit

E.1. Installing HtmlUnit

Download HtmlUnit from http://htmlunit.sourceforge.net/ and unzip it to your local drive. In our examples, we have unzipped it to C:Javahtmlunit-2.7.

E.1.1. Standard configuration

Add all JAR files to the classpath except for the three XML libraries: XML-APIs, Xalan, and Xerces. Starting with version 1.4.2, Java ships with an XML parser and transformer (Apache Xalan). Because HtmlUnit ships with XML-APIs, Xalan, and Xerces, the version of these libraries must override the default Java versions through the Java-endorsed mechanism.[1], [2]

1 For Java 5, see http://java.sun.com/j2se/1.5.0/docs/guide/standards/index.html.

2 For Java 6, see http://java.sun.com/javase/6/docs/technotes/guides/standards/.

Move all XML libraries to a subdirectory of HTmlUnit-2.7/lib called endorsed. For example, the lib directory should contain the following files:

commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-httpclient-3.1.jar
commons-io-1.4.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
cssparser-0.9.5.jar
htmlunit-2.7.jar
htmlunit-core-js-2.7.jar
nekohtml-1.9.14.jar
sac-1.3.jar
serializer-2.7.1.jar

The directory lib/endorsed should contain these files:

xalan-2.7.1.jar
xercesImpl-2.9.1.jar
xml-apis-1.3.04.jar

Your classpath must list all JAR files in lib. In addition, you must add the following to your Java VM invocation:

-Djava.endorsed.dirs=C:Javahtmlunit-2.7libendorsed

If you’re lucky enough to develop on Java 6, your command line classpath doesn’t need to list each HtmlUnit JAR file; instead, it can contain

C:Javahtmlunit-2.7lib*

Starting with Java 6, at last you can use * to include all JAR files in a directory.

E.1.2. Eclipse configuration

In Eclipse, you must set up a JRE as shown in figure E.1.

Figure E.1. Setting up a JRE in Eclipse for HtmlUnit

The two key items in this JRE configuration are as follows:

  • Default VM Arguments sets the endorsed path to our HtmlUnit lib/endorsed directory.
  • JRE System Libraries lists the HtmlUnit lib/endorsed JAR files first.

Eclipse will automatically set up all other entries in the JRE System Libraries list.

E.2. Configuring Cactus with HtmlUnit

HtmlUnit integration requires Cactus version 1.8 or greater and a container such as Tomcat or Jetty. Depending on which container you pick, and the version of Cactus and HtmlUnit, you might have to adjust your installation.

Because Cactus 1.8.1 ships with HtmlUnit 1.6, you may want to update Cactus to HtmlUnit 2.7 by copying the HtmlUnit JAR files over the ones provided by Cactus and deleting htmlunit-1.6.jar. The HtmlUnit 2.7 HTML parser depends on the Xerces and Xalan classes, so make sure you also make these JAR files available to your web application or container.

Chapter 12 introduces writing HtmlUnit tests in the Cactus framework and chapter 14 dives into the details. For the details regarding the installation and management of applications and tests within particular containers, we refer you to the Cactus documentation. We wrote the examples in this chapter with Tomcat 6.0.18 and Cactus 1.8.1, and setup is per the Cactus installation guide.[3]

3 For Cactus and Tomcat setup, see http://jakarta.apache.org/cactus/integration/howto_tomcat.html.

E.3. Installing Selenium

Download Selenium Remote Control (Selenium RC) from http://seleniumhq.org/download/, unzip it to your local drive, and add the Selenium Java client driver to your classpath. As of this writing, the current Selenium version is 1.0 Beta 2, and the client JAR file is selenium-remote-control-1.0-beta-2selenium-java-client-driver-1.0-beta-2selenium-java-client-driver.jar.

E.4. Installing RhinoUnit

RhinoUnit is a library of scripts used to run JavaScript unit tests from Ant, tested here with Ant 1.7.1. If you’re running Java 6 or later, you don’t need any additional setup because Java 6 includes the Java Scripting Framework (http://jakarta.apache.org/bsf/) and the Mozilla Rhino JavaScript engine. So, for Java 5 and earlier, use the following steps.

The Ant script task is an optional task package with the core tasks. It requires Apache BSF, which you can download from http://jakarta.apache.org/site/downloads/downloads_bsf.cgi. Unzip the download and copy the file bsf-2.4.0libsf.jar to one of the Ant locations used for optional tasks as documented in Ant (http://ant.apache.org/manual/install.html#optionalTasks), for example, in ANT_HOME/lib to make the JAR file available to all Ant users and builds.

Next, get the Mozilla Rhino JavaScript (http://www.mozilla.org/rhino/) engine from http://www.mozilla.org/rhino/download.html. For Java 5, copy the file js.jar; for Java 1.4.2, copy the file js-1.4.jar to an Ant location used for optional tasks.

Apache BSF uses Apache Commons Logging, which has been included with Ant since version 1.6. If you must use a version of Ant older than 1.6.x, you can download Apache Commons Logging from http://commons.apache.org/logging/ and copy commons-logging-1.1.1.jar to an Ant location used for optional tasks.

E.5. Installing JsUnit

You can find JsUnit at http://jsunit.net/. We’ve included in the source for chapter 13 the build for version 2.2. This build is located in the jsunit directory in the chapter 13 source.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.123.34