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='groovy'> instead.

However, this extract from http://webtest.canoo.com/webtest/manual/groovy.html  

   "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='Install proxy'>
  <scriptStep description="Install Proxy" language="groovy"
              src='startZeligServer.groovy' />
<!-- The zeligPort coming out of Groovy code is a "dynamic" property.
         Create an "ant" property of the same name. -->
<storeProperty
      description="Use #{zeligPort} (dynamic property) to create a ${zeligPort} 
(ant property)."
   name="zeligPort"
   propertyType="ant"
   value="#{zeligPort}" />
</webtest>


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Niko Schmuck
Sent: Sunday, April 06, 2008 1:29 PM
To: [email protected]
Cc: [EMAIL PROTECTED]
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  
for. Since I am a newbie to webtest, I still seem to miss the link  
between how to retrieve the "step" variable in your example from my  
groovy code? Assuming that I am in a groovy test class, and extending  
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  
> "step". The process may be reversible also, that is, one may be able  
> to add to the two Property (Map) objects in the Groovy code; but I  
> have not tried that as yet.
>
> //  
> = 
> = 
> ======================================================================
> // Get the two types of properties set in the Webtest.
> //  
> = 
> = 
> ======================================================================
> def antProperties =  
> step.getWebtestProperties( step.PROPERTY_TYPE_ANT ) ;
> def dynamicProperties =  
> step.getWebtestProperties( step.PROPERTY_TYPE_DYNAMIC ) ;
> //  
> = 
> = 
> ======================================================================
>
> "dynamic" == Webtest Property.
>
> They are two separate domains so you either have to know which you  
> want or try both.
>
> Once you have the Maps, just use them like any Java Map. That is,  
> extract your Ant property or Webtest property like this;
>
>  def antPropertyOfInterest =
>      antProperties.get( 'ant.property.of.interest.name' ) ;
>
>  def dynamicPropertyOfInterest =
>      dynamicProperties.get( 'dynamic.property.of.interest.name' ) ;
>
> Hope that helps a bit,
> George
> ________________________________________
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> ] On Behalf Of [EMAIL PROTECTED]
> Sent: Thursday, April 03, 2008 4:41 AM
> To: [email protected]
> Subject: Antwort: RE: [Webtest] Canoo + Grails
>
>
>
> Hi Niko,
>
>> Another question is (for may be including in the documentation),  
>> 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   
> 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" <[EMAIL PROTECTED]>
> Gesendet von: [EMAIL PROTECTED]
> 03.04.2008 12:20
> Bitte antworten an
> [email protected]
>
> An
> Dierk König <[EMAIL PROTECTED]>
> Kopie
> [email protected]
> Thema
> RE: [Webtest] Canoo + Grails
>
>
>
>
>
>
>
> Hi Dierk, and all,
>
> webtest embedded into the grails development process is absolutely  
> 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  
> 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  
> 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önig 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: [EMAIL PROTECTED]
>> | [mailto:[EMAIL PROTECTED] On Behalf Of
>> | [EMAIL PROTECTED]
>> | Sent: Mittwoch, 2. April 2008 14:39
>> | To: [EMAIL PROTECTED]
>> | 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  
>> 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 <[EMAIL PROTECTED]>
>> | Sent by: [EMAIL PROTECTED]
>> |
>> | 04/02/2008 05:34 AM
>> | Please respond to
>> | [EMAIL PROTECTED]
>> |
>> | To
>> | [EMAIL PROTECTED]
>> | 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
>> |
>> |
>> | [EMAIL PROTECTED] 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  
>> 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
>> | [email protected]
>> | http://lists.canoo.com/mailman/listinfo/webtest
>> |
>> |
>> |
>>
>
>
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
>

_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest
_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest

Reply via email to