Skip to content

Sample project that demonstrates adding custom keywords for OpenTest

Notifications You must be signed in to change notification settings

mcdcorp/opentest-extension-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OpenTest extension sample

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.

Creating an OpenTest extension

To create a new OpenTest keyword and make it available in your tests, follow the steps below:

  1. Create a new Java project.
  2. Define a dependency on the opentest-base project.
  3. Create a new class that extends the org.getopentest.base.TestAction class.
  4. Override the run method and implement it by adding whatever functionality you want your new keyword to perform. Inside of the run method you'll have access to a few things that you need that are provided by the base TestAction 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.
  5. Build your new project into a JAR.
  6. 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.

Debugging your custom keywords

To debug your new custom keywords:

  1. 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).
  2. 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).
  3. 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 named actor.sample.yaml, so you'll need to copy & paste that into a new actor.yaml file in the same path.
  4. Indicate org.getopentest.Main as the "main" class of your project. This is done differently depending on the IDE you are using.
  5. 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.
  6. 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.

Sample test

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));

About

Sample project that demonstrates adding custom keywords for OpenTest

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages