// Copyright � 2002-2005 Canoo Engineering AG, Switzerland.
package com.canoo.webtest.steps.request;
import java.io.IOException;
import org.xml.sax.SAXException;
import com.canoo.webtest.steps.AbstractBrowserAction;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequest;
/**
* This is the abstract base class for all test specification steps
* that initiate a request.
* <p/>
* It offers common functionality like preparing the request,
* handling dynamic parameters and captures HTML parser
* errors generated by JTidy by providing the required HTML
* error listeners.
*
* @author Carsten Seibert
* @author Marc Guillemot
* @author Paul King
* @webtest.step
*/
public abstract class AbstractTargetAction extends AbstractBrowserAction {
private String fUserName;
private String fPassword;
private final TargetHelper fTargetHelper = new TargetHelper(this);
/**
* @param userName
* @webtest.parameter required="no"
* description="A username that can be provided for pages that require basic authentication. Typically only needed on the first step of any <stepref name='webtest'/> accessing a secure site. Required if <em>password</em> is specified."
*/
public void setUsername(final String userName) {
fUserName = userName;
}
public String getUsername() {
return fUserName;
}
public String getPassword() {
return fPassword;
}
/**
* @param password
* @webtest.parameter required="no"
* description="A password that can be provided for pages that require basic authentication. Required if <em>username</em> is specified."
*/
public void setPassword(final String password) {
fPassword = password;
}
/**
* Placeholder for a getter. Since this is a <em>synthetic</em> attribute, the getter returns null and it won't be reported.
* @return null.
*/
public String getSave() {
return null;
}
protected Page getResponse(final WebRequest settings) throws IOException, SAXException {
return fTargetHelper.getResponse(getContext(), settings);
}
public void doExecute() throws Exception {
fTargetHelper.setUsername(getUsername());
fTargetHelper.setPassword(getPassword());
findTarget();
}
/**
* Fetch the target URL specified byu the step.
* @return A new Page for the target URL.
* @throws Exception
*/
protected abstract Page findTarget() throws Exception;
protected abstract String getLogMessageForTarget();
}