public abstract class AbstractJavaTestScript extends Object implements TestWrapper, JavaTestScript
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
WRAPPER_TYPE_BLOCK, WRAPPER_TYPE_INCLUDE, WRAPPER_TYPE_JAVA, WRAPPER_TYPE_PROCEDURE, WRAPPER_TYPE_RUN, WRAPPER_TYPE_SCRIPT, WRAPPER_TYPE_UNKNOWN
Constructor and Description |
---|
AbstractJavaTestScript() |
Modifier and Type | Method and Description |
---|---|
int |
callByName(String command,
String... parameters)
Generic method allowing to call a command by name.
|
ScriptingContext |
getContext()
Get context associated with this test script.
|
StyledDocument |
getDocument()
Get the document associated with this wrapper.
|
int |
getLineNumber(ScriptingContext ctx)
Get number of the currently executed command line.
|
String |
getOutputDir()
Get the output path.It is the directory where the script will store any
file outputs such as screen shots, logs and reports.
|
TestWrapper |
getParentWrapper()
Get the parent wrapper.
|
File |
getScriptFile()
Get the script file.
|
ScriptManager |
getScriptManager()
Get script manager associated with this test script and its interpret.
|
String |
getTemplateDir()
Get the template path.
|
String |
getTestSource() |
Object |
getVariable(String name)
Convenience method to get a context variable value.
|
Boolean |
getVariableAsBoolean(String name)
Convenience method to get a context variable value and convert it to a Boolean.
|
Color |
getVariableAsColor(String name)
Convenience method to get a context variable value and convert it to a Color.
|
Float |
getVariableAsFloat(String name)
Convenience method to get a context variable value and convert it to Float number.
|
Integer |
getVariableAsInt(String name)
Convenience method to get a context variable value and convert it to Integer number.
|
Point |
getVariableAsPoint(String name)
Convenience method to get a context variable value and convert it to a Point.
|
Rectangle |
getVariableAsRectangle(String name)
Convenience method to get a context variable value and convert it to a Rectangle.
|
String |
getVariableAsString(String name)
Convenience method to get a context variable value and convert it to String.
|
int |
getWrapperType() |
void |
importVariables()
This method is intended to support conversion of TPR test scripts
into Java.
|
boolean |
isDebug()
Indicate whether the debug mode is on.
|
boolean |
isPaused()
Find out whether execution of the script is paused.
|
void |
mouseEvent(MouseEvent event)
Allows to send low level mouse event (a MouseEvent instance) to the
underlying remote desktop client.
|
void |
resume()
Resume execution (set the pause indicator to false).
|
int |
runScriptCommand(String commandName,
List params,
Map values)
Generic method to execute a scripting language command.
|
void |
setContext(ScriptingContext context)
Set the context.
|
void |
setDebug(boolean debug)
Set the debug mode flag.
|
void |
setDocument(StyledDocument document)
Set the document associated with this wrapper.
|
void |
setInterpret(TestScriptInterpret interpret)
Set the test script interpret.
|
void |
setOutputDir(String dir)
Set the output path.
|
void |
setTemplateDir(String dir)
Set the template path.
|
void |
setTestSource(String testSource) |
void |
setVariable(String name,
Object value)
Convenience method to set a context variable value from the test script body
(from inside the
JavaTestScript.test() method). |
String |
toString() |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
test
public void resume()
public boolean isPaused()
public void mouseEvent(MouseEvent event) throws IOException
event
- a mouse event.IOException
- on an I/O error or when the client is not connected.public final int runScriptCommand(String commandName, List params, Map values) throws IllegalArgumentException, IOException, StopRequestException
commandName
- command name. If the command is not known (there's no
command handler registered for the name in the map maintained by the script
managers) the method throws an IllegalArgumentException.params
- command parameters in the correct order (if applicable).values
- map of parameters and their values.IllegalArgumentException
- on unknown command name.IOException
- when the exception is thrown by the command
handler. This in general applies just to commands which participate
in the client-server communication. Other command declare the exception
but never throw it.StopRequestException
- when a request to
stop execution of the script has been registered.public int callByName(String command, String... parameters) throws IOException
Generic method allowing to call a command by name. It is mainly intended
to provide a nicer (and shorter) interface to command calls than the
similar legacy method of runScriptCommand(java.lang.String, java.util.List, java.util.Map)
which required coding of multiple lines to create the necessary parameter
list and map.
The method may be also used to call commands delivered by
third party subjects and integrated with the tool through the plugin interface.
See the CommandHandler
and AbstractCommandHandler
classes
for more details on this mechanism.
Last but not least this method allows to conversion of scripting language code where the command name is specified by a variable.
The method allows to search the command by name in the internal command
table and execute it with parameters passed in through the parameters
array. Each element of the parameter array must contain either a valid argument
or a "parameter=value" pair exactly as it is specified in the legacy scripting
language. If the parameter value in a "parameter=value" pair contains a
space, it must be properly enclosed with double quotes. For example, to
call an equivalent of the command
Screenshot desktop.jpg desc="My desktop"
runCommand("screenshot", "desktop.jpg", "desc=\"My desktop\"");
command
- command name according to the language specification and/or
returned by the CommandHandler.getCommandNames()
method. It is not case sensitive.parameters
- array of arguments and/or parameters in form of "parameter=value" pairs.IOException
- on I/O error (applies only to commands which communicate with the
desktop client and/or work with local files and/or communicate with other network services
(such as SendMail).public void importVariables()
public ScriptingContext getContext()
public void setContext(ScriptingContext context)
setContext
in interface JavaTestScript
context
- a context instance.public boolean isDebug()
public void setDebug(boolean debug)
debug
- the debug to setpublic String getTestSource()
getTestSource
in interface TestWrapper
public int getWrapperType()
getWrapperType
in interface TestWrapper
public int getLineNumber(ScriptingContext ctx)
getLineNumber
in interface TestWrapper
ctx
- context instance.public TestWrapper getParentWrapper()
getParentWrapper
in interface TestWrapper
public File getScriptFile()
getScriptFile
in interface TestWrapper
public void setTestSource(String testSource)
testSource
- the testSource to setpublic StyledDocument getDocument()
getDocument
in interface TestWrapper
public void setDocument(StyledDocument document)
setDocument
in interface TestWrapper
document
- a new document for this wrapper.public ScriptManager getScriptManager()
public void setInterpret(TestScriptInterpret interpret)
setInterpret
in interface JavaTestScript
interpret
- interpret instance able to handle Java source code.public Object getVariable(String name)
getContext().getVariable()
.name
- variable name.public String getVariableAsString(String name)
name
- variable name.public Float getVariableAsFloat(String name)
Float.parseFloat(getContext().getVariable().toString))
.
As the method doesn't catch any exceptions, it may throw a NumberFormatException
if the variable is not a number.name
- variable name.public Integer getVariableAsInt(String name)
name
- variable name.public Boolean getVariableAsBoolean(String name)
ScriptingContext.getVariableAsBoolean(java.lang.String)
.
As the method relies on the Boolean.parseBoolean(java.lang.String)
method it returns
false when the value is not a valid boolean instead of throwing any exception.name
- variable name.public Point getVariableAsPoint(String name)
ScriptingContext.getVariableAsPoint(java.lang.String)
.name
- variable name.IllegalArgumentException
- if the variable value is not a point.public Rectangle getVariableAsRectangle(String name)
ScriptingContext.getVariableAsRectangle(java.lang.String)
.name
- variable name.IllegalArgumentException
- if the variable value is not a rectangle.public Color getVariableAsColor(String name)
ScriptingContext.getVariableAsColor(java.lang.String)
.name
- variable name.IllegalArgumentException
- if the variable value is not a valid color.public void setTemplateDir(String dir)
ScriptingContext.setTemplateDir(java.io.File)
method of the associated script context
.dir
- a directory.NullPointerException
- when the method is called before the script execution from
outside of the JavaTestScript.test()
method (when no context has been associated with the test script).public void setOutputDir(String dir)
ScriptingContext.setOutputDir(java.io.File)
method of the associated script context
.dir
- a directory.NullPointerException
- when the method is called before the script execution from
outside of the JavaTestScript.test()
method (when no context has been associated with the test script).public String getTemplateDir()
ScriptingContext.getTemplateDir()
method of the associated script context
.NullPointerException
- when the method is called before the script execution from
outside of the JavaTestScript.test()
method (when no context has been associated with the test script).public String getOutputDir()
ScriptingContext.getOutputDir()
method of the associated
script context
.NullPointerException
- when the method is called before the script
execution from outside of the JavaTestScript.test()
method (when no context has
been associated with the test script).public void setVariable(String name, Object value)
JavaTestScript.test()
method). The method just calls
the ScriptingContext.setVariable(java.lang.String, java.lang.Object)
on the test script context (getContext()
.name
- variable name.value
- the variable value.NullPointerException
- when the method is called before the script execution from
outside of the JavaTestScript.test()
method (when no context has been associated with the test script).