Table of Contents

Tutorial: Custom Plugins

Learning Objectives

What does a plugin do?

Plugin extends capability that enables your script to interact with AUT like SELENIUM plugin and build shared operations to be used on multiple models like RANDOM plugin.

Develop custom plugin

Custom plugins are just java classes. They can be developed in any java IDE. We will use Eclipse IDE in this tutorial, you should be able to do the same in other IDEs.

Before we can start building our custom plugin, we need to set up the java development environment:

  <dependency>
    <groupId>com.github.testoptimal</groupId>
    <artifactId>JavaConnector</artifactId>
    <version>1.0.2</version>
  </dependency>

Now we are ready to build our first custom plugin in Eclipse:

Below is an example of the java class:

 package com.mine.plugin;
 import com.testoptimal.plugin.MScriptInterface.IGNORE_INHERITED_METHOD;
 import com.testoptimal.plugin.MScriptInterface.TO_PLUGIN;
 import com.testoptimal.plugin.PluginAncestor;
 @IGNORE_INHERITED_METHOD
 @TO_PLUGIN
 public class MyPlugin extends PluginAncestor {
 
    @Override
    public String getPluginID() {
       return "MYPLUGIN";
    }
 
    @Override
    public String getPluginDesc() {
       return "My Plugin";
    }
 
    @NOT_MSCRIPT_METHOD
    @Override
       public void start() throws Exception {
          System.out.println("My Plugin started");
 
    }
 
    @NOT_MSCRIPT_METHOD
    @Override
    public void close() {
       System.out.println("My Plugin closed");
    }
 
    public String doSomething (String something_p) {
       System.out.println("My plugin: " + something_p);
       return "Done";
    }
 }

By default, all public methods declared as well as inherited are exposed as MScript function. To exclude certain methods from being exposed as MScript function, add annotation @NOT_MSCRIPT_METHOD to the method. Add annotation @IGNORE_INHERITED_METHOD to the plugin class to exclude inherited methods from being exposed as MScript functions.

Don't forget to write junit test to test the plugin functions.

Deploy Custom Plugin

 plugin.packages=com.mine.plugin

Above registry tells TestOptimal server where to look for your custom plugins. If you have multiple custom plugins in the same java package, they will all be found automatically.

Using Custom Plugin

Plugins must be activated before they can be used in the script. Below is the steps to activate the plugins:

Press Ctrl-Space to open CodeAssist. Your plugin should show up on CodeAssist list as $'pluginID'