[Webtest] javascript and webtest
Dierk Koenig
webtest@lists.canoo.com
Tue, 11 Jul 2006 23:30:44 +0200
Hi Stephanie,
Marc is currently not available.
Are you sure you included the groovy step early enough?
Did you check that the text was indeed replaced, e.g. by
println text
at the position marked below (*) ?
cheers
Mittie
> -----Original Message-----
> From: webtest-admin@lists.canoo.com
> [mailto:webtest-admin@lists.canoo.com]On Behalf Of Stefanie Wilms
> Sent: Dienstag, 11. Juli 2006 23:12
> To: webtest@lists.canoo.com
> Subject: Re: [Webtest] javascript and webtest
>
>
> Hi Marc,
>
> I tried your suggestion and it seems to work in general. My problem is
> that the resulting page after a 'setSelectField'-step creates still the
> same error message about the unterminated string before groovy has a
> chance to change the parts of the source code which are causing
> the trouble.
>
> Stefanie
>
>
> Marc Guillemot wrote:
> > Hi Stefanie,
> >
> > here is an example changing the string "User ID" to "toto User
> toto Id" in
> > received responses before the content gets parsed (works with
> latest build
> > using htmlunit 1.9, if you want to use an older version you
> need to look at
> > the API as a bit more glue code is needed):
> >
> > <groovy>
> > import com.gargoylesoftware.htmlunit.*
> >
> > def webClient = (WebClient) step.context.webClient
> >
> > class FixerWebConnection extends WebConnectionWrapper
> > {
> > FixerWebConnection(WebConnection _wrappedConnection)
> > {
> > super(_wrappedConnection)
> > }
> >
> > WebResponse getResponse(WebRequestSettings settings)
> > {
> > WebResponse response = super.getResponse(settings)
> >
> > def text = response.getContentAsString()
> > if (text.contains('User ID'))
> > {
> > text = text.replaceAll('User ID', 'toto
> User Toto Id')
(*)
> > def newResponseData = new
> > WebResponseData(TextUtil.stringToByteArray(text), response.statusCode,
> > response.statusMessage, response.responseHeaders)
> > response = new
> WebResponseImpl(newResponseData, response.url,
> > response.requestMethod, response.loadTimeInMilliSeconds)
> > }
> > return response
> > }
> > }
> >
> > webClient.webConnection = new FixerWebConnection((WebConnection)
> > webClient.webConnection)
> > </groovy>
> >
> > Marc.
>
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest