Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:plugins [2020/06/06 19:20]
admin
tutorial:plugins [2021/01/10 17:58] (current)
admin [Using Custom Plugin]
Line 1: Line 1:
-====== Tutorial: Plugins ======+====== Tutorial: Custom Plugins ====== 
 + 
 +====Learning Objectives==== 
 +  * [[#What does a plugin do?]] 
 +  * [[#Develop custom plugin]] 
 +  * [[#Deploy custom plugin]] 
 +  * [[#Using custom plugin]] 
 + 
 + 
 +===== What does a plugin do?===== 
 +Plugin extends capability that enables your script to interact with AUT like [[plugins#selenium_plugin|SELENIUM]] plugin and build shared operations to be used on multiple models like [[plugins#random_plugin | RANDOM]] plugin. 
  
-Learning Objectives: 
-  * What does a plugin do? 
-  * System plugins 
-  * Develop custom plugin 
-  * Deploy custom plugin 
-  * Sharing custom plugin 
  
 ===== Develop custom 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:
 +  * create a java maven project
 +  * add following maven dependency to pom.xml
 +
 +    <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:
 +  * create a plugin java package to hold your custom plugin java classes, e.g. com.mine.plugin
 +  * create your custom plugin java class by inheriting from //com.testoptimal.plugin.PluginAncestor// class
 +  * add @TO_PLUGIN annotation to your java class
 +  * implement required methods
 +  * add your plugin functions - declare them as public functions
 +
 +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 =====
 +  * Export project as jar file
 +  * Copy the plugin jar file to /lib folder in //TestOptimal// server
 +  * Register your plugin package in //config/config.properties//:
 +
 +   plugin.packages=com.mine.plugin
  
-Set plugin development environment using Eclipse IDE: +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.
-  * create a java project +
-  * add toplugin.jar to build path (project properties)+
  
-Create plugin package +  * Restart TestOptimal server to make the changes effective.
-Create plugin class inheriting from PluginAncestor class +
-Add @TO_PLUGIN annotation to the class +
-Implement required methods +
-Add your plugin functions, declare as public functions +
-Compile and fix errors +
-Write your junit test to test the plugin functions.+
  
 +===== Using Custom Plugin =====
 +Plugins must be activated before they can be used in the script.  Below is the steps to activate the plugins:
  
-Deploy Custom Plugin: +  * Open an existing model or create a new model 
-Export project as jar file +  * Select //SCRIP//T tab 
-Copy plugin jar file to /lib folder +  * Click on "P" icon on the upper-right toolbar 
-Register your plugin package in config.properties +  * Check the checkbox for your custom plugin 
-   plugin.packages=your_plugin_package_path +  * Close Plugin Activation dialog
-Restart TestOptimal server+
  
-Use Custom Plugin: +Press //Ctrl-Space// to open //CodeAssist//  Your plugin should show up on //CodeAssist// list as //$'pluginID'//
-Open an existing model or create a new model +
-Select SCRIPT tab +
-Click on "P" icon on SCRIPT tab toolbar +
-Check the checbox for your custom plugin +
-Your plugin should show up on CodeAssist list as "$'pluginID'", e.g. $MYPLUGIN +
-CodeAssist on your custom plugin should automatically be added.+