Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space FUNCTDEV and version SOAVIRT_9.10.3_CTP_3.1.0

...

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 are using Java for scripting and want to use SOAtest recompile modified Java files, see Using Eclipse Java Projects in SOAtest for details on how to set your environment on scripting.

...

...

If you are using Java for scripting and want to use Virtualize to recompile modified Java files, see Using Eclipse Java Projects in Virtualize for details on how to set your environment on scripting.

Specifying the Script

To define a script from SOAtest or Virtualize GUI controls that provide a scripting option:

...

If your Java code uses the Extensibility API and you want to compile the code within the

...

...

SOAtest

...

SOAtest

or

Virtualize

environment,

...

or

...

Virtualize

environment, use the Java Project wizard. This wizard will create a new Eclipse Java project that has access to the Extensibility API. For details, see 

...

Using Eclipse Java Projects in SOAtest

see 

Using Eclipse Java Projects in SOAtest

or

Using Eclipse Java Projects in Virtualizefor details.

If you want to compile the code outside of the

SOAtest

or

...

or

...

Using Eclipse Java Projects in Virtualize

for details.

If you want to compile the code outside of the

...

SOAtest

...

or

...

Virtualize

 environment, you will need the following jar files:

...

These jar files are available at

...

<SOAtest Installation Directory>\plugins\com.parasoft.xtest.libs.web_<SOAtest version>\root

...

  

...

and

...

<Virtualize Installation Directory>\plugins\com.parasoft.xtest.libs.web_<Virtualize version>\root


Info
iconfalse
titleBuilding with Maven?

If you’re building your Java project with Apache Maven,  you can add the following to your project's pom.xml:

Code Block
<project>
  ...
  <dependencies>
    <dependency>
		<groupId>com.parasoft.soavirt</groupId>
		<artifactId>com.parasoft.api</artifactId>
		<version>9.9.0</version>  <!-- should match product version -->
    </dependency>   
  </dependencies>   ...
<repositories>
    <repository>
		<id>ParasoftMavenPublic</id>
		<name>Parasoft Public Repository</name>
		<url>http://build.parasoft.com/maven/</url>
    </repository>
  </repositories>
  ...
</project>


...


0A010204015CF6008A11EEF43AC91334 0A010204015A9054C886C0AC137B8C01
Info
titleSOAtest Example and Notes

For example, let's say you have a test that looks similar to that in the following image:

The name of the table data source is Data Source Name. Not pictured are the following important facts:

  • The table Data Source Name has a column labeled Column Name.
  • The XML Data Bank contains a column labeled Test 1: Result.
  • The XML Data Bank and Writable Data Source belong to a data source labeled Generated Data Source.

In order to make one of these data sources available to your script, select the data source in the top of the Extension tool’s configuration panel, then check Use Data Source

Notes

When opening older files (created prior to SOAtest 6.1), note that Browser Data Bank Tool column names are automatically transformed to "Extracted:xyz", where "xyz" was the column name that you specified. This provides support for legacy scripts that reference "Extracted:xyz". You can change the column name in the Browser Data Bank to just "xyz" or "abc."

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".

Conditional Content
Product: (SOAVirt, SOAtest)Product: (SOAVirt, SOAtest)sv-attr:0A010204015A9054C88481D043445E2F


Extensibility Examples for SOAtest

Accessing, Manipulating, and Storing Data

One typical usage of an Extension tool is accessing data from a data source, manipulating it, and then storing it dynamically in an XML Data Bank or Writable Data Source. In this scripting example, we define a method called getKeywords in which we are accessing data from a data source titled “Books” with a data source column titled “keywords”. We then return an XML representation of this string so that we can send the output from this script to an XML Data Bank. 

Note that additional configuration is required to access Data Sources from an Extension Tool. See the previous section for details.

In these samples, the methods take two arguments as input:

  • Object input: Represents input passed to the method from a previous test case. For example, if we chain an Extension tool to the SOAP Response of a SOAP Client tool, the input Object will be a string representing the SOAP Response.
  • ExtensionToolContext context: The method getValue gives access to Data Sources from an Extension Tool. This method can be used along with other methods exposed by the Context interface for sharing Data Source values between scripts and other tools.

Jython Example 1

Code Block
from soaptest.api import *

def getKeywords(input, context):
   title = context.getValue("Books", "keywords")
    return SOAPUtil.getXMLFromString([title])

Jython Example 2



  1. Code Block
    def methodName():
      # code



  2. Code Block
    def methodName(input):
      # code
  3. Code Block
    def methodName(input, context):
      # code


In the above examples, "input" refers to either:


  • The data passed from the output of the tool to which this Extension Tool is chained. For example, the Response SOAP Envelope of a SOAP Client OR
  • The data that appears in the Input area of the Extension Tool.  This is found at the bottom of the Extension Tool interface.

