From: SourceForge.net <no...@so...> - 2011-12-21 07:38:52
|
The following forum message was posted by nikhilkr1984 at http://sourceforge.net/projects/abbot/forums/forum/168263/topic/3401336: Assume you have prepared the script (ie: xml file) using Abbot. Follow the 3 steps to run it automatically. 1. Create a class like below for initiating your test. [code] package sample.test; import java.io.File; import junit.extensions.abbot.ScriptTestSuite; import junit.framework.Test; import junit.framework.TestCase; import junit.textui.TestRunner; import abbot.Log; import abbot.finder.AWTHierarchy; import abbot.finder.Hierarchy; import abbot.finder.TestHierarchy; import abbot.script.Script; import abbot.script.StepRunner; import abbot.util.AWTFixtureHelper; public class AbbotStarter extends ScriptFixture { static String ABBOT_SCRIPT_HOME ; public AbbotStarter(String name) { super(name); } public static Test suite() { return new ScriptTestSuite(AbbotStarter.class, ABBOT_SCRIPT_HOME); } public static void main(String[] args) { if(args.length<1) { System.out.println("Usage : sample.test.AbbotStarter <Abbot-Script-home>"); return; } ABBOT_SCRIPT_HOME = args[0]; TestRunner.run(AbbotStarter.suite()); new File(burbLog).delete(); } } class ScriptFixture extends TestCase { private static AWTFixtureHelper oldContext = null; private static final Hierarchy DUMMY_HIERARCHY = new AWTHierarchy(); private StepRunner runner; /** * Construct a test case with the given name, which <i>must</i> be the * filename of the script to run. */ public ScriptFixture(String filename) { // It is essential that the name be passed to super() unmodified, or // the JUnit GUI will consider it a different test. super(filename); } /** * Saves the current UI state for restoration when the fixture (if any) is * terminated. Also sets up a {@link TestHierarchy} for the duration of the * test. */ protected void setUp() throws Exception { if (oldContext == null) { oldContext = new AWTFixtureHelper(); } runner = new StepRunner(oldContext); // Support for deprecated ComponentTester.assertFrameShowing usage // only. Eventually this will go away. AWTHierarchy.setDefault(runner.getHierarchy()); } protected void tearDown() throws Exception { AWTHierarchy.setDefault(null); runner = null; } /** * Override the default TestCase runTest method to invoke the script. The * {@link Script} is created and a default {@link StepRunner} is used to run * it. * * @see junit.framework.TestCase#runTest */ protected void runTest() throws Throwable { Script script = new Script(getName(), DUMMY_HIERARCHY); Log.log("Running " + script + " with " + getClass()); try { runner.run(script); } finally { Log.log(script.toString() + " finished"); } } } [/code] 2. Invoke the above class from a batch file, abbot.bat [code] @echo off title Abbot Runner set CP=-classpath set CP=%CP%./lib/abbot.jar; set CP=%CP%./lib/burpsuite_v1.4.01.jar; set CP=%CP%./lib/costello.jar; set CP=%CP%./lib/commons-logging-1.1.1.jar; set CP=%CP%./lib/jdom-1.1.1.jar; set CP=%CP%./lib/junit-4.8.2.jar; set CP=%CP%./AbbotTestRunner.jar java %CP% sample.test.AbbotStarter [/code] 3. Run your application as "abbot.bat my_automation.xml" |