Extending the script bindings for Java

Extending the script bindings for Java

Testing with the Squish Qt edition, one can add (from the Squish documentation)
var num = QInputDialog.getInteger( "Require User Input", "How many pages have been printed?" );
in the scripts. So testers can fill-in data that the program can’t see.
Unfortunately testing with the Java edition and using the SWT toolkit, there is no such a ready-to-use dialog for this.

However, the Java edition of Squish is easily extended because classes are dynamically wrapped at application startup. We must therefor write an input dialog ourselves, tell Squish about it and call it from our test scripts.

So first write a simple input dialog

package com.froglogic;
import org.eclipse.swt.widgets.*;

public class Input
{
public static String getMessage( Shell parent, String question ) {
...
}
}

The implementation is in the input.zip file, together with a jar file containing the compiled classes of the sources.

Now we must add the .jar to our classpath. (Btw. Squish 3.2.1 will now finally have an editbox for setting the classpath and main class in the testsuite settings dialog.)

Next we must tell Squish that we want to wrap the new classes. So we must carry out the task “Wrapping custom Java™ classes” from the Squish User Guide.
Basically write a .ini file, like:

[general] AutClasses="com.froglogic.Input"

and register this by squishserver:

squishserver --config setConfig MyAUT /path/extras.ini

Finally use the code in our scripts. I’ve put it here just after the script is waiting for a CCombo widget:

var shell = findObject(":Buttons_org.eclipse.swt.custom.CCombo").shell;
test.log(com_froglogic_Input.getMessage(shell, "What's your name?"));

In the code above the return value is directly printed in the test results.
Note that the property CCombo.shell is a synthetic property, I’ve could have used CCombo.getShell() as well.

Summarizing, it requires some work but it is not very hard and without modifying any code of the application we’re testing.

2 Comments

  1. Leo 11 years ago

    Hello,

    My Environment:
    – WinXP SP3
    – Squish for QT Version: 3.4.3

    Problem:
    i could’t call a java Method from *.jar (archive) file (I use JS as Test Suite language).

    Used Files:
    -java_archive.jar
    -server.ini

    Server.ini file:
    [General]
    AutClasses=”java_archive/MyClassName”
    AutClassPath=”java_archive.jar”

    register this by squishserver
    >>squishserver –config setConfig MyClassName ./server.ini

    then:
    squishserver –config setJavaVM “C:Program FilesJavajre6clientjvm.dll”
    squishserver –config setConfig MyClassName ..myappsxyzjava_archive.jar

    In my Test Suite:
    If i declare a new object in JavaScript with:
    function main(){
    var MyNewObject = new MyClassName();
    }

    i become exception “Can’t find variable” MyClassName.

    Please help me.

  2. koos 11 years ago

    > AutClasses=�java_archive/MyClassName�

    This doesn’t look correct. You should only list class names. In the sever log you should see that an extra class gets registered and if you don’t see an exception, then Squish knows about this class

Leave a reply

Your email address will not be published. Required fields are marked *

*