/** * Gant script that runs all the webtests against a running Grails application, * and allows tests to be filtered based on Class and Method name. * * @author Graeme Rocher * @author Dierk Koenig * @author Bernd Schiffer * @author Lee Butts * * @since 0.4 */ Ant.property(environment: "env") grailsHome = Ant.antProject.properties."env.GRAILS_HOME" pluginHome = new File("./plugins").listFiles().find { it.name.startsWith("webtest")} includeTargets << new File("${grailsHome}/scripts/RunApp.groovy") target(default: "Run's all (or one) of the Web tests against an already running Grails application") { depends(checkForTests, classpath, checkVersion, packagePlugins, packageApp, generateWebXml) event("StatusUpdate", ["Running WebTest"]) def argsSplitted = args?.split(/\s+/) if (argsSplitted) { System.setProperty('webtest.class.run.pattern', argsSplitted[0]) event("StatusUpdate", ["Class filter: ${argsSplitted[0]}"]) if (argsSplitted.length > 1) { System.setProperty('webtest.test.run.pattern', argsSplitted[1]) event("StatusUpdate", ["Test filter: ${argsSplitted[1]}"]) } } Ant.property(file: './webtest/conf/webtest.properties') def serverPort = Ant.antProject.properties.'webtest_port' runApp.serverPort = serverPort.toInteger() def failed = false try { failed = runWebTest() event("StatusFinal", ["WebTest complete"]) } catch (Throwable t) { failed = true event("StatusError", ["${t.class.name}: $t.message"]) event("StatusFinal", ["WebTest error occurred"]) throw t } finally { stopServer() if (failed) { exit(1) } } } target(runWebTest: "Main implementation that executes a Grails' Web tests") { Ant.ant(antfile: "${pluginHome}/scripts/call-webtest.xml") { property(name: 'pluginHome', value: pluginHome) property(name: 'grailsHome', value: grailsHome) } File webtestPropFile = new File("${basedir}/webtest/conf/webtest.properties") Properties props = new Properties() props.load(webtestPropFile.newInputStream()) File resultFile = new File("$props.webtest_resultpath/$props.webtest_resultfile") if (!resultFile.exists()) return true def xml = new XmlSlurper().parse(resultFile) return xml.folder.summary.topsteps.@failed.text().toList()*.toInteger().sum() != 0 } target(checkForTests: "Checks that there are WebTests to run and fails if not") { def tests = resolveResources("file:${basedir}/webtest/tests/**/*") if (!tests) { Ant.fail("WARNING: This project does not contain any WebTests.") } }