Sahi Pro - Sahi Applet Support (Beta)

Introduction

Sahi Pro V4.5 and higher versions provide support for automation of applets.

For automating your applets you need to configure Sahi for applet support.

  1. Open /config/sahi.properties
  2. Set the below statement to true and save this file
    applet_support.enabled=true
  3. Open /userdata/config/substitutions.xml
  4. Add rule as given below.
  5. When applet is bundled in a jar

    <rule>
    	<name>change_user_jars</name>
    	<urlPattern>.*</urlPattern>
    	<isRegExp>false</isRegExp>
    	<find><![CDATA[user_jar.jar]]></find>
    	<replace><![CDATA[user_jar.jar,sahiapplet.jar]]></replace>
    </rule>
    Replace user_jar.jar with the jar that your applet uses.

    When applet is NOT bundled in a jar, using applet tag

    In case your applet does not use a jar and you are using <applet> tag for inserting your applet in HTML page. Use
    <rule>
    	<name>change_user_jars</name>
    	<urlPattern>.*</urlPattern>
    	<isRegExp>false</isRegExp>
    	<find><![CDATA[<applet]]</find>
    	<replace><![CDATA[<applet archive='sahiapplet.jar']]></replace>
    </rule>
    In your HTML file, if your <applet tag is in upper case, use <APPLET instead of <applet above (in both find and replace nodes).

    When applet is NOT bundled in a jar, using object tag

    In case your applet does not use a jar and you are using <object> tag for inserting your applet in HTML page. Use
    <rule>
    	<name>change_user_jars</name>
    	<urlPattern>.*</urlPattern>
    	<isRegExp>false</isRegExp>
    	<find><![CDATA[</object>]]</find>
    	<replace><![CDATA[<param name='archive' value='sahiapplet.jar'/></object>]]></replace>
    </rule>
    In your HTML file, if your </object> is in upper case, use </OBJECT> instead of </object> above (in both 'find' and 'replace' nodes).

  6. Save this file.
  7. Restart Sahi.

Automating Oracle Forms

For automating Oracle Forms following steps need to be done

  1. Open "Configure Sahi" page by clicking on "configure" link on Sahi's Dashboard.
  2. Click on “download_contenttypes.txt”.
  3. Remove the following line from download_contenttypes.txt.
  4. application/octet-stream
  5. Click Save.
  6. Restart Sahi.

Recording an Applet

From the Sahi Dashboard, open any browser and navigate to the page containing your applet.
Press ALT and double click on the document window of the page which you want to record (outside applet area). Sahi's Controller window will popup. You can now start recording. As with normal Sahi, you can use CTRL-Hover to identify various elements on the applet.

NOTE: Sahi currently automates only Java Swing based applets

Applet APIs

Applets APIs are different from the normal JavaScript APIs. All elements are prefixed with

_a("appletId").
or
_applet("appletId").
followed by the component type and component id.

Example:
_a("SampleApplet").jbutton("Test Button")
or
_applet("SampleApplet").jbutton("Test Button")
_a and _applet API's can be used interchangebly.

Applet also supports near, inside and under APIs.

Example:
_a("SampleApplet").jcombobox("").near(_a("SampleApplet").jlabel("Mouth"));

_highlight(_a("SampleApplet").jcombobox("").under(_a("SampleApplet").jlabel("Mouth")));

_setSelected(_a("SwingSet2Applet").jcombobox(3).near(_a("SampleApplet").jlabel("Mouth")),"Larry");

_click(_a("SwingSet2Applet").jbutton("sun_small.gif"));
Some more detail on Applet APIs

Trouble Shooting

Java security error while loading applets with Sahi

Following security error may occur while automating applets with Sahi.
Solution
  1. Open Java Control Panel.
  2. Where is Java Control Panel in Windows
    Where is Java Control Panel in Mac
  3. Select "Enable - hide warning and run with protections" Security verification option as shown in below image.

Page hangs or Sahi does not recognize any element

While automating applets using Sahi make sure that java uses browser's proxy setting.
This can be configured in Java Control Panel as shown in below images.

Sample applet

A sample applet is available at http://sahi.co.in/demo/applet/simple.htm