001: package com.xoetrope.carousel.testpilot;
002:
003: import net.xoetrope.swing.XApplet;
004: import net.xoetrope.xui.XProjectManager;
005: import javax.swing.JFrame;
006: import javax.swing.SwingUtilities;
007: import net.xoetrope.debug.AWTExceptionHandler;
008: import net.xoetrope.xui.XPageManager;
009: import net.xoetrope.xui.XProject;
010: import net.xoetrope.xui.build.BuildProperties;
011:
012: /*
013: To do.
014: 1. Investigate the WBT possibilities
015: 2. Stress testing with multiple instances on a single client and over multiple
016: clients
017: 3. Unit testing applets.
018: */
019:
020: /**
021: * Support for ???
022: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
023: * the GNU Public License (GPL), please see license.txt for more details. If
024: * you make commercial use of this software you must purchase a commercial
025: * license from Xoetrope.</p>
026: * <p> $Revision: 1.2 $</p>
027: * License: see license.txt
028: */
029: public class UnitApplet extends XApplet {
030: private Recorder pg;
031: private static UnitApplet unitApplet;
032: private XProject currentProject;
033: private XPageManager pageMgr;
034:
035: /**
036: * main method to be invoked as an application. This method is invoked as the
037: * entry point to the 'Application', it is not used if an Applet is being
038: * launched. This method establishes the frame within which the application
039: * runs. If overloading this method remeber to call the setup method.
040: */
041: public static void main(String args[]) {
042: if (BuildProperties.DEBUG)
043: AWTExceptionHandler.register();
044:
045: final String[] myArgs = args;
046: SwingUtilities.invokeLater(new Runnable() {
047: public void run() {
048: // createSplashScreen();
049: loadUI(myArgs);
050: }
051: });
052: }
053:
054: public JFrame getFrame() {
055: return clientFrame;
056: }
057:
058: /**
059: * Do the actual work of loading the UI
060: * @param args
061: */
062: protected static void loadUI(String[] args) {
063: JFrame clientFrame = new JFrame();
064: unitApplet = new UnitApplet(args, clientFrame);
065: clientFrame.getContentPane().add(unitApplet);
066: }
067:
068: /**
069: * Create a new aplication. Most of the setup work is actually done by the initialize
070: * method and is called by the main method or the init method depending on
071: * whether or not an application of applet is being launched.
072: */
073: public UnitApplet(String[] args, JFrame frame) {
074: super (args, frame);
075: currentProject = XProjectManager.getCurrentProject(this );
076: pageMgr = currentProject.getPageManager();
077: }
078:
079: public static XApplet getApplet() {
080: return unitApplet;
081: }
082:
083: //
084: // public void testinit()
085: // {
086: // JFrame frame = new JFrame();
087: // frame.getContentPane().add( this );
088: // String args[] = {
089: // "testpilot.properties"};
090: // setup( frame, args );
091: // }
092:
093: public void createScript(String url) {
094: pg = (Recorder) pageMgr.getPage("tprecorder");
095: pg.createScript();
096: }
097:
098: public void resumeScript() {
099: Runner run = (Runner) pageMgr.getPage("tprunner");
100: run.resumeScript();
101: }
102:
103: public void recordEvent(String ctlName, String evt, String tagName,
104: String ctlOuterHTML, String frameName) {
105: pg.recordEvent(ctlName, evt, tagName, ctlOuterHTML, frameName);
106: }
107:
108: public void recordBrowserEvent(String type) {
109: pg.recordBrowserEvent(type);
110: }
111:
112: public void setKeyCode(String key) {
113: pg.setKeyCode(key);
114: }
115:
116: public void setInputValue(String value) {
117: pg.setInputValue(value);
118: }
119:
120: // public boolean isMoniteringAssertion()
121: // {
122: // return false;
123: // }
124:
125: public void setAssertControl(String name, String value, String frame) {
126: Assert assertPage = (Assert) pageMgr.getPage("tpassert");
127: assertPage.setAssertControl(name, value, frame);
128: }
129:
130: public void setStartPage(String url) {
131: AppletConfig welcome = (AppletConfig) pageMgr
132: .getPage("tpwelcome");
133: welcome.setStartPage(url);
134: }
135:
136: public void addPause(String len) {
137: Recorder recorder = (Recorder) pageMgr.getPage("tprecorder");
138: recorder.addPause(len);
139: }
140:
141: public String getHashcode(String str) {
142: return String.valueOf(str.hashCode());
143: }
144:
145: public void debug(String msg) {
146: System.out.println("msg:" + msg);
147: }
148:
149: public void addPauseAfterNext() {
150: Recorder recorder = (Recorder) pageMgr.getPage("tprecorder");
151: recorder.addPauseAfterNext();
152: }
153:
154: public void recordAlert(String value) {
155: Recorder recorder = (Recorder) pageMgr.getPage("tprecorder");
156: recorder.recordAlert(value);
157: }
158:
159: public void recordConfirm(String value, String ret) {
160: Recorder recorder = (Recorder) pageMgr.getPage("tprecorder");
161: recorder.recordConfirm(value, ret);
162: }
163:
164: public boolean getConfirmResult() {
165: Runner runner = (Runner) pageMgr.getPage("tprunner");
166: return runner.getConfirmResult();
167: }
168: }
|