//: test_scenario/SwingApplicationScenario.java package test_scenario; import swing.*; import org.netbeans.jemmy.*; import org.netbeans.jemmy.operators.*; /** * Testing Swing application by Jemmy ver 2 toolkit * @author Shpatserman Maria */ public class SwingApplicationScenario implements Scenario{ public int runIt(Object param) { try { //start application new ClassReference("swing.SwingApplication").startApplication(); //wait frame JFrameOperator mainFrame = new JFrameOperator("SwingApplication"); //wait for queue to be empty new QueueTool().waitEmpty(200); //Find button by name(text) JButtonOperator firstButton = new JButtonOperator(mainFrame, "First"); firstButton.push(); new QueueTool().waitEmpty(200); //Find TextField with text ( after push() the First button JTextFieldOperator textField = new JTextFieldOperator(mainFrame,"First pressed"); new QueueTool().waitEmpty(200); //Clear Text textField.clearText(); new QueueTool().waitEmpty(200); //type text + enter textField.enterText("Hello"); new QueueTool().waitEmpty(400); //Find label by text new JLabelOperator(mainFrame,"Hello"); //Find second textField by index JTextFieldOperator textField2 = new JTextFieldOperator(mainFrame,1); textField2.enterText("Field2"); //Find label by text new JLabelOperator(mainFrame,"Field2"); new QueueTool().waitEmpty(400); JButtonOperator secondButton = new JButtonOperator(mainFrame, "Second"); secondButton.push(); new QueueTool().waitEmpty(200); System.out.println("TextField2 = "+textField2.getText()); if (textField2.getText().equals("Second pressed")){ System.out.println("textField 2 OK!!!"); } mainFrame.close(); } catch(Exception e) { e.printStackTrace(); return(1); } return(0); } public static void main(String [] argv){ String[] params = {"test_scenario.SwingApplicationScenario"}; org.netbeans.jemmy.Test.main(params); } }