Canoo Webtest WebTest Canoo

Troubleshooting WebTests

Issue Tracker

When in trouble, you may want to visit Canoo WebTest's JIRA Issue Tracker.

Out of Memory

ANT may eat up a lot of memory when started for the use with Canoo WebTest. You can give it more space to live in by specifying a higher "maximum heap size" through the environment variable ANT_OPTS, e.g.:

ANT_OPTS=-Xmx128m

See the ANT documentation for more details.

In order to save memory avoid calling the taskdef more than once. When your test suite grows beyond some thousand steps consider using more than one file for collecting the reports.

java.lang.VerifyError

There may be non-compliant ANT version that interferes with the ant.jar provided in <WEBTESTHOME>/lib.

Consider to copy <WEBTESTHOME>/lib/ant.jar to <ANT_HOME>/lib.

While installTest.xml reports this error on some occasions, it cannot catch all possible cases.

Taskdef not found

The full message is:

taskdef class com.canoo.webtest.ant.TestSpecificationTask cannot be found

This is an ANT problem that occurs when it cannot find the webtest task. The tests contain a part that specifies the location of the webtest ANT task. It looks like this:

ANT task definition
<import file="${webtest.home}/lib/taskdef.xml"/>

The file lib/taskdef.xml that you find in the build.zip contains the valid version of task definitions for your build. It will look for the resource webtest.taskdef in the classpath.

Note: Before build 280 the taskdef was like follows:

old ANT task definition (deprecated)
<taskdef name="webtestclassname="com.canoo.webtest.ant.TestSpecificationTask">
  <classpath>
    <pathelement location="../../classes"/>
    <fileset dir="../..includes="**/lib/*.jar"/>
  </classpath>
</taskdef>

It will look for the file webtestTaskdefs.properties in the directory webtest.home. You can replace webtest.home with an absolute path, or better: define an ANT property for it and use it as above.

You do not need to include the taskdef in your test files, if you install Canoo WebTest as an optional ANT task. Refer to the ANT documentation for this advanced option.

Button not found in a page

If it happens that Canoo WebTest shows an error indicating that it did not find a button that was referenced in a test although the button is clearly visible in the browser (and works as well), one of the most common reasons is incorrectly nested HTML.

In order to track down the problem, turn on the internal HTML parser output by setting the showhtmlparseroutput attribute in the config task to "true". Run the test again and watch out for the parser warnings after each invoke, clickButton or clickLink step. Scan for messages like the ones in the following example:

HTML parser warnings on STDOUT
...
[webtest] line 6 column 1 - Warning: <tr> isn't allowed in <body> elements
[webtest] line 6 column 1 - Warning: inserting implicit <table>
[webtest] line 17 column 2 - Warning: missing </table>
...

If there are similar messages, it is worth taking a look at the original HTML page causing the problems. This can either be done by manually invoking the page in a browser or by enabling the "save-output-feature" and examine the saved HTML page. To do this, set the saveresponse attribute to "true" and let the resultpath attribute point to a valid directory where the output is to be saved. Run the test again and the generated test report will contain a link to the saved result page.

If the report generation is not used, look at the directory specified by resultpath. It contains files like "response_999999999999999_XXX.html". Find the appropriate one by opening the files in a browser and examine the HTML source closely for unbalanced or incorrectly nested HTML tags.

Below is an example for all required settings in the config task:

Configuration for HTML debugging
<webtest name="HTML debugging">
  <config
    ...
    saveresponse="true"
    resultpath="/tmp/results"
    showhtmlparseroutput="true"
  />
  ...
</webtest>

Button found more than once

For clicking on a button or a link, Canoo WebTest needs to locate that button or that link on the page. The above message occurs if the reference is not unique, which generally indicates an error in the test.

Consider using the name attribute or a locator element to create a unique reference. Refer to the syntax description and the samples on how to do this.

If the message still shows up, although the reference should be unique, it is likely that the page's HTML source is invalid. A common error is improper nesting of form elements with table rows and cells, they cannot be mixed. "Taskdef not found" may be helpful.

Getting more information

A test fails, but you don't know why? If that is because of the ANT structure of the tests, unresolved properties or unexpected directory handling, you should consider running your ANT tests with the -v option. This gives additional verbose information about target sequence, unresolved properties and attempts to override property values.

If it is a problem within the HTML, try to use the reporting as described in "Out of Memory". It is often useful to inspect your page with an HTML Validator.

Debugging WebTest

The last ditch attempt to troubleshoot Canoo WebTest is to go for Java debugging on the source code level. You are likely to need not only the Canoo WebTest sources but also the source of the packages that Canoo WebTest is built on. That is ANT, HtmlUnit and JUnit. You may need even more, e.g. when stepping into the xml parsing. But if you are so experienced, you probably know how to do this.

You need a Java debugger, a class to start the debugger on, the command line parameters and the proper classpath and sourcepath. We cannot help you with the debugger itself. You probably have one within your IDE. The JDK contains the jdb, but that one is not very comfortable. The remaining parameters can be determined from your ant starter script that resides under <ANT_HOME>/bin. Put all jars on the CLASSPATH that reside under <ANT_HOME>/lib and <WEBTESTHOME>/lib. Put the sources on the -sourcepath. Provide the option -Dant.home="<ANT_HOME>" and start the debugger on the class org.apache.tools.ant.Main. Provide the command line parameters -buildfile <file> and <target> as necessary.

When debugging, a good thing to look for is implicit tags that the parser inserts into incomplete HTML.

Tests get messy

If your tests get messy, this is mostly because they contain duplication. Avoid this at any costs.

Put all the references that occur more than once into an ANT property. Consider putting shared properties into a properties file. Use the ant and antcall tasks to extract reusable logic into subbuild files and subtargets. Use XML entities for textual includes. See the samples on how to do this. Also consider using Macros - see the ANT documentation for more details.

Keep your targets short and avoid putting too many webtests into one target.

Make use of the description attribute for main targets and use the description attribute for test steps.

Weird Errors running your script

If you get weird errors when running your script inside an IDE it could be that your IDE is using a custom ant runner. For some reason this seems to sometimes cause a conflict. If you find yourself in this situation, try to configure your IDE to use a standard ANT runner.

Possible technical explanation: Canoo WebTest relies on HtmlUnit which parses HTML using NekoHTML. NekoHTML is set up as a custom ContentHandler for the Xerces XML Parser. Your custom ANT runner may also have set itself up as a custom ContentHandler. For some reason this seems to sometimes cause a conflict.

As an example, in IntelliJ, if you run a script which uses the standard embedded ant then if you have a step which parses HTML you might see the following exception thrown: java.lang.AbstractMethodError: org.cyberneko.html.HTMLScanner.getCharacterOffset()I. This will occur if you for instance use an invoke step. The workaround is simply to configure in your ant build settings to use an external ant rather than the embedded one.

news

Latest build: R_1705
Posted: 14-May-2008 13:13

WebTest @ JavaOne
Dierk König will present "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne in the Tools and Scripting Languages track.
Posted: 6 May 2008

WebTest 2.6 released, featuring upgrades to Ant 1.7, Groovy 1.5.4, and HtmlUnit 1.14.
The release includes support for data-driven testing, testing of drag-and-drop, advanced AJAX support, high-concurrency testing and reporting, real-time monitoring, and - as usual - lots of handling improvements.
Posted: 18 March 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007