How to develop your own Plugins for Seleniet

Java File

Create a java file in the seleniet root folder, like e.g. this one:

package et.seleniet.plugins.ext;
import java.util.List;
import org.openqa.selenium.Alert;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import et.seleniet.api.AbortException;
import et.seleniet.api.ElementIndependentKeywordPlugin;
import et.seleniet.api.Seleniet;
import et.seleniet.api.Log;

public class DummyExamplePlugin extends ElementIndependentKeywordPlugin {

 public void execute(Seleniet driver, WebElement elem, String page, List<String> lineArgs, List<String> tcParams)
 throws NoSuchElementException, AbortException {
   try {
     Alert alert = driver.webDriver().switchTo().alert();
     if (alert != null) {
       alert.accept();
     }
   } catch (Exception e) {
     // all fine
   }
  }
}

Warning_iconWarning_icon

Make SURE that your class name ends with “Plugin” and that you derive from “ElementIndependentKeywordPlugin” else it won’t be found by Seleniet!

Compile

run the command below to compile your source code

Linux
javac -cp seleniet-exec*.jar:lib/* DummyExamplePlugin.java
Windows
javac -cp seleniet-exec*.jar;lib\* DummyExamplePlugin.java

Jar it

After successful compilation create the folders:

mkdir et/seleniet/plugins/ext

and move the class file into the ext subfolder. Now jar the class file and move the jar file to the lib/ext folder (if it doesnt exist create it!).

jar cvf  seleniet-extplugin.jar et
mv seleniet-extplugin.jar lib/ext

For Windows please use analog commands on the command line or use Tools such as Winzip to create the Java Archive.

Run it

Test it by starting seleniet with

./seleniet.sh run --dev Development.xls zephyr --url http://localhost

Check the console ouptut and you will see two lines amongst many others

...
...
[.....] - INFORMATION - PLUGIN Found resource URL for package et.seleniet.plugins.ext: jar:file: .....
...
...
...
[.....] - INFORMATION - PLUGIN KEYWORD 'dummyexample' -> 'et.seleniet.plugins.ext.DummyExamplePlugin' 
...
...

This indicates that Seleniet has successfully detected your plugin and you can use it in your test cases.

Leave a Reply

Your email address will not be published. Required fields are marked *