[Webtest] Grails like Groovy testing in non-grails project

Dierk Koenig Dierk Koenig" <dierk.koenig@canoo.com
Fri, 11 May 2007 00:10:13 +0200


ok, I'm convinced.
(never thought it would be necessary to convince me using Groovy ;-))

Dierk

> -----Original Message-----
> From: webtest-admin@lists.canoo.com
> [mailto:webtest-admin@lists.canoo.com]On Behalf Of Marc Guillemot
> Sent: Donnerstag, 10. Mai 2007 21:08
> To: webtest@lists.canoo.com
> Subject: Re: [Webtest] Grails like Groovy testing in non-grails =
project
>=20
>=20
> Hi Andre,
>=20
> I believe too that WebTest should contain a base WebTestCase class to
> allow writing tests =C3=A0 la Grails. I've tried once to convince =
Dierk to
> include in WebTest distribution some stuff he wrote for Grails but he
> told me that it was too Grails specific to be interesting (and that
> "normal" WebTest users wouldn't not be interested). Your email shows
> that I have to try again to convince him.
>=20
> I don't understand why you start building your webtest test cases with
> the ant builder within an ant script (where you perform a taskdef for
> tasks already defined in the "main" ant project).
>=20
> In fact you can just write your own base WebTestCase using an ant
> builder that does just what is done in Grails or what is done in
> WEBTEST_HOME/webtest.xml (lib/useWebTest.xml is deprecated and will
> disappear). The smartest way would be to import this file in current
> AntBuilder but this doesn't work currently (see recent discussion in
> Groovy User mailing list). In the mean time you have to do it by
> yourself ;-)
>=20
> Marc.
>=20
> Andre Schaefer wrote:
> > Hello all,
> >=20
> > I just startet to use Canoo WebTest to functionally test some web
> > applications. I did use the auto generated tests in a grails project
> > beforehand.
> >=20
> > I understand, that I can use groovy scripts in groovy steps from an =
xml
> > test definition like explained here:
> > http://webtest.canoo.com/webtest/manual/groovy.html
> >=20
> > However I find the approach, grails generated, i.e. test classes
> > extending grails.util.WebTest very elegant.=20
> >=20
> > Is there a chance to use grails.util.WebTest outside of a grails
> > project? How would I do that?
> >=20
> > Here is the minimal example I use for now, wich runs but feels =
"clumsy"
> > in comparison:
> >=20
> > build.xml:
> > /--
> > <project name=3D"BI IDEA Use Case Tests">
> > 	<property name=3D"webtest.resultpath" value=3D"webtest-results" />
> > 	<property name=3D"webtest.resultfile" value=3D"results.xml"/>
> > 	<property name=3D"webtest.resultfile.html" value=3D"results.html"/>
> > 	<property environment=3D"env"/>
> > 	<property name=3D"env.WEBTEST_HOME" location=3D"/opt/webtest"/>
> >=20
> > 	<property name=3D"webtest.home" location=3D"${env.WEBTEST_HOME}"/>
> > 	<property name=3D"testInWork" value=3D"main"/>
> >=20
> > 	<description>
> > 		<![CDATA[
> > 			Invoke the webtest scripts to invoke=20
> functional webtests on the
> > Interface
> > 		]]>
> > 	</description>
> > 	<import file=3D"${webtest.home}/lib/useWebTest.xml" />
> >=20
> > </project>
> > \--
> >=20
> > main.xml:
> > /--
> > ...
> > <project name=3D"testMe" basedir=3D"." default=3D"main">
> > <property environment=3D"env" />
> > 	<import file=3D"${env.WEBTEST_HOME}/lib/taskdef.xml" />
> >=20
> > 	<target name=3D"main">
> >=20
> > 		<webtest name=3D"googletest">
> >   		&config;
> >   		<steps>
> > 				<groovy replaceProperties=3D"false"=20
> file=3D"GoogleStep.groovy" />
> > 			</steps>
> > 		</webtest>
> > </target>
> >=20
> > </project>
> >=20
> > GoogleStep.groovy:
> > /--
> > def ant =3D new AntBuilder()
> > def webtest_home =3D "/opt/webtest"
> >=20
> > ant.taskdef(resource:'webtest.taskdef'){
> >     classpath(){
> >            pathelement(location:"$webtest_home/lib")
> >            fileset(dir:"$webtest_home/lib", includes:"**/*.jar")
> >     }
> > }
> >=20
> > ant.webtest(name:'Test Google with Groovy, AntBuilder and WebTest'){
> >     steps(){
> >         invoke(url:'http://www.google.com')
> >         verifyTitle(text:'Google')
> >         setInputField(name:'q', value:'Groovy')
> >         clickButton(name:'btnG')
> >         =
verifyXPath(xpath:"//a[@href=3D'http://groovy.codehaus.org/']")
> >     }
> > }
> > \--
> >=20
> > Any thoughts?
>=20
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>=20