One, the code is as follows
Package Com.woniuxy.auto;import Java.awt.component;import Java.awt.frame;import java.lang.reflect.method;import Javax.swing.jbutton;import Javax.swing.jcombobox;import Javax.swing.jframe;import Javax.swing.JLabel;import Javax.swing.jtextfield;public class Javacalctest {public static void main (string[] args) {javacalctest calctest = new Java Calctest (); Calctest.startapp (); Calctest.dotest ();} public void Dotest () {JFrame JF = This.getframe ("javaswing demo program"); JTextField Numberx = (JTextField) this.getcomponent (JF, "Txtnumberx"); Numberx.settext ("100"); JTextField numbery = (JTextField) this.getcomponent (JF, "txtnumbery"); Numbery.settext ("200"); JComboBox type = (JComboBox) this.getcomponent (JF, "Calctype"); Type.setselecteditem ("multiplication"); JButton Btncalc = (JButton) this.getcomponent (JF, "Btncalc"); Btncalc.doclick ();d ouble expect = 20000; JLabel result = (JLabel) this.getcomponent (JF, "Lblresult");d ouble actual = double.parsedouble (Result.gettext ()); if ( actual = = expect) {System.out.println ("Multiplication: success.");} Else {System.out.println ("multiplication: Failed.");}} public void startApp () {try {//class<?> clazz = class.forname ("Com.woniuxy.auto.JavaSwingCalc");//method main = Clazz.getmethod ("main", String[].class);//main.invoke (Clazz, New string[1]); Javaswingcalc.main (new string[0]);//javaswingcalc calc = new Javaswingcalc ();//calc.windowinit ();// Calc.buttoninvoke ();//string Userdir = System.getproperty ("User.dir");//string jarfile = Userdir + "\\lib\\ Javaswingcalc.jar ";//runtime.getruntime (). EXEC (" Java-jar "+ jarfile); Thread.Sleep (5000);} catch (Exception e) {e.printstacktrace ();}} Public JFrame GetFrame (String title) {frame[] frames = jframe.getframes (); JFrame JF = null;for (int i=0; i<frames.length; i++) {if (Frames[i].gettitle (). Equals (title)) {JF = (JFrame) frames[i];} }return JF;} Public Component getcomponent (JFrame JF, String name) {component[] controls = Jf.getcontentpane (). getcomponents (); Component control = null;for (int i=0; i<controls.length; i++) {if (Controls[i].getname ()! = null &&Amp;controls[i].getname (). Equals (name)) {control = Controls[i];}} return control;}}
"Automation __gui Automation" __java__ Case __java Application Calculator __ Code to execute the test