01: package com.canoo.webtest.extension.applet.awt;
02:
03: import com.canoo.webtest.extension.applet.runner.AbstractScenario;
04: import com.canoo.webtest.extension.applet.runner.AppletRunner;
05: import org.netbeans.jemmy.operators.ContainerOperator;
06: import org.netbeans.jemmy.operators.LabelOperator;
07: import org.netbeans.jemmy.util.NameComponentChooser;
08:
09: import java.awt.Frame;
10: import java.awt.Label;
11:
12: /**
13: * @author Denis N. Antonioli
14: */
15: public class SuccessScenario extends AbstractScenario {
16: public SuccessScenario(AppletRunner appletRunner, Frame applet) {
17: super (appletRunner, applet);
18: }
19:
20: public int runIt(Object obj) {
21: ContainerOperator appOper = new ContainerOperator(
22: getRootFrame());
23:
24: Label compWelcomeLbl = (Label) appOper
25: .findSubComponent(new LabelOperator.LabelByLabelFinder(
26: Applet.WELCOME));
27: if (compWelcomeLbl == null) {
28: return 1;
29: }
30:
31: LabelOperator compBtnLblOper = new LabelOperator(appOper,
32: new NameComponentChooser(Applet.NAME_LBL_BTN_OUTPUT));
33: if (compBtnLblOper == null
34: || !Applet.BTN_LBL_BEFORE.equals(compBtnLblOper
35: .getText())) {
36: return 2;
37: }
38:
39: LabelOperator imgBtnLblOper = new LabelOperator(appOper,
40: new NameComponentChooser(Applet.NAME_LBL_IMG_SIZE));
41: if (imgBtnLblOper == null
42: || Applet.INITIAL_SIZE.equals(imgBtnLblOper.getText())) {
43: return 3;
44: }
45:
46: /*
47: although this runs on the Mac, awt makes problem on the build server
48: ButtonOperator btnOper = new ButtonOperator(appOper, new NameComponentChooser(Applet.NAME_BTN));
49: if (btnOper == null) {
50: return 3;
51: }
52: btnOper.push();
53: try {
54: Thread.sleep(100);
55: } catch (InterruptedException e) {
56: return 4;
57: }
58: if (!Applet.BTN_LBL_AFTER.equals(compBtnLblOper.getText())) {
59: LOG.error("Got '" + compBtnLblOper.getText() + "' instead of '" + Applet.BTN_LBL_AFTER + "'");
60: return 5;
61: }
62:
63: Label compStatusLbl = (Label) appOper.findSubComponent(new LabelOperator.LabelFinder(new NameComponentChooser(com.canoo.webtest.extension.applet.runner.AbstractAppletStub.APPLET_STATUS_NAME)));
64: if (compStatusLbl == null) {
65: return 6;
66: }
67: // the value of the label comes from the one of the applet's parameters.
68: if (!compStatusLbl.getText().equals("Status: Init")) {
69: return 7;
70: }
71: */
72: return 0;
73: }
74:
75: public String getDescription() {
76: return getClass().getName() + " test (success expected)";
77: }
78: }
|