How to create Custom keywords in Opkey?


As we all know Opkey is now a well-known test automation tool and provides a unique and rich set of more than 700 keywords. But, at times we do come across a scenario where the existing keyword set is insufficient and the need arises to create our own keyword. Users can perform such behavior using a custom keyword. Designing custom keywords is one of the advanced features of Opkey. Users can easily add and use a custom keyword like other Opkey keywords. In this article, it is described in detail how you can create your own Custom Keywords using the Opkey Selenium-JS Plugin.

1. Custom keyword without WebDriver’s object 2. Custom-keyword using WebDriver’s object Steps to create custom keywords:-

  • Inside Eclipse select the menu item File > New > Java Project to open the New Java Project wizard.
  • Type “OpKeyCustomeKeywordProject” in the Project name field. Click Finish.
  • Right-click on the src folder. Select New and then select the Package option to create a Package.
  • Browse and select the Source folder path, enter the Name, and then click Finish.
  • Now you need to add the Opkey-pluginbase jar file which is the base file of the Opkey plugins. The Opkey-plugin base jar file's location depends on the Opkey Agent's installation directory. If your OpKey Agent is installed in C drive (Windows 10-based machine) then the location of the opkey-plugin base may be C:\Program Files (x86)\SSTS\OpKey\OpKey Execution Agent\AgentData\Plugins\libs\PluginBase
  • Select the Project Right-click on it and then click on Build Path and then select Configure Build Path.
  • Select the Java Build Path option and then select the Libraries tab and then click on the Add External JARS link.
  • Browse and select the Opkey-plugin base jar file and click Open.
  • Opkey-plugin base jar file has been successfully added as an external jar file.
  • Click Apply and then close the window.
  • Similarly, you can add other external jar files required for the Custom keyword.
  • If you are creating a web Plugin-based Custom Keyword then you need to add the Web Plugin jar file by following the above-described method of adding external jars of Opkey-pluginbase.
  • The Default location of the installed OpKey plugins (like Web) is C:\Program Files (x86)\SSTS\OpKey\OpKey Execution Agent\AgentData\Plugins\Web\Web.jar
  • Let us now create a new Java Class.
  • Right-click on the Package name, select New and then click on the Class option.
  • Enter the name of the Class and click Finish.
  • Now you are ready to create your CustomeKeyword.
  • Write the Java code of the action that you want to perform. (For example, here we have written Java code to add two numbers).
  • Let us now export the Jar file of the written Java code for Custom Keyword.
  • Right-click on your Class and select the Export option.
  • Click on the Browse button to select the export destination. Then click on the Finish button.
  • Now come to the OpKey Web.
  • Select Keyword Management under the Tools menu to open the Keyword Management Wizard.
  • The Manage Libraries tab of the Keyword Management window opens.
  • Upload the specific custom keyword jar using the browse button. Then, click on the Open button to upload the file in OpKey.
  • Navigate to the Custom Keyword tab & click on Add new keyword button.
  • Add new Custom Keyword page opens. Fill all required fields & click on Save.
  • You can add Input Arguments as per the custom keyword requirement.
  • Keyword name: Give the name of your keyword.
  • Plug-in: Select the Selenium-JS plugin.
  • Associated Method: The name should be the same as provided on your jar file function name.
  • Output type: This should be the same as your function.
  • Comment: Enter comments as per the keyword requirement.
  • Input Argument Details: The argument should be in the same order as provided in the function.
  • Associate Library: Select Library (jar file) from the list.
  • Click on the Save button to create the custom keyword.
  • Custom Keyword has successfully been created and you can now use it in Opkey Web.

Coded Function Library is a better alternative for creating Custom Keywords in Opkey. Here, you can write your Custom Keyword-specific code in Java, compile it to fix code errors, associate required libraries, import pre-built libraries, and execute it. Furthermore, this code can directly be called and used in a Test Case or a Function Library and get Executed. You can refer: Coded Function Library

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article