[Webtest] minor problem with <clickbutton>

webtest@lists.canoo.com webtest@lists.canoo.com
Wed, 3 Sep 2003 15:55:37 -0600


Hi,

I'm having a minor problem with <clickbutton> when
there are multiple forms on the page with the same
button name.  Although I specify <form> or <index>,
I get an error indicating that the target form does
not have the specified input.  I'm using build 364.

I get the following error:

com.canoo.webtest.engine.StepFailedException: No such parameter in form: input2, Step: ClickButton at file:C:/views/srpOasis1.2J/Oasis/was/tools/canooPlus/examples/tests.xml:225: with (stepId="submit form", name="submit", stepType="clickbutton")

HTML snippet:

<form name="form1" method="post" action="example2.html">
<input name="input1" type="text" size="10" value="">
<input name="submit" type="submit" value="submit">
</form>
<form name="form2" method="post" action="example2.html">
<input name="input2" type="text" size="10" value="">
<input name="submit" type="submit" value="submit">
</form>

WebTest snippet:

<steps>
<invoke url="example2.html"/>
<setinputfield stepid="set input value" name="input2" value="xyzzy"/>
<clickbutton stepid="submit form" name="submit">
  <form name="form2"/>
</clickbutton>
</steps>

If I modify the HTML to eliminate the duplicate names
so I don't need the locators, it works fine -- but this
is really not an option.

It looks like ClickButton.findFormFor(...) does not
use the form/index locators.  The HTML/test above works
When I extend ClickButton and override findFormFor() 
with:

protected WebForm findFormFor( WebResponse resp, Button button ) throws SAXException
{
  if ( formLocator != null ) {
    try {
      // cachedContext is a reference to the Context passed in to doExecute()
      return formLocator.locateForm( cachedContext );
    }
    catch ( Exception e ) {
      // error ... fall in to parent functionality
    }
  }
  if ( indexLocator != null ) {
    // findFormsFor() is a utility to find all forms that contain 'button'
    return ( WebForm )indexLocator.locateItem( findFormsFor( resp, button ) );
  }
  return super.findFormFor( resp, button );
}

It would also be very nice to have the error message include
the form name.

By the way, I've been using an older version of WebTest
(build 234) for the past year to monitor/test development
on a web-site, and it has been invaluable!  Thanks for all
the good work.

Regards,

Stephen