Sign in to follow this  
Followers 0
tracer321us

Java automation

7 posts in this topic

Hi,

At the moment, I'm looking for a scripting program similar to AutoIt that I can use to automate Java applications. Here are my requirements for a program that can automate a Java application:

1) The program should be free

2) The program should run stand alone and not require any kind of installation (other than maybe the actual Java runtime environment itself)

3) An automation script created using this program should be able to simulate mouse clicks and keyboard input whether the computer is in a locked state or not

4) I want this automation script to either be able to be compiled into an exe file or at the very least that it can be executed automatically from the command line using a command similar to "path/theprogram.exe thescript.scr". My point is that I'd like the script to be executed without the need for the user to first load the scripting program , load the actual script into this program, and finally execute the script.

5) I'd prefer that the commands be a script and not actual Java code because I've never programmed in Java and don't have the time to learn it.

I've skimmed through some programs out there but haven't really seen anything that meets my needs. Does anybody know of a program that would fit my needs?

Share this post


Link to post
Share on other sites



@2tracer321us, welcome to the forum.

A better questions would have been, can AutoIt work with Java as AutoIt can do many many things.

Have a look at the Java UDF. If you use the search feature you will find many topics on Java Automation.

If you have any questions regarding the usage of the UDF you can post here on the given thread. I know you will be hard pressed to find a program that meets the second requirement outside of AutoIt.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Hi,

Have a Look at SAHI, a free automation tool for no windows applications :

- Work with IE, FF, Chrome, Safari, Opera

- On httpS (SSL) sites

- 'understand' the Java family : JAVA , AJAX, Javascript, HTML ....

- Record and playback tools

For AJAX see : http://www.youtube.com/watch?v=EYJjXO4ax94

For FLASH / FLEX and HTML5 : commencing in 12/2010

Best is to see : http://sahi.co.in

Regard.

Share this post


Link to post
Share on other sites

Hi,

Have a Look at SAHI, a free automation tool for no windows applications :

- Work with IE, FF, Chrome, Safari, Opera

- On httpS (SSL) sites

- 'understand' the Java family : JAVA , AJAX, Javascript, HTML ....

- Record and playback tools

For AJAX see : http://www.youtube.com/watch?v=EYJjXO4ax94

For FLASH / FLEX and HTML5 : commencing in 12/2010

Best is to see : http://sahi.co.in

Regard.

Hi french guy !

It look interesting !

I have seen the flash tutorial, and it seems there is no install !

I'm right ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Bonjour,

I am not a SAhi specialist and excuse my poor english.

The size of last version is 2303 Ko

SAHI does not write values in the Windows Registry during installation.

I think the word 'Install' can be replaced by 'copy' to a folder

See : http://sahi.sourceforge.net/install.html for installation

you can use AUTOIT and SAHI together using the syntax :

_execute(myScriptAUTOIT.exe) in Sahi

Bonne journée.

Share this post


Link to post
Share on other sites

@HOMERE - thanks for the link, I did not know about the tool.

It looks very much like selenium with a proxy recorder (like JMeter uses) instead of the FF IDE. Selenium is great requiring only Java to run but it is for testing web applications. It will not work for a Swing or AWT based Java GUI like AutoIt will.

While Selenium records in HTML, the test case can be translated into many languages. I currently have a few thousand lines of code mostly created by the IDE to test a web application.

Here is a small sample of what you can do. I have removed some information.

