Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

Sahi on Java applet file uplaod page

realmindsrealminds Members
edited 10:13AM in Sahi - Open Source
Hi,
I was testing Sahi to update a few fields on soem secure pages, works pretty fine. I have a page made in java upload where when it loaded, one can press a button to browse for a file, then submit and file is uploaded to web server. I wonder if it is possible to automate using sahi?
Thanks

Comments

  • narayannarayan Administrators
    Hi,
    Applets are not currently supported by Sahi unless applet buttons have been programmatically exposed to javascript.
    Applet support is being worked upon and may be available soon (no timelines yet).
    Let us know if you would want this on priority.
    Regards,
    Narayan
  • Hi,
    Thanks for your reply. Not on priority, I can wait when Sahi is able to play with java applet pages :)
    Thanks.
  • Hi,

    I saw several posts about sahi working with JAVA, but this is the only one with an answer.

    I have the same problem, I want to test a page that has both JAVA applets and JAVASCRIPT. The problem with the applets is that they do not offer public methods for setting or selecting things, just ones for getting what's been selected, so I can't use that way around the applets (to call their public methods through sahi).

    So is there any chance there will be some applet support in the not-so-far-future? Is there any applet-testing utility that can be run from sahi?

    Best regards,
  • narayannarayan Administrators
    Well, if you insist, we could add support for applets. How integral to your application testing is this applet support?
  • Hi narayan,

    Thank you for the answer!

    Our application has several parts that are applets, these do not implement core functionality, but without using the applets one can not test the access to all core functionality via the user interface. So applet support is crucial for us.

    From the posts in the forum I conclude I'm not the only one who would be happy about applet support ;-)

    Best regards,
  • Hi,

    In the thread cited below you suggest using java.awt.Robot for clicking on a (in this case) Flash application (as a crude and dirty hack), would this be the way to do applet support for sahi as well?

    topic id=1022

    I think some of the applet threads mentioned Robot as well, but I don't find it right now.

    I also tried executing an external program for clicking on the applet through sahi, the sikuli project of MIT (sikuli.org/). I really need just a few mouseclicks, so it's a 4 line sikuli script that runs fine on itself, but does not run when called via _execute from sahi. I found threads in the sahi suggesting such a thing might not run... So I'm a little bit stuck right now.

    Does anyone have a suggestion on what might at least theoretically work for applets when using sahi?

    Best regards,
  • narayannarayan Administrators
    Hi,

    java.awt.Robot may work.
    _execute should work too. If it does not, use java's runtime.exec() to launch Sikuli.
    Have a look at http://sahi.co.in/w/sahi-scripting-calling-java to see how to invoke Java from a Sahi script.

    You could also check AutoIt if you are on windows.

    Regards,
    Narayan
  • Hi,

    First success report:

    java.awt.Robot works at least as the mouse gets translated to the desired absolute screen coordinates and performs left- and right mouse clicks (both are needed, select, pop-up menu, select menu item from it).

    Of couse absolute screen coordinates are not very useful, but it's a start.

    That's my test code, included in a sahi .sah script:
    function testMouse () {
            var robot = new java.awt.Robot();
        var mouseX = 150;
        var mouseY = 608;
        robot.mouseMove(mouseX, mouseY);
        robot.delay(2000);
        robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
        robot.delay(2000);
            robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
        robot.mousePress(java.awt.event.InputEvent.BUTTON3_MASK);
        robot.delay(2000);
            robot.mouseRelease(java.awt.event.InputEvent.BUTTON3_MASK);
        robot.mouseMove(mouseX+10, mouseY+10);
        robot.delay(2000);
        robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
        robot.delay(2000);
            robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
        
    }
    
    // Call it
    _wait(1000)
    testMouse();
    
    

    Best regards,
  • Hi,

    This might be interesting for other sahi users with un-sahi-able elements on theit webpages like applets or flashes, so I'm posting it here. Please post improvements you make ;-)

    Using sikuli as a way to identify clickable elements inside an applet (I assume it works the same way with other embedded objects, as it works on the operating system level and not on the browser level;) proved to be useful. Sikuli makes screenshots of the elements you want to click/enter text to/whatever and uses some sort of pattern matvhing to find the elements afterwards. You have to record the sikuli scripts separately from sahi using the sikuli IDE.

    Sikuli is a java applivcation, so you need to do two things to integrate it with sahi: add the jar file and options to sahi.bat (and whatever you use for batch running) and have a function in your sahi scripts that calls the sikuli scripts on the appropriate locations.

    add this to sahi.bat:
    REM =====================
    set SIKULI_PATH=PATH_TO_YOUR_Sikuli
    REM =====================
    set SAHI_EXT_CLASS_PATH=%SAHI_EXT_CLASS_PATH%;%SIKULI_PATH%\sikuli-ide-full.jar
    set PATH=%PATH%;%SIKULI_PATH%;%SIKULI_PATH%\tmplib
    set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar
    
    java -Dfile.encoding=UTF-8 -Dpython.path="%~d0%~p0sikuli-ide-full.jar\Lib" -classpath %SAHI_EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.Proxy "%SAHI_HOME%" "%SAHI_USERDATA_DIR_TMP%"
    

    function to call sikuli with a sikuli script:
    /* 
     * Run the given sikuli script, which must be a directoty containing 
     * the PNG (.png) images and a Python (.py) file
     * 
     * Does throw NullPointerException if sikuli does not find the images,
     * try again! 
     */
    function runSikuli ($sikuli_script) {
        //_wait(10000) // wait for applets to load -- better do it in the sikuli skript by waiting for a specific image to appear
        var sikuli = new edu.mit.csail.uid.ScriptRunner();
        sikuli.runPython(new Array($sikuli_script));
    }    
    

    Enjoy!
  • narayannarayan Administrators
    Hi,

    This is quite cool! Thanks for sharing!

    Regards,
    narayan
  • Hi,

    the batch and code seems from an older version of sikuli and sahi. Is it possible to get a new version of both?

    I'm inserted the sikuli-ide.jar and .dlls into extlib\sikuli and added it to the extend class path variable in the batch file.

    Using the function from above with org.sikuli.script.ScriptRunner always throws me an "Type Error: [JavaPackage org.sikuli.script.ScriptRunner] is not a function, it is object.

    Maybe somone can help me? I really want to use sahi but need a gui automation too.

    thanks
    Christoph
Sign In or Register to comment.