In the vast majority of cases, you can assume that the value passed to the "input" variable will be a primitive Jython string.

Generally, the "context" variable is determined dynamically by SOAtest and will be an instance of the Context class, found in the Extensibility API. In the case of an Extension Tool, the context will be an instance of ExtensionToolContext for this specific tool (as compared to other Extension Tools in your test suite).

JavaScript Example

Code Block
var SOAPUtil = Packages.soaptest.api.SOAPUtil

function getKeywords(input, context) {
   title = context.getValue("Books", "keywords")
   return SOAPUtil.getXMLFromString([title])
}

Java Example

Code Block
package examples;

import soaptest.api.*;
import com.parasoft.api.*;

public class Keyword {

    public Object getKeywords(Object input, ExtensionToolContext context)
            throws com.parasoft.data.DataSourceException {
        String[] titles = new String[1];
        titles[0] = context.getValue("Books", "keywords");
        return SOAPUtil.getXMLFromString(titles);
   }
}
Note
titleNote

Java code such as this example must be compiled outside of SOAtest. You will need to make sure that you have the SOAtest jar files on the Classpath for your Java compiler in order to access packages from the SOAtest Extensibility API, in particularwebking.jar and com.parasoft.api.jar.

For this Keyword example, the source code and compiled class file is available at SOAtestInstallRoot/build/examples. The SOAtestInstallRoot/build folder is already on the Classpath for SOAtest so you can use the Keyword example in a test suite. You could also put your own Java class files here to use the Java class in SOAtest. An alternative to using the SOAtestInstallRoot/build folder is to add the class file using the System Properties tab in the Preferences.

Reading File Contents into a String

To read the contents of a file into a String using a Jython script, you can use the following method:

Code Block
from java.lang import *
from java.io import *
from soaptest.api import *

def getContents(input, context):
  contents = StringBuffer()
  reader = BufferedReader(FileReader(File("c:\Documents and Settings\jhendrick\Desktop\test.txt")))
  line = String()
  while line != None:
    line = reader.readLine()
    if line != None:
       contents.append(line)
    contents.append(System.getProperty("line.separator"))
reader.close()
return contents.toString()

Defining a Custom Assertion

Here is a sample Java script that can be used as a custom assertion in the XML Assertor tool. This script gets a value from a data source, prints that value along with the response value, and returns a boolean value based on whether or not the response value contains the data source value.

Code Block
package examples;

import com.parasoft.api.*;

public class Comparison {

//Compares a value from a database data source to a value returned in a SOAP response
public boolean compareToDatabase(Object input, ScriptingContext context)
throws com.parasoft.data.DataSourceException {

//Gets values from database data source named "Books"
String value = context.getValue("Books", "Book");

//Prints database data source values along with SOAP response values in a message to the console
Application.showMessage("Value from database is " + value + ".\nValue from SOAP response is " +
input.toString() + ".");

//Verifies that the SOAP response value contains the database data source value
return input.toString().contains(value);
}
}

String Operations Using Extracted Values

Here is an example of a Jython script that extracts values from various sources (data bank, test suite variable, and environment variable) for use with string operations such as concatenation using the '+' operator...

Code Block
from soaptest.api import *
from com.parasoft.api import *

# Gets a value from a data bank (line 10) or test suite variable (line 11),
# appends an environment variable value to the front of that value,
# and returns the modified value. Be sure to comment out line 11
# when using line 10 and vice versa.

def getModifiedString(context):
#value = context.getValue("Generated Data Source", "columnName")
value = context.getValue("testSuiteVariableName")

environmentVariableValue = context.getEnvironmentVariableValue("environmentVariableName")

modifiedString = environmentVariableValue + value

return modifiedString

This example is for a fairly specific use case but nonetheless uses some common methods from the SOAtest extensibility API.

Accessing a Window or Frame’s Document

These examples are intended for use when chaining an Extension tool to a Browser Playback Tool, used in a Web Scenario.

getDocument is overloaded as follows:

Code Block
getDocument(); // gets the document for the main window
getDocument(String windowName); // gets the document for the window with the specified window name
getDocument(String windowName, String frameName); // gets the document for a frame within a
window

For example, the following code gets the content of a frame titled "mainPane" in the main window. It then uses the document to get the title text for the selected frame.

Code Block
var Application = Packages.com.parasoft.api.Application;
var WebBrowserUtil = Packages.webking.api.browser2.WebBrowserUtil;

function getFrameDocument(input, context) {
   var document = input.getDocument("", "mainPane");
   var titles = document.getElementsByTagName("title");
   var title = titles.item(0);
   var value = WebBrowserUtil.getTrimmedText(title);
   Application.showMessage("title: " + value);
   return value;
}

Language-Specific Tips

...