01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.request;
03:
04: import java.io.IOException;
05:
06: import org.xml.sax.SAXException;
07:
08: import com.canoo.webtest.steps.AbstractBrowserAction;
09: import com.gargoylesoftware.htmlunit.Page;
10: import com.gargoylesoftware.htmlunit.WebRequestSettings;
11:
12: /**
13: * This is the abstract base class for all test specification steps
14: * that initiate a request.
15: * <p/>
16: * It offers common functionality like preparing the request,
17: * handling dynamic parameters and captures HTML parser
18: * errors generated by JTidy by providing the required HTML
19: * error listeners.
20: *
21: * @author Carsten Seibert
22: * @author Marc Guillemot
23: * @author Paul King
24: * @webtest.step
25: */
26: public abstract class AbstractTargetAction extends
27: AbstractBrowserAction {
28: private String fUserName;
29: private String fPassword;
30: private final TargetHelper fTargetHelper = new TargetHelper(this );
31:
32: /**
33: * @param userName
34: * @webtest.parameter required="no"
35: * 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."
36: */
37: public void setUsername(final String userName) {
38: fUserName = userName;
39: }
40:
41: public String getUsername() {
42: return fUserName;
43: }
44:
45: public String getPassword() {
46: return fPassword;
47: }
48:
49: /**
50: * @param password
51: * @webtest.parameter required="no"
52: * description="A password that can be provided for pages that require basic authentication. Required if <em>username</em> is specified."
53: */
54: public void setPassword(final String password) {
55: fPassword = password;
56: }
57:
58: /**
59: * Placeholder for a getter. Since this is a <em>synthetic</em> attribute, the getter returns null and it won't be reported.
60: * @return null.
61: */
62: public String getSave() {
63: return null;
64: }
65:
66: protected Page getResponse(final WebRequestSettings settings)
67: throws IOException, SAXException {
68: return fTargetHelper.getResponse(getContext(), settings);
69: }
70:
71: public void doExecute() throws Exception {
72: fTargetHelper.setUsername(getUsername());
73: fTargetHelper.setPassword(getPassword());
74: findTarget();
75: }
76:
77: /**
78: * Fetch the target URL specified byu the step.
79: * @return A new Page for the target URL.
80: * @throws Exception
81: */
82: protected abstract Page findTarget() throws Exception;
83:
84: protected abstract String getLogMessageForTarget();
85: }
|