public interface TestScriptInterpret extends ScriptedExecutable
Generic test script interface. It describes methods of a test script written in a particular language.
T-Plan Robot Enterprise supports two languages, TPR and Java. The necessary minimum
to add support of a new scripting language you must implement this interface
together with the Plugin
one. The recommended way is to extend the
AbstractTestScriptInterpret
class and implement optional interfaces
to enable GUI support:
Interface | Description |
---|---|
EditorFriendlyInterpret |
Method required to enable GUI tools such as context menus, break points, styled documents with syntax highlighting etc. |
OptimizedInterpret |
Allows to skip lengthy compilation and use cached results if the script code hasn't changed. |
ScriptViewFriendlyInterpret |
Enables to display the script in alternative views such as a graph or a tree. |
RefactoringCapable |
Enables refactoring of resources in the script. For example, if a component image gets moved or renamed the interpret must update all commands that reference it. |
FallbackSupport |
Support of fall back tasks. It allows the interpret to perform something after the script finishes executing, such as for example a clean up or a user defined custom task. |
Configurable ConfigurationChangeListener |
Allows the command to store user preferences and get notified of their changes. |
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_JAVA |
static int |
TYPE_PROPRIETARY |
static int |
TYPE_UNKNOWN |
Modifier and Type | Method and Description |
---|---|
boolean |
compile(ScriptingContext customContext)
Compile source code of the test script.
|
void |
destroy()
Clean up method.
|
int |
execute(ScriptingContext customContext)
Execute the test script.
|
ScriptingContext |
getCompilationContext()
Get context from the last compilation.
|
StyledDocument |
getDocument()
Get the styled document holding source code of the test script.
|
ScriptingContext |
getExecutionContext()
Get context from the last execution.
|
long |
getFileLastModified()
Get the last modification time (in millis) of the file that the interpret
owns.
|
ScriptManager |
getScriptManager()
Get the script manager associated with this test interpret instance.
|
String[] |
getSupportedFileExtensions()
Get typical file extensions that should be handled by a particular
implementation of a test script.
|
int |
getType()
Get the test script type.
|
String |
getTypeDescription()
Get the test script interpret type description.
|
String |
getUID()
Get the test script unique Id (UID).
|
URI |
getURI()
Get test script source code URI.
|
boolean |
hasSource()
Find out if the interpret has access to the source code.
|
boolean |
isDestroyed()
Test out whether the interpret has been destroyed by a call of
destroy() . |
boolean |
isEditable(String extension)
Find out if a test script file of the given extension is a text one
(source code) and can be edited in the script editor.This method allows
to prevent users from opening of binary test scripts, such as for example
Java byte code (.class).
|
boolean |
isExecuting()
Find out whether the test script is currently executing.
|
boolean |
isManualStop()
Indicates whether the script execution was stopped manually by the user.
|
boolean |
isModified()
Find out if the script is modified or not.
|
boolean |
isPartialExecutionAllowed()
Indicate whether it is possible to execute just a part of the test script.
|
boolean |
isPartialExecutionAllowed(int start,
int end,
int[] outRange)
Indicate whether it is possible to execute the specified part of the test script.
|
boolean |
isPartiallyExecuting()
Indicates whether the interpret is currently executing a subset of code.
|
boolean |
isPause()
Indicates whether the script is currently paused/suspended.
|
boolean |
isRunning()
Find out if the script is currently running, i.e.
|
boolean |
isStop()
Indicates whether the execution was stopped.
|
boolean |
isSupportedTestScript()
Test whether the interpret is a supported script, i.e.
|
void |
reload()
Reload the content from the URI set through the
setURI(java.net.URI, boolean) method. |
void |
resetSelection()
Reset selection for partial execution purposes.
|
void |
setFileLastModified(long time)
Set the last modification time (in millis) of the file that the interpret
owns.
|
void |
setModified(boolean modified)
Indicate that the test script has been modified.
|
void |
setPause(Object source,
boolean pause,
String reason)
Pause or resume the executing script.
|
void |
setScriptManager(ScriptManager sm)
Set the script manager associated with this test script interpret.
|
void |
setScriptOwner(ScriptOwner owner)
Set the script owner, typically the GUI editor.
|
void |
setSelection(int startOffset,
int endOffset)
Set the start and end offset for partial execution of a test script.
|
void |
setStop(Object source,
boolean stop,
boolean isManual,
String manualStopJustification)
Request to stop the script execution.
|
void |
setURI(URI uri,
boolean load)
Set the test script URI.
|
static final int TYPE_UNKNOWN
static final int TYPE_PROPRIETARY
static final int TYPE_JAVA
int getType()
String getTypeDescription()
String[] getSupportedFileExtensions()
TestScriptInterpretFactory
)
takes advantage of this method to create interpret instances for particular
test script files.new String[] { "java" }
.
If the method returns null, it means that there is no specific extension
for the script type handled by this class. The latter case applies for example
for the proprietary test script format which may be saved with any extension.boolean isEditable(String extension)
extension
- the file extension.URI getURI()
void setURI(URI uri, boolean load) throws IOException
load
argument is true, the interpret
should load content from the URI to the document. A value of false
is
usually used in "Save As" operations where the URI changes for the
current document content. Saving of the file is however not performed by
this method.uri
- test script URI.load
- whether to open the URI in the current document (see getDocument()
).IOException
- if the load parameter is true and loading of test script fails.void reload() throws IOException
setURI(java.net.URI, boolean)
method.IOException
- on an I/O error.long getFileLastModified()
void setFileLastModified(long time)
time
- last time of saving of the script to the file.void setScriptManager(ScriptManager sm)
sm
- a script manager.ScriptManager getScriptManager()
boolean compile(ScriptingContext customContext) throws InterpretErrorException
customContext
- customized context for this validation. If the argument
is null, the interpret is supposed to obtain a preinitialized context instance
from the script manager through ScriptManager.createDefaultContext()
.SyntaxErrorException
instances to the compilation context. The interpret is also supposed to fire
appropriate compilation script events through the associated script manager.
The context should be made available after compilation through
the getCompilationContext()
method.InterpretErrorException
- should be thrown on an internal error or
illegal interpret state. The exception message gets typically displayed
or otherwise reported to the user.int execute(ScriptingContext customContext) throws InterpretErrorException
customContext
- customized context for this execution. If the argument
is null, the interpret is supposed to obtain a preinitialized context instance
from the script manager through ScriptManager.createDefaultContext()
.
The context should be made available after execution through
the getExecutionContext()
method.InterpretErrorException
- should be thrown on an internal error or
illegal interpret state. The exception message gets typically displayed
or otherwise reported to the user.ScriptingContext getExecutionContext()
execute(ScriptingContext)
, the method should return null.ScriptingContext getCompilationContext()
compile(ScriptingContext)
, the method should return null.boolean isPartialExecutionAllowed()
Indicate whether it is possible to execute just a part of the test script. This is typically possible with scripting languages, such as the proprietary T-Plan Robot Enterprise one, where user can select part of the code in the editor and execute it. It is on the other hand not possible with test scripts written in Java.
Interprets returning true
should expect the calls of the
setSelection(int, int)
method. Interprets which do not support
this feature and return false
should throw an exception when
the method is called.
boolean isPartialExecutionAllowed(int start, int end, int[] outRange)
start
- selection start offsetend
- selection end offsetoutRange
- this is an optional output array (length >= 2) where the
interpret may specify the start and end elements that will be executed for the given
selection specified by [start, end]. Thesevoid setSelection(int startOffset, int endOffset) throws IllegalStateException
getDocument()
method. Interprets which do not support partial executions (i.e. their
isPartialExecutionAllowed()
method returns false) should throw
an IllegalStateException
exception if this method gets called.startOffset
- start offset indicating position in the test script
document to start the execution from.endOffset
- end offset in the test script where execution should be finished.IllegalStateException
- if the method gets called even though the isPartialExecutionAllowed()
method returns false to indicate that this mode is not supported.void resetSelection() throws IllegalStateException
isPartialExecutionAllowed()
method returns false) should throw
an IllegalStateException
exception if this method gets called.IllegalStateException
- if the method gets called even though the isPartialExecutionAllowed()
method returns false to indicate that this mode is not supported.StyledDocument getDocument()
boolean isExecuting()
isExecuting
in interface ScriptedExecutable
boolean isRunning()
isExecuting()
or it is in the post-execution phase involving
posting of final events, result creating and cleaning up.boolean isPartiallyExecuting()
boolean isStop()
isStop
in interface ScriptedExecutable
boolean isManualStop()
void setStop(Object source, boolean stop, boolean isManual, String manualStopJustification)
Request to stop the script execution. The method is not supposed to stop the automated task immediately. It is rather expected to set an internal "stop" flag. The interpret should periodically test the flag, for example between individual command calls, and stop the execution as soon as possible.
The method should not fire a stop event through the ScriptListener
interface. It should be rather fired when the execution is really stopped,
not when the request is made.
setStop
in interface ScriptedExecutable
source
- request source.stop
- true stops (false doesn't really make sense).isManual
- this is additional flag allowing to specify whether the
stop is manual, i.e. requested by the user either through GUI controls or
by pressing Ctrl+C in CLI. This information is saved to the context for
the benefit of report providers and doesn't affect the way the stop action
is carried out.manualStopJustification
- optional string describing why or how the
script was stopped. It is used just for reporting purposes.boolean isPause()
isPause
in interface ScriptedExecutable
void setPause(Object source, boolean pause, String reason)
setPause
in interface ScriptedExecutable
source
- the object requesting the pause (for tracking purposes only)pause
- true to pause, false to resumereason
- optional string describing why or how the
script was paused or resumed.void destroy()
boolean isDestroyed()
destroy()
.void setModified(boolean modified)
modified
- true sets the script status to modified, false to unmodified.boolean isModified()
boolean isSupportedTestScript()
void setScriptOwner(ScriptOwner owner)
owner
- the owner.boolean hasSource()
String getUID()