[Webtest] Running a webtest from java, rendering output via x slt

Richard Hill webtest@lists.canoo.com
Fri, 23 Jan 2004 10:47:22 -0800


Here's a way to run canoo from a Java class, assuming that
canoo is ran from an Ant build file.

I have a web interface that allows a user to select a canoo suite
and a test environment to run it in. These parameters are passed
in as 'antFile' and 'propertyValue'. This would be simular to an Ant command

like 'ant -f someAntFileName.xml -DmyPropertyName=myPropertyValue'. If
you don't pass in properties you can remove the following lines
from class RunTest:

  Property property = createProperty();
  property.setName(propertyName);
  property.setValue(propertyValue);

Parameter 'buildDirectory' is the path to the Ant build file to execute,
and parameter 'outputFile' is the log file from running the Ant build.

To use this class just create an instance of RunTest and execute it:

----------------------------------------------------------------------------
----
import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import RunTest;

public class RunSomeTest {

  public static void main(String[] args) {

    // get parameter values here from a property file, etc...

    RunTest rt = new RunTest(antFile, propertyName, propertyValue, 
                             buildDirectory, outputFile);
    try{
      rt.execute();
    } catch(BuildException be) {
      be.printStackTrace();
    }
  }
}

----------------------------------------------------------------------------
----
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.types.*;
import org.apache.tools.ant.*;

import java.io.File;

/**
 * Creates an Ant project to run an Ant build
 * @author Richard Hill
 * @version 1.0
 */
public class RunTest extends Ant {

  private static final String generic = "ant";

  public RunTest(String antFile, String propertyName, String propertyValue, 
                 String buildDirectory, String outputFile) {

    project = new Project();
    project.init();
    taskType = generic;
    taskName = generic;
    setOutput(outputFile);
    setAntfile(antFile);
    setDir(new File(buildDirectory));
    Property property = createProperty();
    property.setName(propertyName);
    property.setValue(propertyValue);
  }

}

----------------------------------------------------------------------------
----

Hope this helps,
- Richard 

-----Original Message-----
From: stu robertson [mailto:stu_us@yahoo.com]
Sent: Thursday, January 22, 2004 2:07 PM
To: webtest@gate2.canoo.com
Subject: [Webtest] Running a webtest from java, rendering output via
xslt


What I'd like to be able to do is execute a webtest
from a java class, and specify the location of the xml
file as a classpath resource.

Something like:

java WebTestRunner org.foo.MyTest.xml

and be able to capture the results as xml.

I've looked through the javadoc and source, but I'm
not sure of the best (or any :-) way to do this.

Any input would be greatly appreciated.  I'm planning
on integrating webtest and Cactus, where we're
executing all of our other tests.

Thanks!

Stu

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
_______________________________________________
WebTest mailing list
WebTest@lists.canoo.com
http://lists.canoo.com/mailman/listinfo/webtest