0

My application is developed on java swing technology and we are trying to automate it using commercial tools build on windows and dlls, but the tool was not able to wait till all the swing event/worker threads complete processing... I have a need go to read and monitor the my application thread/event process completion status before moving to next operation ?

Please help me in some sample code to read swing application process from another jar/ from command prompt

In simple words, how to read java swing application thread/process completion status from another java program? we are using github.com/vivekprahlad/frankenstein to automate our application ... this has very less documentation on how to start application and execute tests ...

I am intermediate to eclipse and java programs ... all we are trying is to automate unit test cases using frankenstein.. Need help on how to start with sample code ... 1. How to start my application from frankenstein, my application will start from a bat file, I added 'com.thoughtworks.frankenstein.application.PipingMain com.abc.app.tone.all.Launcher' to bat file, so that frankenstein recorder will open and was able to record actions. But want to write a test in eclipse and execute ..

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
SAM
  • 11
  • 1
  • 1
    I'm not sure about the others, but I'm very confused about your requirements and problems. Consider clarifying your question by providing more detail and explanation and possibly some pertinent code, preferably a [minimal example program](http://stackoverflow.com/help/mcve) if that's possible. – Hovercraft Full Of Eels Apr 04 '15 at 16:15
  • In simple words, how to read java swing application thread/process completion status from another java program? we are using https://github.com/vivekprahlad/frankenstein to automate our application ... this has very less documentation on how to start application and execute tests ... – SAM Apr 04 '15 at 17:09
  • @HovercraftFullOfEels I am intermediate to eclipse and java programs ... all we are trying is to automate unit test cases using frankenstein.. Need help on how to start with sample code ... 1. How to start my application from frankenstein, my application will start from a bat file, I added 'com.thoughtworks.frankenstein.application.PipingMain com.abc.app.tone.all.Launcher' to bat file, so that frankenstein recorder will open and was able to record actions. But want to write a test in eclipse and execute .. – SAM Apr 04 '15 at 17:17
  • Why don't you use VC++ for this? and if using java is very important, why are you destroying the language's **WORA** principle? – nom Apr 04 '15 at 17:24
  • @NabeelOmer Didn't get your comment, how does VC++ would solve my issue ? or will it automate java swing applications ? if yes any tool suggestions you have ? – SAM Apr 04 '15 at 17:43

1 Answers1

2

One approach is to make your SwingWorker background task separately testable. Using this example, set an appropriate exit() status in the implementation of done(). In the example below, the code is marked successful, 0 by convention, if the calculated value is within a defined tolerance.

Command line:

$ java -cp build/classes Test ; echo $?
1.4142135623730951
0

Code:

import java.util.List;
import javax.swing.SwingWorker;

public class Test {

    /** @see https://stackoverflow.com/a/4637725/230513 */
    private static class TwoWorker extends SwingWorker<Double, Double> {

        private static final int N = 5;
        double x = 1;

        @Override
        protected Double doInBackground() throws Exception {
            for (int i = 1; i <= N; i++) {
                x = x - (((x * x - 2) / (2 * x)));
                setProgress(i * (100 / N));
                publish(x);
            }
            return x;
        }

        @Override
        protected void process(List<Double> chunks) {
            for (double d : chunks) {
                //…
            }
        }

        @Override
        protected void done() {
            System.out.println(x);
            System.exit((Math.abs(x - Math.sqrt(2))) < 0.00001 ? 0 : 1);
        }
    }

    public static void main(String[] args) {
        new TwoWorker().execute();
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045