This projects implements some very simple OpenTest keywords and can be used as a starting point or example of how to extend the OpenTest functionality with new keywords.
To create a new OpenTest keyword and make it available in your tests, follow the steps below:
- Create a new Java project.
- Define a dependency on the opentest-base project.
- Create a new class that extends the
org.getopentest.base.TestAction
class. - Override the
run
method and implement it by adding whatever functionality you want your new keyword to perform. Inside of therun
method you'll have access to a few things that you need that are provided by the baseTestAction
class:- A set of methods that provide the values of the arguments supplied to the test action in the test file (e.g.
readStringArgument
,readIntArgument
, etc.) - The
writeOutput
method that allows you to output a value that can be used from subsequent test steps. - The
log
object, that can be used to write an entry into the test session log. - When you need to signal that the test action failed you can just throw a
RuntimeException
. The test actor will safely catch it and will understand that the action has failed.
- A set of methods that provide the values of the arguments supplied to the test action in the test file (e.g.
- Build your new project into a JAR.
- Copy the JAR (along with any dependencies that are not already included with the test actor) into the
user-jars
directory in the working directory of your test actor. When the test actor starts, it will automatically load any JARs it find in that location.
To debug your new custom keywords:
- Create a new Java project that will represent the test actor application. You can look at the
opentest-actor
project here for an example (and you can even use it as your starting point). - Define a dependency on the project where you implemented the custom keywords. This will bring in your keywords along with all other OpenTest dependencies (since your extension project already defines the dependency to the
opentest-base
project). - Add an
actor.yaml
file as a resource into your project. This file will be used as the test actor configuration file. You can look at the opentest-actor project for an example on how this looks like, but please note that the file that was added to source control is namedactor.sample.yaml
, so you'll need to copy & paste that into a newactor.yaml
file in the same path. - Indicate
org.getopentest.Main
as the "main" class of your project. This is done differently depending on the IDE you are using. - Make sure your OpenTest server is running and start debugging your new test actor project. You will immediately see your test actor appear in the OpenTest server UI. You can now set breakpoints in your test actions and can use all the tools provided by your IDE.
- Create a new test that makes use of the custom test action(s) you created and run it by starting a new test session from the OpenTest server web UI.
Here's a simple tests that makes use of the sample keywords defined in this project:
description: Demonstrate the use of the sample test actions
actors:
- actor: ACTOR1
segments:
- segment: 1
actions:
- action: opentest.extension.sample.GreetUser
args:
userName: John Doe
- action: opentest.extension.sample.CalculateAge
args:
birthDate: "1983-02-03"
- script: |
$log(
$format(
"The calculated age is {0} years",
$output.years));