Introduction?

This section covers how to write custom functional points specific for the HtmlUnit plug-in..

Please be sure to read the Jameleon Custom Functional Points section on the main Jameleon documents area before continuing here. Many important principles are explained there.

While the provided tags will likely be sufficient to test most web applications, it is recommended to write custom tags that at the very least represent each action or form in your application.

How to Write a Custom Functional Point Using the HtmlUNit Plug-in

All HtmlUnit plug-in functional points must extend HtmlUnitFunctionTag. Extending this class, gives you access to the session and several helper methods. Please see the javadocs provided at the link above for a detailed list of provided methods. For examples, please see the source code for the provided tags.

Quick Tips

Submitting Forms

Usually, custom tags include filling out a form and clicking on the appropriate button. Below is an example of this.

package net.sf.jameleon.plugin.htmlunit.acceptance;

import net.sf.jameleon.plugin.htmlunit.HtmlUnitFunctionTag;

/**
 * Fills out a form and submits it.
 * 
 * @jameleon.function name="htmlunit-form-test" type="action"
 */
public class FormTestTag extends HtmlUnitFunctionTag{

    /**
     * @jameleon.attribute
     */
    protected String username;
    /**
     * @jameleon.attribute
     */
    protected String password;
    /**
     * @jameleon.attribute
     */
    protected boolean someCheckbox;

    public void testBlock(){
        setWorkingFormByName(formName);
        setTextField(usernameField, username);
        setPasswordField(passwordField, password);
        setCheckBox(someCheckboxField, someCheckbox);
        clickElementWithXPath(genXPath());
    }

    public String genXPath(){
        String xpath = "//form[@name='"+formName+"']//input[@type='button' and @value='"+submitButtonName+"']";
        return xpath;
    }

///////////////////////////////////////////////////////////////////////////////////////////////
// For Field Definitions
// These all have default values and contain attributes we wish to make available to be set.
// However, for the most part, these are attributes that hide the form specifics from the user. 
///////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * @jameleon.attribute default="userid"
     */
    protected String usernameField;
    /**
     * @jameleon.attribute default="password"
     */
    protected String passwordField;
    /**
     * @jameleon.attribute default="ed1"
     */
    protected String someCheckboxField;
    /**
     * @jameleon.attribute default="Go"
     */
    protected String submitButtonName;
    /**
     * @jameleon.attribute default="sample"
     */
    protected String formName;
}
If you look at the javadocs for HtmlUnitFunctionTag, you will see each of the methods called above.