01: /*
02: * Created on 15.10.2004
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.jzonic.webtester.commands;
08:
09: import org.jzonic.webtester.WebTestContext;
10:
11: import com.meterware.httpunit.WebLink;
12: import com.meterware.httpunit.WebResponse;
13:
14: /**
15: * @author Mecky
16: *
17: * TODO To change the template for this generated type comment go to
18: * Window - Preferences - Java - Code Style - Code Templates
19: */
20: public class ClickLinkCommand implements WebTestNode {
21:
22: public static final String COMMAND_NAME = "click_link";
23: private String linkName;
24:
25: public void setParameter(String value) {
26: linkName = value;
27: }
28:
29: public WebTestNodeResult execute(WebTestContext context) {
30: WebTestNodeResult result = new WebTestNodeResult(COMMAND_NAME,
31: linkName);
32: try {
33: WebLink link = context.getLinkWith(linkName);
34: if (link != null) {
35: WebResponse resp = link.click();
36: context.setResponse(resp);
37: result.setSuccess(true);
38: } else {
39: link = context.getLinkWithID(linkName);
40: if (link != null) {
41: WebResponse resp = link.click();
42: context.setResponse(resp);
43: result.setSuccess(true);
44: } else {
45: link = context.getLinkWithImageText(linkName);
46: if (link != null) {
47: WebResponse resp = link.click();
48: context.setResponse(resp);
49: result.setSuccess(true);
50: } else {
51: result.setErrorMessage("The link:'" + linkName
52: + "' was not found");
53: result.setSuccess(false);
54: }
55: }
56: }
57: } catch (Exception e) {
58: result.setSuccess(false);
59: result.setException(e);
60: }
61: return result;
62: }
63:
64: public String getName() {
65: return COMMAND_NAME;
66: }
67:
68: }
|