[Webtest] FollowFrame
Dierk Koenig
webtest@lists.canoo.com
Wed, 16 Oct 2002 15:40:46 +0200
looks perfekt!
Unit tests ideas (error messages) for:
- there is no lastResponse
- lastResponse does not contain a frameset
- lastResponse contains multiple framesets
- what if there is a <noframes> section?
Functional Tests by extending the selftest servlet with frames.
Check that the reporting is done correctly.
Congratulations
Mittie
> -----Original Message-----
> From: webtest-admin@lists.canoo.com
> [mailto:webtest-admin@lists.canoo.com]On Behalf Of Torben Tretau
> Sent: Mittwoch, 16. Oktober 2002 14:50
> To: webtest@gate.canoo.com
> Subject: [Webtest] FollowFrame
>
>
> Hi List,
>
> getting new into WebTest I quickly hacked a FollowFrame element
> as mentioned sometimes earlier from Dierk in a discussion here..
> As I am new and surely I could misunderstood some things and made
> wrong, I post my first hack here..
> Perhaps someone who is more into it can give me feedback on it and
> give me hints on what i could have done wrong..
>
> ------------------------- snip
> -------------------------------------------------
> my add-on to the Target-class: (->creator: is it totally wrong
> placed here?)
> ...
> public WebResponse gotoSubframe(TestContext context, String
> framename) throws IOException, MalformedURLException, SAXException {
> WebResponse resp = null;
> try {
> installHtmlErrorHandlerIfNeeded(context);
> logText(context, "-> gotoSubframe(by name): " + framename);
> prepareConversation(context);
> resp = context.getLastResponse().getSubframeContents(framename);
> } catch (AuthorizationRequiredException are) {
> throw new TestStepFailedError("Authorization required
> for page: " + framename, this);
> } catch (HttpNotFoundException hnfe) {
> throw new TestStepFailedError(getStepId(context) + ":
> Page not found: " + framename, this);
> } finally {
> removeHtmlErrorHandlerIfNeeded(context);
> }
>
> context.resetNextParameters();
> context.setLastResponseForStep(resp, (Target) this);
>
> return resp;
> }
> ...
> -----------------snap---------------------------------------------
> ---------------
> my FollowFrame-class:
> package com.canoo.webtest.steps;
>
> import com.canoo.webtest.engine.TestContext;
> import com.canoo.webtest.engine.TestStepSetupError;
> import com.canoo.webtest.engine.TestStepFailedError;
> import com.meterware.httpunit.WebLink;
> import com.meterware.httpunit.WebResponse;
> import org.xml.sax.SAXException;
>
> import java.util.*;
>
> public class FollowFrame extends Target
> {
> private String fName;
>
> /**
> * Constructor used for instance creation as nested element by ant
> */
> public FollowFrame()
> {
> super();
> }
>
> protected void doExecute(TestContext context) throws Exception
> {
> super.doExecute(context);
>
> String[] subFrames = context.getLastResponse().getFrameNames();
> boolean foundFrame = false;
> for (int i=0;i < subFrames.length; i++) {
> if(subFrames[i].equals(getName()))
> {
> foundFrame = true;
> }
> }
> if(!foundFrame)
> throw new TestStepFailedError(getStepId(context) + "
> Frame not found with name: " + getName(), this);
>
> verifyParameters();
> gotoSubframe(context, getName());
> }
>
> private void verifyParameters()
> {
> if (fName == null)
> {
> throw new TestStepSetupError("Required parameter name
> not set!", this);
> }
>
> }
>
> protected String getName()
> {
> return fName;
> }
>
> public void setName (String newName)
> {
> fName = newName;
> }
>
> public HashMap getParameterDictionary()
> {
> HashMap map = super.getParameterDictionary();
> if (getName() != null)
> {
> map.put("name", getName());
> }
> return map;
> }
>
> protected void expandProperties()
> {
> super.expandProperties();
> fName = expandDynamicProperties(fName);
> }
> }
>
> ----------------------------snap----------------------------------
> -----------------
>
> now a <followframe name="blub"/> works for me..
>
> Looking forward for all feedback..
> Bye,
> Torben
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>