[Webtest] Refresh-tasks

Parker, Michael webtest@lists.canoo.com
Wed, 28 Jul 2004 09:47:49 +0200


to avoid problems with less supported javascipt we added a Refresch task:

It's a supplement to the deliverd classes as far as we understood:
	puts a request ab
	most of the other tasks work on the resonse
Clickbutton maps the funcitionality of a Submit-Buttons
clicklink verifies links

The task refresh just requests an actualization of ther response.

So we can force some "dynamics" between our input-fields which is not always
guaranteed by the js.jar.

We also had to patch httpunit to work:

The deliverd httpunit-1.5.4.jar
gives us a

    [mkdir] Created dir: D:\webentw\canoo\canoo468\build\classes
    [javac] Compiling 196 source files to
6: cannot resolve symbol
    [javac] symbol  : method getRequestByForm ()
    [javac] location: class com.meterware.httpunit.WebForm
    [javac]                             WebRequest req =3D
    [javac]                                                      ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -deprecation for details.
    [javac] 1 error

So we added the method

		 submit without button-event to simulate
	public WebRequest getRequestByForm() {
	  if (getMethod().equalsIgnoreCase( "post" )) {
			return new PostMethodWebRequest( this );
		} else {
			return new GetMethodWebRequest( this );

Is this to complicate, is there an easier way to do  or could this be a
contribution to canoo ?


// Copyright =A9 2002 Canoo Engineering AG, Switzerland.
package com.canoo.webtest.steps.request;

import com.canoo.webtest.engine.Context;
import com.canoo.webtest.engine.StepExecutionException;
import com.canoo.webtest.engine.StepFailedException;
import com.canoo.webtest.interfaces.IButtonLocator;
import com.canoo.webtest.interfaces.IFormLocator;
import com.canoo.webtest.interfaces.IIndexLocator;
import com.canoo.webtest.self.Block;
import com.canoo.webtest.steps.ParameterHolder;
import com.canoo.webtest.steps.Step;
import com.canoo.webtest.steps.locator.*;
import com.meterware.httpunit.*;
import org.xml.sax.SAXException;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

*  Klasse au=DFerhalb der canoo-Distribution
*  bewirkt submit ohne Button-Event
*  fordert Aktualisierung des aktuellen Response an

public class Refresh extends Target

	IFormLocator fFormLocator =3D null;
	 * C'tor used for instance creation as nested element by ant
	public Refresh()


	 * Gotcha: Use the implementation and *not* the interface for
	 * or a "strange" ant introspection exception will occur ...
	public void addForm(FormLocator locator)
		fFormLocator =3D locator;

	 * Use the locator mechanism to get to the required request by using
the configured
	 * locators (if any). Configure the generated request with
	 * @throws com.canoo.webtest.engine.StepFailedException if the
locator has a problem (e.g. no button found, multiple
	 * buttons found, ...) or if a problem with parameters exists.
	public void doExecute(Context context) throws Exception

			WebResponse resp=3Dcontext.getLastResponse();
			WebForm form =3D resp.getForms()[0];
			setParameters(context, form);
			gotoTarget(context, form);
		catch (Exception error)
			throw new StepFailedException(error.getMessage(),

	protected WebResponse gotoTarget(final Context context, final
WebForm form) throws Exception
		return protectedGoto(context, "refresh", new Block(){
			public void call() throws Exception
				WebRequest req =3D form.getRequestByForm();


	 * Add all parameters collected in the nextParameters HashMap to the
request and remove
	 * all parameters from the request that are listed in the
resetNextParameters list.
	 * Set also the click position if coordinates are configured.
	 * @param context The current test context
	 * @param form The form to add/remove parameters from
	 * @throws com.canoo.webtest.engine.StepFailedException if a
parameter to remove is not present in the request,
	 * if a parameter is not available in the form
	 * or if click positions are configured and target button is no
image button
	protected void setParameters(Context context, WebForm form) throws
		for (Iterator i =3D
context.getNextParameters().entrySet().iterator(); i.hasNext();)
			ParameterHolder parameter =3D (ParameterHolder)
((Map.Entry) i.next()).getValue();
				addParameter(form, parameter);
			catch (IllegalRequestParameterException irpe)
				throw new StepFailedException("No such
parameter in form: " + parameter.getName(), this);

		for (Iterator i =3D
context.getNextResetParameters().iterator(); i.hasNext();)

			String resetParameterName =3D (String) i.next();
(form.getParameterValues(resetParameterName).length > 0)
				throw new StepFailedException("Could not
remove parameter from request: " + resetParameterName, this);


	 * Add a new multivalue parameter to the request. Add the new values
to the existing ones if the parameter
	 * exists already in the request.
	 * @param form The WebForm to which the parameter shall be added
	 * @param parameterHolder The parameterHolder representing the
	private void addParameter(WebForm form, ParameterHolder
		List parameterValues =3D parameterHolder.getValueList();
		if (parameterHolder.isPreserveExistingValue())
			String[] existingParameters =3D
		    (String[]) parameterValues.toArray(new


AXA Service AG
Colonia-Allee 10-20; D-51067 K=F6ln
Tel.: +49 (0)221 - 148 - 24 173
Fax:  +49 (0)221 - 148 - 44 - 42 663
E-Mail: mailto:Michael.Parker@axa.de

Aus Rechts- und Sicherheitsgruenden ist die in dieser E-Mail gegebene Infor=
mation nicht rechtsverbindlich. Eine rechtsverbindliche Bestaetigung reiche=
n wir Ihnen gerne auf Anforderung in schriftlicher Form nach. Beachten Sie =
bitte, dass jede Form der unautorisierten Nutzung, Veroeffentlichung, Vervi=
elfaeltigung oder Weitergabe des Inhalts dieser E-Mail nicht gestattet ist.=
 Diese Nachricht  ist ausschliesslich fuer den bezeichneten Adressaten oder=
 dessen Vertreter bestimmt. Sollten Sie nicht der vorgesehene Adressat dies=
er E-Mail oder dessen Vertreter sein, so bitten wir Sie, sich mit dem Absen=
der der E-Mail in Verbindung zu setzen.
For legal and security reasons the information provided in this e-mail is n=
ot legally binding. Upon request we would be pleased to provide you with a =
legally binding confirmation in written form. Any form of unauthorised use,=
 publication, reproduction, copying or disclosure of the content of this e-=
mail is not permitted. This message is exclusively for the person addressed=
 or their representative. If you are not the intended recipient of this mes=
sage and its contents, please notify the sender immediately.