01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.request;
03:
04: import org.apache.log4j.Logger;
05:
06: import com.canoo.webtest.steps.Step;
07: import com.gargoylesoftware.htmlunit.Page;
08:
09: /**
10: * Selects the WebClient to use as current, creating a new one if this WebClient doesn't exist.
11: *
12: * @author Marc Guillemot
13: * @webtest.step category="Extension"
14: * name="selectWebClient"
15: * description="Selects the WebClient to navigate with, creating it if none exists with this name.
16: * Useful when a test sequence requires actions to be performed by different users (e.g. an admin and an normal user)."
17: */
18: public class SelectWebClient extends Step {
19: private static final Logger LOG = Logger
20: .getLogger(SelectWebClient.class);
21: private String fName;
22:
23: public String getName() {
24: return fName;
25: }
26:
27: /**
28: * @webtest.parameter required="yes"
29: * description="The name of the WebClient to select (will be created if it doesn't yet exist).
30: * 'default' designates the WebClient available at test startup.
31: * This name has nothing to do with the simulated browser and just serve for organisation within the test"
32: */
33: public void setName(final String newName) {
34: fName = newName;
35: }
36:
37: public void doExecute() throws Exception {
38: LOG.debug("Selecting WebClient " + getName());
39:
40: getContext().defineCurrentWebClientContext(getName());
41:
42: final Page currentResponse = getContext().getCurrentResponse();
43: final String message;
44: if (currentResponse == null) {
45: message = "No current response";
46: } else {
47: message = "Current response is now: "
48: + currentResponse.getWebResponse().getUrl();
49: }
50: LOG.debug(message);
51: }
52:
53: protected void verifyParameters() {
54: super .verifyParameters();
55: emptyParamCheck(getName(), "name");
56: }
57: }
|