01: package org.jzonic.webtester.commands;
02:
03: import org.jzonic.webtester.WebTestContext;
04:
05: import com.meterware.httpunit.SubmitButton;
06: import com.meterware.httpunit.WebForm;
07: import com.meterware.httpunit.WebResponse;
08:
09: /**
10: * This command will submit the selected form.
11: * <br/>
12: * parameter: name of the button
13: * <br/>
14: * examples:
15: * <br/>
16: * submit_form | btnSave
17: *
18: * @author Mecky
19: */
20: public class SubmitFormCommand implements WebTestNode {
21:
22: public static final String COMMAND_NAME = "submit_form";
23: private String btnName;
24:
25: public void setParameter(String value) {
26: btnName = value;
27: }
28:
29: public WebTestNodeResult execute(WebTestContext context) {
30: WebTestNodeResult result = new WebTestNodeResult(COMMAND_NAME,
31: btnName);
32: WebForm form = context.getWebForm();
33: if (form != null) {
34: try {
35: SubmitButton btn = form.getSubmitButton(btnName);
36: WebResponse resp = form.submit(btn);
37: context.setResponse(resp);
38: result.setSuccess(true);
39: } catch (Exception e) {
40: result.setSuccess(false);
41: result.setException(e);
42: }
43: } else {
44: result.setErrorMessage("submit_form: No form selected");
45: result.setSuccess(false);
46: }
47: return result;
48: }
49:
50: public String getName() {
51: return COMMAND_NAME;
52: }
53:
54: }
|