Accessing webtest steps from grails Webtest groovy code (was: Re: [Webtest] Canoo + Grails)
George Policello
George Policello" <gpolicello@mmetrics.com
Mon, 7 Apr 2008 09:47:21 -0700
Niko,
I have not used this particular construct in a <groovy> block since I =
was in a hurry to get things done. From reading the documentation, I =
thought that the bindings were available inside the <groovy> block. I =
used a <scriptStep language=3D'groovy'> instead.
However, this extract from =
http://webtest.canoo.com/webtest/manual/groovy.html =20
"As an example, the GroovyStep class extends the Step class which has =
a
getContext() method which returns the current Context which has a =
method
getCurrentResponse() which returns the current response which has a
method getDocumentElement(). In groovy you can just use
step.context.currentResponse.documentElement to return the current =
HTML
document."
And the subsequent examples imply that step is available within =
<groovy>.
One thing I found is that some of the tags only work properly inside a =
<target>. If you are not inside a <target> you many not have step =
variable since there may not be a step.
An alternative might be to see if things are defined in =
project.getProperties(). Again, I am not sure of the scoping of property =
variables but the "Groovy In Action" book implies that this will get all =
the Ant properties. You might be able to use a <storeProperty> to =
convert any Dynamic properties (Webtest properties) to Ant properties =
depending on your context. There is also the getContext() method briefly =
mentioned in the link above.
Hope that helps,
George
Example I extracted the original code from.
The groovy code has the things from the previous email on the first =
lines.
<webtest name=3D'Install proxy'>
<scriptStep description=3D"Install Proxy" language=3D"groovy"
src=3D'startZeligServer.groovy' />
<!-- The zeligPort coming out of Groovy code is a "dynamic" property.
Create an "ant" property of the same name. -->
<storeProperty
description=3D"Use #{zeligPort} (dynamic property) to create a =
${zeligPort} (ant property)."
name=3D"zeligPort"
propertyType=3D"ant"
value=3D"#{zeligPort}" />
</webtest>
-----Original Message-----
From: webtest-admin@lists.canoo.com =
[mailto:webtest-admin@lists.canoo.com] On Behalf Of Niko Schmuck
Sent: Sunday, April 06, 2008 1:29 PM
To: webtest@lists.canoo.com
Cc: pompl@comnetmedia.de
Subject: Accessing webtest steps from grails Webtest groovy code (was: =
Re: [Webtest] Canoo + Grails)
Hi George,
Many Thanks for your answer, I think this is exactly what I am looking =20
for. Since I am a newbie to webtest, I still seem to miss the link =20
between how to retrieve the "step" variable in your example from my =20
groovy code? Assuming that I am in a groovy test class, and extending =20
from grails.util.WebTest class, how would I access webtest "step"?.
Thanks,
Niko
On 03.04.2008, at 18:45, George Policello wrote:
> Niko,
>
> I am not completely sure what you are asking for.
>
> Here is one way to get things into a Groovy script from a Webtest =20
> "step". The process may be reversible also, that is, one may be able =20
> to add to the two Property (Map) objects in the Groovy code; but I =20
> have not tried that as yet.
>
> // =20
> =3D=20
> =3D=20
> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> // Get the two types of properties set in the Webtest.
> // =20
> =3D=20
> =3D=20
> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> def antProperties =3D =20
> step.getWebtestProperties( step.PROPERTY_TYPE_ANT ) ;
> def dynamicProperties =3D =20
> step.getWebtestProperties( step.PROPERTY_TYPE_DYNAMIC ) ;
> // =20
> =3D=20
> =3D=20
> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> "dynamic" =3D=3D Webtest Property.
>
> They are two separate domains so you either have to know which you =20
> want or try both.
>
> Once you have the Maps, just use them like any Java Map. That is, =20
> extract your Ant property or Webtest property like this;
>
> def antPropertyOfInterest =3D
> antProperties.get( 'ant.property.of.interest.name' ) ;
>
> def dynamicPropertyOfInterest =3D
> dynamicProperties.get( 'dynamic.property.of.interest.name' ) ;
>
> Hope that helps a bit,
> George
> ________________________________________
> From: webtest-admin@lists.canoo.com =
[mailto:webtest-admin@lists.canoo.com=20
> ] On Behalf Of pompl@comnetmedia.de
> Sent: Thursday, April 03, 2008 4:41 AM
> To: webtest@lists.canoo.com
> Subject: Antwort: RE: [Webtest] Canoo + Grails
>
>
>
> Hi Niko,
>
>> Another question is (for may be including in the documentation), =20
>> how to
>> define more than one test suites (beside the standard
>> webtest/tests/TestSuite.groovy) and how to invoke them.
>
> just search for "Any public interest in separating tests by =20
> groups?" in the "grails user" mailing list.
>
> There is a patch which may solve your problem.
>
> I hope, it will be applied to a coming grails version.
>
>
> Best regards
> Marc Pompl
>
>
> "Niko Schmuck" <niko.schmuck@nava.de>
> Gesendet von: webtest-admin@lists.canoo.com
> 03.04.2008 12:20
> Bitte antworten an
> webtest@lists.canoo.com
>
> An
> Dierk K=F6nig <dierk.koenig@canoo.com>
> Kopie
> webtest@lists.canoo.com
> Thema
> RE: [Webtest] Canoo + Grails
>
>
>
>
>
>
>
> Hi Dierk, and all,
>
> webtest embedded into the grails development process is absolutely =20
> great
> to use. Thanks very much for your groovy-fication!
>
> The only thing I wonder is, how one would get out the webtest step
> properties into the groovy script for further processing. I am sure =20
> there
> is a groovy way to interact between webtest properties and groovy
> variables, but cannot find it.
>
> Another question is (for may be including in the documentation), how =20
> to
> define more than one test suites (beside the standard
> webtest/tests/TestSuite.groovy) and how to invoke them.
>
> Cheers,
> Niko
>
>
> On Wed, April 2, 2008 4:05 pm, Dierk K=F6nig wrote:
>> Hi David,
>>
>> The documentation of general Groovy usage with WebTest is
>> under http://webtest.canoo.com/webtest/manual/groovyTesting.html
>> which in turns points to
>> http://grails.codehaus.org/Functional+Testing
>> for the Grais specifics.
>>
>> Could you give a list of topics that are not covered by these
>> pages?
>>
>> much appreciated
>> Dierk
>>
>> | -----Original Message-----
>> | From: webtest-admin@lists.canoo.com
>> | [mailto:webtest-admin@lists.canoo.com] On Behalf Of
>> | david.cate@wachovia.com
>> | Sent: Mittwoch, 2. April 2008 14:39
>> | To: webtest@gate4.canoo.com
>> | Subject: Re: [Webtest] Canoo + Grails
>> |
>> |
>> | Marc, thank you for the response - got it working
>> | beautifully. I've noticed that while the Canoo documentation
>> | is fairly thorough with the exception of the Grails portion
>> | and even Grails skips around the functional testing portion as =20
>> well.
>> |
>> | 1. Are there any sites or guides that give a good overview of
>> | custom functional testing for Webtests in Grails?
>> | 2. This is just to confirm something: the XML patterns for
>> | specifying the tests are not available with the Grails plugin
>> | - correct? If I create my tests within the XML using
>> | definitions and entity replacements - I would then need to
>> | change those tests to use the method described below?
>> |
>> |
>> |
>> |
>> | Marc Guillemot <mguillemot@yahoo.fr>
>> | Sent by: webtest-admin@gate4.canoo.com
>> |
>> | 04/02/2008 05:34 AM
>> | Please respond to
>> | webtest@gate4.canoo.com
>> |
>> | To
>> | webtest@gate4.canoo.com
>> | cc
>> | Subject
>> | Re: [Webtest] Canoo + Grails
>> |
>> |
>> |
>> |
>> |
>> |
>> | Hi,
>> |
>> | the mailing list is fully correct.
>> |
>> | In Grails you can just extract common step sequences in
>> | utility methods like
>> |
>> | // Utility.groovy
>> | class Utility
>> | {
>> | doLogin(ant)
>> | {
>> | ant.group(description: 'perform login')
>> | {
>> | invoke "http://..."
>> | }
>> | }
>> | }
>> |
>> | // SomeTest.groovy
>> | import static Utility.*
>> | ...
>> | webtest('some test')
>> | {
>> | doLogin(ant)
>> | ...
>> | }
>> |
>> | (my mailer still doesn't compile, syntax error are possible ;-))
>> |
>> | When you're utility methods are located directly in your
>> | class (or in some parent class), you don't need to pass ant
>> | as parameter.
>> |
>> | Cheers,
>> | Marc.
>> | --
>> | Blog: http://mguillem.wordpress.com
>> |
>> |
>> | david.cate@wachovia.com wrote:
>> | >
>> | > I have Grails running with Canoo Webtest plugin installed.
>> | Life is great
>> | > except my tests feel very repetitive. When I used Canoo Webtests
>> | > stand-alone, I used a lot of in-line parsing with the entity =20
>> and put
>> | > common tests in areas available to all. I know a lot of
>> | work was going
>> | > on in the background to make those pieces available. Is
>> | there a similar
>> | > process for the plugin for Grails? Is there a different way
>> | to include
>> | > common tests?
>> | >
>> | > This may not the best forum to address the question, if
>> | it's not please
>> | > let me know. There's not a whole lot of information that
>> | discusses this
>> | > that i could find. I would love to be proven wrong -
>> | especially if you
>> | > have the documentation available :)
>> |
>> | _______________________________________________
>> | 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
> _______________________________________________
> 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