import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.SeleniumException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class MyCustomTestCase extends SeleneseTestCase {

    public static final String timeout = "30000";
    protected String baseURL = "https://someURL/";
    protected String browser = "*iexplore";

    public MyCustomTestCase(String name, URL baseURL) {
        super(name);
        this.baseURL = baseURL.toString();
    }

    public MyCustomTestCase(String name, URL baseURL, String browserType) {
        this(name, baseURL);

        if (!browserType.startsWith("*")) {
            this.browser = "*" + browserType;
        } else {
            this.browser = browserType;
        }
    }

    @Override
    public void setUp(String baseURL, String browserString) throws Exception {
        if (!browserString.startsWith("*")) {
            this.browser = "*" + browserString;
        } else {
            this.browser = browserString;
        }
        super.setUp(baseURL, this.browser);
        selenium.setSpeed("50");
        System.out.print("Starting Browser....  ");
        System.out.println("Connecting to: \"" + baseURL + "\"");
        selenium.windowMaximize();
        if (!getName().isEmpty()) {
            System.out.println("Running Test Case " + getName() + " ...");
        }
    }

    @Override
    public void tearDown() throws Exception {
        System.out.println("Closing Browser ...\n");
        try {
            super.tearDown();
            int count = 0;
            while (util.isProcessRunning("iexplore.exe") && count <= 50) {
                Thread.sleep(250); // like WinWaitActive
                count++;
            }
        } catch (Throwable th) {
            System.out.println("Exception at tearDown: " + th.toString());
        } finally {
            if (util.isProcessRunning("iexplore.exe")) {
                System.out.println("super.tearDown Failed. Forced to manaually stop the session ...\n");
                selenium.stop();
            }
        }
    }

    private void chear_IE_security_certificate() {
        if (selenium.isTextPresent("There is a problem with this website's security certificate")) {
            selenium.click("id=overridelink");
            selenium.waitForPageToLoad(timeout);
        }
    }

    protected void configBrowser() {
        try {
            Thread.sleep(50);
        } catch (InterruptedException ex) {
            Logger.getLogger(MyCustomTestCase.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
        if (util.isProcessRunning("iexplore.exe") == false) {
            try {
                selenium.stop(); // a session is running when IE has been closed
                selenium.start();
                selenium.windowMaximize();
            } catch (NullPointerException nex) { // be thrown if there is no selenium session to stop
                try { // setup will take care of the rest.
                    System.out.println("Selenium session was not started " + nex.toString()
                            + "Starting it now");
                    this.setUp(this.baseURL, this.browser); // setup may not have been run
                } catch (Exception ex) {
                    Logger.getLogger(MyCustomTestCase.class.getName()).log(Level.SEVERE, ex.toString(), ex);
                }
            }
        }
    }
}

Test Cases are created by the IDE (recorded) then I tweek them a touch. This test case is in a seperate class called MyCustomExtendedTestCase which extends MyCustomTestCase.

Here is an example

public boolean ActualTestCase() throws Exception {
        try {
            login("xxxxxx", "xxxxxx");
            if (!selenium.isTextPresent("some custom text ")) {
                selenium.click("link=Pay-roll Tax");
                selenium.waitForPageToLoad("some custom text");
            }
            selenium.click("link=a link I want to click");
            selenium.waitForPageToLoad("30000");
            selenium.type("xxxxxxxxxxSearchCriteria.xxxxxxxClientNumber", "1654540");
            selenium.click("submit");
            selenium.waitForPageToLoad("30000");
            if (!selenium.isTextPresent("Reset")) {
                return true; // Error Handling
            }
            selenium.click("link=Reset");
            selenium.waitForPageToLoad("30000");
            assertTrue(selenium.getConfirmation().matches("^This will xxxxxd\\. Do you wish to continue[\\s\\S]$"));
            verifyTrue(selenium.isTextPresent("OPEN"));
            selenium.click("link=View");
            selenium.waitForPageToLoad("30000");
            assertEquals("33,016,925", selenium.getValue("FieldLocationID")); // assert
            selenium.click("link=Logout");

        } catch (Assertionerror ex) {
            System.err.println("Test Case " + new Throwable().fillInStackTrace().getStackTrace()[0].getMethodName() + " Failed!" + ex.toString());
            Logger.getLogger(MyCustomExtendedTestCase.class.getName()).log(Level.SEVERE, ex.toString(), ex);
            return false;
        } catch (SeleniumException ex) {
            System.err.println("Test Case " + new Throwable().fillInStackTrace().getStackTrace()[0].getMethodName() + " Failed!" + ex.toString());
            Logger.getLogger(MyCustomExtendedTestCase.class.getName()).log(Level.SEVERE, ex.toString(), ex);
            return false;
        }
        System.out.println("Test Case " + new Throwable().fillInStackTrace().getStackTrace()[0].getMethodName() + " Passed!");
        return true;
    }

You can also do stuff within the cmd in Java as with any language.

public static boolean isProcessRunning(String processName) {
        try {
            String line;
            Process p = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + processName + "\"");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                if (line.contains(processName)) {                    
                    input.close();
                    return true;
                }
            }
            input.close(); // the process was not found
        } catch (Exception err) {
            err.printStackTrace();
        }
        return false;
    }

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0