Test Script Services Reference |
Use the utility methods to perform actions common to many test scripts.
Commonly used with TestManager and QualityArchitect.
The following table lists the utility methods. They are static methods of class TSSUtility
.
applicationPid()
Gets the process ID of an application.
applicationStart()
Starts an application.
applicationWait()
Waits for an application to terminate.
delay()
Delays the specified number of milliseconds.
errorDetail()
Retrieves error information about a failure.
getComputerConfiguration
AttributeList() Gets the list of computer configuration attributes and their values.
getComputerConfiguration
AttributeValue() Gets the value of a computer configuration attribute.
getPath()
Gets a pathname.
getScriptOption()
Gets the value of a script playback option.
getTestCaseConfiguration
Attribute() Gets the value of a test case configuration attribute.
getTestCaseConfiguration
AttributeList() Gets the list of test case configuration attributes and their values.
getTestCaseConfigurationName()
Gets the name of the configuration (if any) associated with the current test case.
getTestCaseName()
Gets the name of the test case in use.
getTestToolOption()
Gets a test case tool option.
javaApplicationStart()
Starts a Java application.
negExp()
Gets the next negative exponentially distributed random number with the specified mean.
rand()
Gets the next random number.
seedRand()
Seeds the random number generator.
stdErrPrint()
Prints a message to the virtual tester's error file.
stdOutPrint()
Prints a message to the virtual tester's output file.
uniform()
Gets the next uniformly distributed random number in the specified range.
uniqueString()
Returns a unique text string.
Gets the process ID of an application.
intapplicationPid
(intappHandle
)
appHandle
The ID of the application whose PID you want to get. Returned by
applicationStart()
or javaApplicationStart()
.
On success, this method returns the system process ID of the specified application. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block .
This method works for applications started by applicationStart() or javaApplicationStart().
A successful invocation does not imply that the application whose PID is returned is still alive nor guarantee that the application is still running under this PID.
This example returns the PID of application myApp
.
int myAppHandle = TSSUtility.applicationStart("myApp", "d:\myDir" ,0);
int myAppPID = TSSUtility.applicationPid
(myAppHandle);
applicationStart(), applicationWait(), javaApplicationStart()
intapplicationStart
(StringappHandle
, StringworkingDir
, intflags
) intapplicationStart
(StringappHandle
)
On success, this method returns a handle for the started application. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block.
This example starts application myApp
.
int myAppHandle = TSSUtility.applicationStart
("myApp", "d:\myDir" ,0);
applicationPid(), applicationWait(), javaApplicationStart()
Waits for an application to terminate.
intapplicationWait
(intapp,
TSSIntegerexitStatus
, inttimeout
) intapplicationWait
(intapp
)
app
The application that you are waiting for. Returned by
applicationStart()
or javaApplicationStart()
.
exitStatus
OUTPUT. If not null, the exit status of
app
. See TSSInteger for the implementation of this argument's type.
timeout
The number of milliseconds to wait for
app
to terminate or 0 to return immediately.
On success, this method returns TSS_OK.
This method may throw an exception with one of the following values:
TSS_FAIL
. The application was still running when the time-out expired.
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_SYSERROR
. The system returned an error: call TSSException.getErrorCode() .
TSS_NOTFOUND
. The process indicated by app
was not found. It may have terminated before this call or app
may be an invalid handle.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
This method works for applications started by applicationStart() or javaApplicationStart().
If app
is still running at the time this call returns, exitStatus
contains NULL. If app
has terminated at the time of return, exitStatus
contains its termination code.
This example waits 600 milliseconds for application myApp
to terminate.
TSSInteger termStatus;
int myAppHandle = TSSUtility.applicationStart("myApp");
int retval = TSSUtility.applicationWait
(myAppHandle, termStatus, 600);
applicationPid(), applicationStart(), javaApplicationStart()
Delays script execution for the specified number of milliseconds.
voiddelay
(intmsecs
)
msecs
The number of milliseconds to delay script execution.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
The delay is scaled as indicated by the contents of the EVAR_Delay_dly_scale
environment variable. The accuracy of the time delayed is subject to operating system limitations.
This example delays execution for 10 milliseconds.
TSSUtility.delay
(10);
Retrieves error information about a failure.
interrorDetail
(StringBuffererrorText
)
errorText
OUTPUT. Returned explanatory error message about the previous TSS call, or an empty string ("") if the previous TSS call did not fail.
This method returns TSS_OK
if the previous call succeeded. If the previous call failed, TSSUtility.errorDetail() returns one of the error codes listed below and corresponding errorText
.
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
This method is called internally by Java methods, which throw TSSException
on error. Get the error code by calling TSSException.getErrorCode()
. You can use TSSUtility.errorDetail()
, but there is no need to do so. For implementation details, see TSSException.
This example opens a datapool and, if there is an error, displays the associated error message text.
TSSDatapool dp = new TSSDatapool();
dp.open ("custdata");
StringBuffer errorText;
boolean fetchRet = dp.fetch();
if (fetchRet==false)
// fetch failed, get detail
int errorRet = TSSUtility.errorDetail
(errorText);
System.out.print (errorText);
Gets the list of computer configuration attributes and their values.
TSSNamedValue[] getComputerConfigurationAttributeList
()
On success, this method returns an array of computer configuration attribute names and their values. It exits with one of the following results:
TSS_OK.
Success.
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
You create and maintain computer configuration attributes from TestManager. This call returns the current settings.
See TSSNamedValue for the implementation of the return value's data type.
This example returns the current computer configuration attribute list.
TSSNamedValue [] nvLst =
TSSUtility.getComputerConfigurationAttributeList
();
if (nvLst.length == 0) {
// if length is 0 we need to check for error
StringBuffer errStr = new StringBuffer();
int errCod = TSSUtility.errorDetail(errStr);
if (errCod == TSS_OK) {
System.out.println("zero attributes returned");
}
else {
System.err.print("error: string=");
System.err.print(errStr);
System.err.print(" code=");
System.err.println(errCod);
}
}
else {
// if length > 0 then print the first TSSNamedValue\qs members
System.out.println(nvLst[1].name);
System.out.println(nvLst[1].value);
}
getComputerConfigurationAttributeValue()
Gets the value of computer configuration attribute.
StringgetComputerConfigurationAttributeValue
(Stringname
)
name
The
name
of the computer configuration attribute whose value is to be returned.
On success, this method returns a handle for the started application. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block.
This example returns the value of the configuration attribute Operating System
.
String OSVal = TSSUtility.getComputerConfigurationAttributeValue
("Operating System");
getComputerConfigurationAttributeList()
Gets the root path of a test asset.
StringgetPath
(LongpathKey
)
pathKey
Specifies one of these values:
On success, this method returns the root of the currently executing test script or of the files attached to the log. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block.
The root path returned by this method might be the exact location where an asset is stored, but it need not be. For example, in the fully-qualified pathname C:\Datastore\TestScripts
, C:
might be the root path and Datastore\TestScripts
a pathname relative to the root path.
For test scripts run from TestManager, the returned root path is a value in shared memory for the current virtual tester at the time of the call. For test scripts run stand-alone (outside TestManager), the returned root path is a value set by context()
.
This example returns the root path of the source from which the currently executing test script was selected.
String scriptPath = TSSUtility.getPath
(TSS_SOURCE_PATH);
Gets the value of a test script playback option.
String getScriptOption(String optionName
)
optionName
The name of the script option whose value is returned.
On success, this method returns the value of the specified script option, or NULL if the value specified is not used by the execution adapter.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
TestManager users can set the values of test script playback options. These may be options specifically supported by a Test Script Execution Adapter (TSEA), or arbitrarily named user-defined options. The common way to use test script options in a test script is to query an option's value with this call and branch according to its returned value.
This example gets the current value of a hypothetical script option named repeat_count
.
String optVal = TSSUtility.getScriptOption
("repeat_count");
Gets the value of the specified test case configuration attribute.
TSSTestCaseConfigurationAttributegetTestCaseConfigurationAttribute
(Stringname
)
name
Specifies the name of the configuration attribute to be returned.
On success, this method returns the value of the specified test case configuration attribute. It exits with one of the following results:
TSS_OK.
Success.
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
You create and maintain test case configuration attributes from TestManager. This call returns the value of the specified attribute for the current test case.
See TSSTestCaseConfigurationAttribute for the implementation of the return value's data type.
This example returns the value of the configuration attribute Operating System
.
TSSTestCaseConfigurationAttribute OSVal =
TSSUtility.getTestCaseConfigurationAttribute
("Operating System");
getTestCaseConfigurationAttributeList()
Gets the list of test case configuration attributes and their values.
TSSTestCaseConfigurationAttribute
getTestCaseConfigurationAttributeList
()
On success, this method returns an array of test case configuration attribute names, base values, and operators.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
You create and maintain test case configuration attributes from TestManager. This call returns the current settings for the current test case.
See TSSTestCaseConfigurationAttribute for the implementation of the return value's data type.
This example returns the current test case configuration attribute list.
TSSTestCaseConfigurationAttribute [] nvLst =
TSSUtility.getTestCaseConfigurationAttributeList
();
if (nvLst.length == 0) {
// if length is 0 we need to check for error
StringBuffer errStr = new StringBuffer();
int errCod = TSSUtility.errorDetail(errStr);
if (errCod == TSS_OK) {
System.out.println("zero attributes returned");
}
else {
System.err.print("error: string=");
System.err.print(errStr);
System.err.print(" code=");
System.err.println(errCod);
}
}
else {
// if length > 0 then print the first TSSNamedValue\qs members
System.out.println(nvLst[1].name);
System.out.println(nvLst[1].op);
System.out.println(nvLst[1].value);
}
getTestCaseConfigurationAttribute()
Gets the name of the configuration (if any) associated with the current test case.
String getTestCaseConfigurationName (void)
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
A test case specifies the pass criteria for something that needs to be tested. A configured test case is one that TestManager can execute and resolve as pass or fail.
This example retrieves the name of a test case configuration.
String tcConfig = TSSUtility.getTestCaseConfigurationName
();
Gets the name of the test case in use.
String getTestCaseName
()
On success, this method returns the name of the current test case.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
Created from TestManager, a test case specifies the pass criteria for something that needs to be tested.
This example stores the name of the test case in use in tcName
.
String tcName = TSSUtility.getTestCaseName
();
Gets the value of a test tool execution option.
String getTestToolOption(String optionName
)
optionName
The name of the test tool execution option whose value is returned.
On success, this method returns the value of the specified test tool execution option. On failure, it returns NULL: call errorDetail() for information.
If you develop adapters for a new test script type that support options, you can use this call to get the value of a specified option.
This example returns the value of an option called persist
.
String optval = TSSUtility.getTestToolOption
("persist");
intjavaApplicationStart
(Stringapp
, StringworkingDir
, StringclassPath
, StringJVM
, StringJVMOptions
) intjavaApplicationStart
(Stringapp
, StringclassPath
) intjavaApplicationStart
(Stringapp
)
On success, this method returns a handle for the started application. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block.
This example starts application myJavaApp
.
int myAppHandle = TSSUtility.javaApplicationStart
("myJavaApp");
applicationPid(), applicationStart(), applicationWait()
Gets the next negative exponentially distributed random number with the specified mean.
intnegExp
(intmean
)
mean
The mean value for the distribution.
This method returns the next negative exponentially distributed random number with the specified mean.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
The behavior of the random number generator routines is affected by the settings of the Seed and Seed Flags options in a TestManager suite. By default, TestManager sets unique seeds for each virtual tester, so that each has a different random number sequence.
This example seeds the generator and gets a random number with a mean of 10.
TSSUtility.seedRand (10)
int next = TSSUtility.negExp
(10);
rand(), seedRand(), uniform()
int rand
()
This method returns the next random number in the range 0 to 32767.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
The behavior of the random number generator routines is affected by the settings of the Seed and Seed Flags options in a TestManager suite. By default, TestManager sets unique seeds for each virtual tester, so that each has a different random number sequence.
This example gets the next random number.
int next = TSSUtility.rand
();
seedRand(), negExp(), uniform()
Seeds the random number generator.
voidSeedRand
(intseed
)
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
The behavior of the random number generator routines is affected by the settings of the Seed and Seed Flags options in a TestManager suite. By default, TestManager sets unique seeds for each virtual tester, so that each has a different random number sequence.
seedRand()
uses the argument seed
as a seed for a new sequence of random numbers to be returned by subsequent calls to the rand() routine. If seedRand()
is then called with the same seed value, the sequence of random numbers is repeated. If rand() is called before any calls are made to seedRand()
, the same sequence is generated as when seedRand()
is first called with a seed value of 1.
This example seeds the random number generator with the number 10:
TSSUtility.seedRand
(10);
rand(), negExp(), uniform()
Prints a message to the virtual tester's error file.
voidstdErrPrint
(Stringmessage
)
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and dos not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
This example prints to the error file the message Login failed.
TSSUtility.stdErrPrint
("Login failed");
Prints a message to the virtual tester's output file.
voidstdOutPrint
(Stringmessage
)
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
This example prints the message Login successful.
TSSUtility.stdOutPrint
("Login successful");
Gets the next uniformly distributed random number.
intuniform
(intlow
, inthigh
)
low
The low end of the range.
high
The high end of the range.
This method returns the next uniformly distributed random number in the specified range, or -1 if there is an error.
This method may throw an exception with one of the following values:
TSS_NOSERVER
. No previous successful call to TSSSession.connect()
.
TSS_ABORT
. Pending abort resulting from a user request to stop a suite run.
If you handle one of these exceptions and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass result for the script.
The behavior of the random number generator routines is affected by the settings of the Seed and Seed Flags options in a TestManager suite. By default, TestManager sets unique seeds for each virtual tester, so that each has a different random number sequence.
This example gets the next uniformly distributed random number between -10 and 10.
int next = TSSUtility.uniform(-10,10);
rand(), seedRand(), negExp()
On success, this method returns a string guaranteed to be unique in the current test script or suite run. On failure, it throws an exception: call TSSException.getErrorCode() in a catch block.
You can use this call to construct the name for a unique asset, such as a test script source file.
This example returns a unique text string.
String str = TSSUtility.uniqueString
();
Rational Test Script Services for Java | Rational Software Corporation |
Copyright (c) 2003, Rational Software Corporation | http://www.rational.com support@rational.com info@rational.com |