[Webtest] NullPointerException on clickLink for javascript

Marc Guillemot webtest@lists.canoo.com
Thu, 05 Feb 2004 16:33:27 +0100


Hi Glen,

The problem comes from a bug in Webtest'S ClickLink (I think, that I've mention 
it for a few months in this mailing list. I will fix it in the distribution as 
soon as the server is ok again). In fact the links are not currently "clicked" 
but a new http request is performed using the href of the link.

This can be easily fixed in doExecute of ClickLink.java, just replace the

   targetUrl = link.getRequest().getURL().toExternalForm();
   gotoTarget(context, targetUrl);

with something like:

   final WebLink theLink = link;
   protectedGoto(context, "page - url=" + theLink.getURLString(), new Block() {
	public void call() throws Exception {
	  WebResponse resp = theLink.click();
	  setIntermediateResponse(resp);
	}
   });


Note: this is not necessary what I would commit. I haven't searched for the best 
way to solve the bug, but this is just a quick solution.

Btw: I think that in your example, the javascript is not needed and a submit 
button with the appropriate style would do exactly the same (you have many html 
correctness problems too ;-)

Marc.

Glen Cordrey wrote:
> Below is the code where the problem is occuring, with comments added to show the results from
> debugging so far.
> 
> 
> package com.canoo.webtest.steps.request;
> ...
> public abstract class Target extends Step {
> ...
> protected WebResponse getResponse(Context context, String url) throws IOException, SAXException {
> 
>         // a println of url at this point shows it to be the string " javascript:document.getElementById('loginForm').submit();"
> 
>         prepareConversation(context);
>         WebResponse response = context.getWebConversation().getResponse(url);
>         LOG.debug("Target.getResponse");
> 
>         /// NullPointerException occurs here because response is null
> 
>         LOG.debug("response.getURL() = " + response.getURL());
>         LOG.debug("response.isHTML() = " + response.isHTML());
>         LOG.debug("response.getText() = " + response.getText());
>         return response;
>     }
> 
> 
>    
> 
> 
> -----Original Message-----
> From: Marc Guillemot [mailto:mguillemot@yahoo.fr]
> Sent: Thursday, February 05, 2004 3:43 AM
> To: webtest@lists.canoo.com
> Subject: Re: [Webtest] NullPointerException on clickLink for javascript
> 
> 
> No idea.
> Have you the stack trace of the root cause, in this case, it would probably 
> provide better information.
> 
> Marc.
> 
> Glen Cordrey wrote:
> 
>>Any idea why I'm getting the NullPointerException on the clicklink that 
>>I want to exercise the javascript in
>>the buttonLink shown below?
>> 
>>file:E:/ci/canooTests/auto_search.xml:12: Test failed.
>>Exception raised: com.canoo.webtest.engine.StepExecutionException: 
>>Unexpected exception caught: java.lang.NullPointerExc
>>eption, Step: ClickLink at  with (href="getElementById", label="log in", 
>>stepId="Click the submit button", stepType="cli
>>cklink")com.canoo.webtest.engine.StepExecutionException: Unexpected 
>>exception caught: java.lang.NullPointerException, St
>>ep: ClickLink at  with (href="getElementById", label="log in", 
>>stepId="Click the submit button", stepType="clicklink")
>>        at 
>>com.canoo.webtest.steps.Step.handleUnexpectedException(Step.java:343)
>>        at 
>>com.canoo.webtest.steps.request.Target.protectedGoto(Target.java:115)
>>        at 
>>com.canoo.webtest.steps.request.Target.gotoTarget(Target.java:153)
>>        at 
>>com.canoo.webtest.steps.request.ClickLink.doExecute(ClickLink.java:36)
>>        at com.canoo.webtest.steps.Step.execute(Step.java:103)
>>        at com.canoo.webtest.engine.Engine.executeSteps(Engine.java:26)
>>        at 
>>com.canoo.webtest.ant.TestSpecificationTask.execute(TestSpecificationTask.java:61)
>>        at 
>>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
>>        at org.apache.tools.ant.Task.perform(Task.java:341)
>>        at org.apache.tools.ant.Target.execute(Target.java:309)
>>        at org.apache.tools.ant.Target.performTasks(Target.java:336)
>>        at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
>>        at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
>>        at org.apache.tools.ant.Main.runBuild(Main.java:609)
>>        at org.apache.tools.ant.Main.start(Main.java:196)
>>        at org.apache.tools.ant.Main.main(Main.java:235)
>> 
>><clicklink label="log in" 
>>    stepid="Click the submit button"/>
>> 
>><a class="buttonLink"
>>href="javascript:document.getElementById('loginForm').submit();"
>>testId="a_loginSubmit">
>><img align="absmiddle" alt="" border="0" class="buttonImage"
>>name="imgBtnArrow" src="images/layout/btn_arrow_r.gif" />
>>log in</a>
>>------------------------------------------------------------------------
>>
>>*Glen Cordrey                 Convera*              
>>
>>voice: (410) 740-8800 x1150  http://www.convera.com 
>><http://www.convera.com/>
>>fax:    (410) 740-8810
>> 
>> 
> 
> 
> 
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>