[Webtest] More groovy questions/help needed

Michael Knapp webtest@lists.canoo.com
Wed, 12 Apr 2006 13:02:24 -0700


Thanks Mittie (and Marc for help when Mittie was gone).   I found a
solution.  Since it might  be helpful to  others, allow me to share it:



Objective: store key=3Dvalue pairs between projects.  (in my case, I
needed to create a gift registry in one webtest and access it as a
different user in a subsequent webtest).  This may be a sloppy hack, but
it works for me!



Project 1:
____________

<project default=3D"useCase"><target =
name=3D"UseCase"><webtest><steps>.....
...
<-- do stuff -->
...
<-- set variables -->
	<storeProperty
            description=3D"Property to store for later"
            name=3D"value1"
            value=3D"#{first_value_to_save}"=20
		propertyType=3D"ant"/>

	<storeProperty
            description=3D"Property to store for later"
            name=3D"value2"
            value=3D"#{second_value_to_save}"=20
		propertyType=3D"ant"/>

	<antcall target=3D"storeVars"/>

</steps></webtest></target>

<-- store the variables as filesnames, like tmp/key_value -->
<target name=3D"storeVars">

	<exec executable=3D"touch"> <arg value=3D"tmp/key1_${value1}"
/></exec>
	<exec executable=3D"touch"> <arg value=3D"tmp/key2_${value2}"
/></exec>

<-- later realized there's an ant "touch" step, but haven't changed my
code -->

</target>=09

</project>


Project 2:
_____________

<project default=3D"useCase"><target =
name=3D"UseCase"><webtest><steps>...
	...
	<-- do stuff -->
	...

<-- access the variables -->
	<groovy>

		f =3D new File("./tmp");

		f.eachFileMatch({m =3D it =3D~ /key1_(.*)/}) {=20
		step.setWebtestProperty("propName1",m[0][1])
			//println it //for debug
		}=20

		f.eachFileMatch({m =3D it =3D~ /key2_(.*)/}) {=20
			step.setWebtestProperty("propName2",m[0][1])
			//println it //for debug
		}=20

	</groovy>

<-- use the variables -->
	<someStep
		property=3D"#{propName1}"/>

	<invoke
		url=3D"/myUrl?key2=3D#{propName2}"/>=09

</steps></webtest></target></project>



Hope its of use.....

mike

> -----Original Message-----
> From: webtest-admin@lists.canoo.com=20
> [mailto:webtest-admin@lists.canoo.com] On Behalf Of Dierk Koenig
> Sent: Saturday, April 08, 2006 10:41 AM
> To: webtest@lists.canoo.com
> Subject: RE: [Webtest] More groovy questions/help needed
>=20
> Hi, I'm back.
>=20
> Please let me know if your questions are still open.
>=20
> > [groovy] groovy.lang.MissingMethodException: No signature of method
> > Script1.group() is applicable for argument types:
> > ([Ljava.lang.reflect.Method;) values: {[.......]}
> ..
> > This happens for assorted methods, and even for code I'm lifting=20
> > directly from=20
> > http://webtest-community.canoo.com/wiki/space/Groovy/GroovyStep
> > Like:
> >
> > print 'methods of step:'
> > print group(step.class.methods)
> > print 'properties of step:' print group(step.allProperties())
>=20
> In the examples you refer to the 'group' method gets defined=20
> inside the script of the Groovy Step and is therefore available.
>=20
> More examples are in the Canoo WebTests selftests:
> http://webtest.canoo.com/fisheye/viewrep/CanooWebtest/webtest/
> selftests/test
> s
>=20
> Look for the ones starting with 'G'.
>=20
> happy testing
> Mittie
>=20
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>=20
>=20