Sometimes, the existing keyword set may not suffice, prompting the need for custom keywords. Opkey allows users to create and use their own custom keywords, which is one of its advanced features. Users can easily add and utilize these custom keywords just like the standard ones.
This article provides a detailed guide on creating your own custom keywords using the Opkey Selenium-JS Plugin.
It can be created in two ways:
1. Custom keyword without WebDriver’s object
2. Custom-keyword using WebDriver’s object
Let’s understand how the Custom keyword can be created without WebDriver’s Object :
Download ECLIPSE IDE to begin the creation of custom keywords
Open the Eclipse IDE and navigate to the File Menu. Click on New and select Java Project.
On the pop-up window, enter the project name, select the JRE and Project Layout. Click Finish.
Once the project is created, select the SRC folder.
Select the Build Path from the options and navigate to Configure Build Path option.
On the pop-up window, select libraries and click on Add External Jars.
Browse and select the Opkey-plugin base jar file and click Open.
Opkey-plugin base jar file gets successfully added as an external jar file.
Click Apply and then click Apply and Close to close the window.
Similarly other external jar files required for the Custom keyword can be added in the similar process.
To add a package, click on the SRC folder, select New and navigate to Package.
On the pop-up window, enter Name and click on Finish.
To enter a Class, click on New and select Class.
On the pop-up, enter name and click Finish.
Now you are ready to create your Custom Keyword.
Write the Java code of the action that you want to perform. For example, here we have written Java code to add two numbers.
Now export the Jar file of the written Java code for Custom Keyword. Right click on the class and select Export.
On the Pop-up window, select the jar file and click Next.
Select the jar file name and select Finish.
Creating Custom Keyword using Web driver Object:
Open the Eclipse IDE and navigate to the File Menu. Click on New and select Java Project.
On the pop-up window enter the name of the Project and select project name. Click Finish.
Click on the Folder and select New. Navigate to Package option.
Enter the name of the package and click Finish.
Click on the keyword folder and select New. Navigate to Class option.
Enter the name of the class and click Finish.
Click on the main folder and select Build path. Navigate to Configure Build path option.
Select Libraries option and click on Add External JARs.
Browse to add the jar and click the option of Apply and select Apply and Close.
Write the code for the functionality. Here we have created a functionality for Click.
Go the folder created for Custom keywords using Web driver Object.
Select Export from the options.
On the next window, select the jar file and click Next.
Select the Jar file to export and click Finish.
The jar file will be exported to be used.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article