[Webtest] Fix for 2 successive <followframe ..>

Marc Guillemot webtest@lists.canoo.com
Wed, 14 May 2003 09:59:47 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0066_01C319FF.8D56B290
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi,

it seems there is a bug in HttpUnit preventing to use successively 2
Webtest's <followframe> (needed in the case where a frame contains itself a
frameset) because HttpUnit doesn't give the right frame names on the second
level but prefixes them with the first level frame name and a ":". I've
entered a bug report by HttpUnit for this:
http://sourceforge.net/tracker/index.php?func=detail&aid=737167&group_id=655
0&atid=106550
and I attach my changed version of
com.canoo.webtest.steps.request.FollowFrame allowing to cope with this
"bug". I have no unit test to incorporate because I've not seen where test
resources should be located.

Marc.

------=_NextPart_000_0066_01C319FF.8D56B290
Content-Type: application/octet-stream;
	name="FollowFrame.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="FollowFrame.java"

package com.canoo.webtest.steps.request;=0A=
=0A=
import com.canoo.webtest.engine.Context;=0A=
import com.canoo.webtest.engine.StepExecutionException;=0A=
import com.canoo.webtest.engine.StepFailedException;=0A=
import org.xml.sax.SAXException;=0A=
=0A=
import java.util.Arrays;=0A=
import java.util.HashMap;=0A=
import java.util.List;=0A=
=0A=
/**=0A=
 * @author <a href=3D"torben@tretau.net">Torben Tretau</a>=0A=
 */=0A=
public class FollowFrame extends Target {=0A=
    private String fName;=0A=
=0A=
    /**=0A=
     * Constructor used for instance creation as nested element by ant=0A=
     */=0A=
    public FollowFrame() {=0A=
        super();=0A=
    }=0A=
=0A=
    public void doExecute(Context context) {=0A=
        super.doExecute(context);=0A=
=0A=
        if (context.getLastResponse() =3D=3D null) {=0A=
            throw new StepExecutionException("No last response =
available!");=0A=
        }=0A=
=0A=
		List liSubFrames =3D null;=0A=
        try {=0A=
        	liSubFrames =3D =
Arrays.asList(context.getLastResponse().getFrameNames());=0A=
        } catch (SAXException e) {=0A=
            handleUnexpectedException(e);=0A=
        }=0A=
        String strDeepFrameName =3D getName();=0A=
        if (!context.getLastResponse().getFrameName().equals("_top"))=0A=
        	strDeepFrameName =3D context.getLastResponse().getFrameName() + =
":" + getName();=0A=
=0A=
		if (!liSubFrames.contains(strDeepFrameName))=0A=
        {=0A=
        	StringBuffer sb =3D new StringBuffer();=0A=
        	sb.append(getStepId(context))=0A=
        		.append(" Frame not found with name: ")=0A=
        		.append(getName())=0A=
        		.append(" (existing frames: ")=0A=
        		.append(liSubFrames.toString())=0A=
        		.append(")");=0A=
            throw new StepFailedException(sb.toString(), this);=0A=
		}=0A=
=0A=
        verifyParameters();=0A=
        gotoSubframe(context, getName());=0A=
    }=0A=
=0A=
    private void verifyParameters() {=0A=
        if (fName =3D=3D null) {=0A=
            throw new StepExecutionException("Required parameter name =
not set!");=0A=
        }=0A=
=0A=
    }=0A=
=0A=
    protected String getName() {=0A=
        return fName;=0A=
    }=0A=
=0A=
    public void setName(String newName) {=0A=
        fName =3D newName;=0A=
    }=0A=
=0A=
    public HashMap getParameterDictionary() {=0A=
        HashMap map =3D super.getParameterDictionary();=0A=
        if (getName() !=3D null) {=0A=
            map.put("name", getName());=0A=
        }=0A=
        return map;=0A=
    }=0A=
=0A=
    public void expandProperties() {=0A=
        super.expandProperties();=0A=
        fName =3D expandDynamicProperties(fName);=0A=
    }=0A=
}=0A=

------=_NextPart_000_0066_01C319FF.8D56B290--