SelectWebClient.java :  » Testing » webtest » com » canoo » webtest » steps » request » Java Open Source

Java Open Source » Testing » webtest 
webtest » com » canoo » webtest » steps » request » SelectWebClient.java
// Copyright  2002-2005 Canoo Engineering AG, Switzerland.
package com.canoo.webtest.steps.request;

import org.apache.log4j.Logger;

import com.canoo.webtest.steps.Step;
import com.gargoylesoftware.htmlunit.Page;

/**
 * Selects the WebClient to use as current, creating a new one if this WebClient doesn't exist.
 *
 * @author Marc Guillemot
 * @webtest.step category="Extension"
 * name="selectWebClient"
 * description="Selects the WebClient to navigate with, creating it if none exists with this name.
 * Useful when a test sequence requires actions to be performed by different users (e.g. an admin and an normal user)."
 */
public class SelectWebClient extends Step {
    private static final Logger LOG = Logger.getLogger(SelectWebClient.class);
    private String fName;

    public String getName() {
        return fName;
    }

    /**
     * @webtest.parameter required="yes"
     * description="The name of the WebClient to select (will be created if it doesn't yet exist). 
     * 'default' designates the WebClient available at test startup.
     * This name has nothing to do with the simulated browser and just serve for organisation within the test"
     */
    public void setName(final String newName) {
        fName = newName;
    }

    public void doExecute() throws Exception {
        LOG.debug("Selecting WebClient " + getName());

        getContext().defineCurrentWebClientContext(getName());
        
        final Page currentResponse = getContext().getCurrentResponse();
        final String message;
        if (currentResponse == null)
        {
          message = "No current response";
        }
        else
        {
          message = "Current response is now: " + currentResponse.getWebResponse().getUrl();
        }
        LOG.debug(message);
    }

    protected void verifyParameters() {
        super.verifyParameters();
        emptyParamCheck(getName(), "name");
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.