"Automation __gui Automation" __java__ Case __java Application Calculator __ Code to execute the test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.