[Webtest] RE: webtest extension- javascript link

Dierk Koenig webtest@lists.canoo.com
Wed, 28 May 2003 19:38:46 +0200


Hi Grammy,

thanx for post - the extension is a cool idea.

For the overall JavaScript support (that we already started with
clickbutton / clicklink) there is a lot to consider:
- backward compatibility (old test should by default ignore any js)
  your idea of enablement (config?) would address this
  (totally differen WebTest Version? Different step names?)
- duplication
  the internal struture of steps must be totally different for
  the 2 cases - presumably
- lots of work
  change all steps and adapt the documentation and
  last not least make test dummies for all the JS code...

no problem, if someone would pay me for this :-)

I actually think about making contributions easier, such that
someone else can do the work.

cu
Mittie

> -----Original Message-----
> From: Graham Cunningham [mailto:graham.cunningham@itwks.com]
> Sent: Dienstag, 27. Mai 2003 18:33
> To: dierk.koenig@canoo.com
> Subject: webtest extension
> 
> 
> Hoi Mittie,
> I changed the doExecute of ClinkLink to this rather horrible 
> code and if my link urls now start with javascript they work 
> beautifully :-) 
> What do you want to do about javascript support? HttpUnit 
> supports quite a lot so it really is just a question of 
> enablement, do you want special tags or some kind of 
> recognition that javascript is being performed, as you can 
> see my url always begins with javascript: so it was trivial 
> to put in js support for this particular case. Have you 
> thought already about this?
> 
> cheers
> Graham
> 
> 	public void doExecute(Context context)
>     {
>         verifyParameters();
>         super.doExecute(context);
> 
>         String targetUrl = null;
>         WebLink link = null;
>         try {
>             link = locateTextLink(context.getLastResponse());
>             if (link == null)
>             {
>                 link = context.getLastResponse
> ().getLinkWithImageText(getLabel());
>             }
>             if (link == null)
>             {
>                 throw new StepFailedException(getStepId
> (context) + ": Link not found in page: <" + getLabel() 
> + ">", this);
>             }
>             targetUrl = link.getRequest().getURL
> ().toExternalForm();
> 
>         } catch (SAXException e) {
>             handleUnexpectedException(e);
>         } catch (MalformedURLException e) {
>             handleUnexpectedException(e);
>         }
> 
>         try {
>             if (targetUrl.startsWith("javascript"))
>             {
>                 link.click();
>                 WebResponse resp = context.getWebConversation
> ().getCurrentPage();
>                 context.resetNextParameters();
>                 context.setLastResponseForStep(resp, this);
>             }
>             else
>                 gotoTarget(context, targetUrl);
>         } catch (IOException e) {
>             e.printStackTrace();  //To change body of catch 
> statement use Options | File Templates.
>         } catch (SAXException e) {
>             e.printStackTrace();  //To change body of catch 
> statement use Options | File Templates.
>         }
>     }
>