...
Jython Version
The Jython 2.57.2 version that ships with SOAtest and Virtualize does Virtualize does not include some of the standard Jython libraries, such as the os module. If you are used to using these modules and would like to access to them in SOAtest or Virtualize, you can point SOAtest or Virtualize to an external Jython installation as follows:
- Install Jython in a location of your choice; we will refer to this location as
<Jython Install Directory>
. - Open SOAtest or Virtualize.
- Choose Parasoft> Preferences.
- Select Scripting.
- In the Jython Home field, enter
<Jython Install Directory>
. - Restart SOAtest or Virtualize.
Jython Syntax Coloring
Jython syntax coloring for the Extension tool is enabled using the PyDev plugin (http://www.pydev.org/). This plugin must have its jython interpreter configured for advanced functionality such as code auto completion. For more details, see http://www.pydev.org/manual_101_interpreter.html.
Accessing Data Sources from Scripts
If you use SOAtest, you can make a data source available to a script by selecting the data source in the top of the tool’s configuration panel, and then enabling the Use Data Source option.
Within other methods in your script, or within any method in the script if you use Virtualize, store a value from the data source into a variable "x" with the line:
x = context.getValue("Data Source Name", "Column Name")
For more information on scripting, see the documentation for the Extension framework API. Choose Parasoft> Help, then look for the book titled "Parasoft SOAtest Extensibility API" (for SOAtest) or "Parasoft Virtualize Extensibility API" (for Virtualize).
...
Anchor | ||||
---|---|---|---|---|
|
- When you specify a Java class in any of the scripting Class fields, you must specify a compiled class that is on your classpath. You can click the Modify Classpath link then specify it in the displayed Preferences page.
- If the class you are using is part of a package, you need to specify the complete package name as well as the class name (for example,
java.lang.String
) - If one of your scripts uses a class that has been changed and recompiled within SOAtest or Virtualize, SOAtest or Virtualize will reload the class and use most recent class for object construction when you invoke the method. SOAtest and Virtualize do not function this way for any class whose package name starts with one of the following prefixes:
- sun.
- com.sun.
- org.omg.
- javax.
- sunw.
- java.
- com.parasoft.
- webtool.
- wizard.
- To manually prompt SOAtest or Virtualize to reload a class that has been modified and recompiled, click Reload Class.
Anchor | ||||
---|---|---|---|---|
|
- The "legacy" SOAtest or Virtualize JavaScript emulation is based on FESI. We recommend using an alternative scripting engine such as Oracle Nashorn. For details, see:
- You can call Java classes and methods that are on your classpath from inside JavaScript methods, or JavaScript tools.
For example, if you’re using Nashorn and you want to call Application.report() (from the SOAtest or Virtualize Extensibility API) from inside JavaScript, you need to need to reference it as
Java.type("com.parasoft.api.Application"): var Application = Java.type("com.parasoft.api.Application") Application.report("Message", "Result Window")
If you decide to use the legacy engine (not recommended) and you want to call Application.report() (from the SOAtest or Virtualize Extensibility API) from inside JavaScript, you need to need to reference it as
Packages.com.parasoft.api.Application.report()
. You could also reference it by prepending the name withPackages
and the name of the package where the Java class lives as followsvar Application = Packages.com.parasoft.api.Application Application.report("Message", "Result Window")
- To check that the specified script is legal and runnable (or to add method entries to the Method box), right-click the File or Text text field (click whichever one you used to specify your script), then choose Evaluate from the shortcut menu.
Anchor | ||||
---|---|---|---|---|
|
For details on Jython (an implementation of Jython that is integrated with Java), including information on how to write Jython and also how to invoke Java classes from inside Jython, visit http://www.jython.org. Note that SOAtest and Virtualize ship with Jython 2.57.2.
- If you are using Jython scripts, you might need to specify your jython.home and jython.path variables in the Scripting tab of the Preferences panel. Both variables are used to locate Jython modules, and Jython code that does not import any Jython modules can use the Jython scripting support without setting either variable. jython.home specifies the Jython installation directory. jython.path is used to add to your path modules that are not in your jython.home/Lib directory. Multiple paths can be listed in jython.path, while jython.home must be a single directory. If you set the jython.home and jython.path variables, you need to restart SOAtest or Virtualize before the changes will take effect.
- If you decide to import optional modules and you do not have Jython 2.57.2 installed, you will need to download and install Jython 2.57.2 from jython.org. For Linux, use java -jar jython_installer-2.57.2.jar. For Windows, double-click jython_installer-2.57.2.jar.
- To check that the specified script is legal and runnable (or to add method entries to the Method box), right-click the File or Text text field (click whichever one you used to specify your script), then choose Evaluate from the shortcut menu.
Anchor | ||||
---|---|---|---|---|
|
Here is a sample Groovy script:
Code Block |
---|
import com.parasoft.api.*; boolean customAssertion(Object input, ScriptingContext context) { String value = context.getValue("Books", "title"); Application.showMessage("Value from data source is " + value) Application.showMessage("Value from SOAP response is " + input.toString()) return input.toString().contains(value); } |
Anchor | ||||
---|---|---|---|---|
|
You can configure SOAtest and Virtualize to recognize any scripting engines that implement the JSR 223 "Scripting for the Java Platform" specification. Oracle Nashorn is available by default; others can be added.
Anchor | ||||
---|---|---|---|---|
|
The Oracle Nashorn ECMAScript engine is available by default because it is included with Java. Here is a sample Oracle Nashorn script:
Code Block |
---|
var Application = Java.type("com.parasoft.api.Application") function customAssertion(input, context) { value = context.getValue("Books", "title"); Application.showMessage("Value from data source is " + value) Application.showMessage("Value from SOAP response is " + input.toString()) return input.toString().contains(value); } |
Mozilla Rhino JavaScript
Mozilla Rhino is the original ECMAScript engine included with the Java runtime. It is the predecessor to Oracle Nashorn, which has replaced Mozilla Rhino as of Java 8. SOAtest and Virtualize versions prior to 9.10 shipped with Java 7, which included Mozilla Rhino. Scripts saved in earlier versions of SOAtest and Virtualizewith the Mozilla Rhino engine will now run in the new Oracle Nashorn with Mozilla compatibility extensions loaded. The compatibility extensions are provided by Oracle as part of Nashorn and are intended for such purposes. By loading the compatibility extensions, scripts will continue to function as before, but with significantly improved runtime performance.
Scripts originally saved using Mozilla Rhino will now show JavaScript (Mozilla Rhino compatible) in the Language selection box, indicating that the script will run with Nashorn but with the Mozilla compatibility extensions. If you create a new script, the JavaScript (Mozilla Rhino compatible) option will not be available; you will see only JavaScript (Oracle Nashorn), which does not load the Mozilla compatibility extensions. If you need to load the compatibility extensions in this case, simply add
load("nashorn:mozilla_compat.js")
; to the top of your script. For more detail, see https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide#RhinoMigrationGuide-Compatibility-script.
Since Oracle Nashorn is the replacement for Mozilla Rhino, use of Mozilla Rhino is not recommended. However, Mozilla Rhino can be made available to SOAtest and Virtualize in the same manner as any other JSR 223 compatible script engine (see Other JSR 223 Scripting Languages). Mozilla Rhino includes two jars which must be added to the classpath in the Preferences panel (under System Properties): Rhino js.jar and js-engine.jar. For details, see https://wiki.openjdk.java.net/display/Nashorn/Using+Rhino+JSR-223+engine+with+JDK8.
Pre-built jars can also be found on maven central:
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.mozilla%22%20a%3A%22rhino%22
- http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rhino-js-engine%22
Anchor | ||||
---|---|---|---|---|
|
To make another JSR 223 scripting language available, add the appropriate engine’s scripting engine to the classpath (go to the Parasoft Preferences panel and add it under the System Properties area).
For example, you could add the JRuby scripting engine, which implements JSR 223. To do this, you would download JRuby from http://jruby.org/ then add jruby.jar to the classpath.
Here is a sample JRuby script:
Code Block |
---|
require 'java' Application = com.parasoft.api.Application def doSomething(input, context) Application.showMessage("hello world") end |
Additional Extensibility Resources
For details on how to create and apply an Extension tool that executes a custom script you have written, see Extension Tool for Custom Scripting.