To understand extensions, lets first understand the three pillars of selenium IDE
- Action: What operation you are performing on UI Screen
- Assessors/Assertion: What verification you do on data you get from UI
- Locator Strategy: How can we find the element in UI.
Now, Selenium IDE has a very mature library with plenty of Actions, Assertion/Assessors and Locator Strategies.
But sometimes we need to add some more functionality to it for our project requirements. In that situation, we can expand this library by adding our custom extensions. These custom extensions are called 'User Extension'.
For example, we need an Action which can convert the text to upper case before filling it in a web element. You cannot find this Action in the default Action library. In such case you can create your own 'User Extension'. In this tutorial , we will learn how to create user extension to convert Text to Upper Case
To create your own user extension you need to create Java script methods and add them to the selenium object prototype and PageBot object prototype.
How Selenium IDE recognizes User Extension?
Step 1) Action- all actions are started by "do", i.e. if the action is for upper case text than its name will be doTextUpperCase. When we add this action method in Selenium IDE, Selenium IDE will itself create a wait method for this action. So in this case when we create doTextUpperCase action, Selenium IDE will create a corresponding wait function as TextUpperCaseAndWait. It can accept two parameters
Example: Upper Case Text Action
Step 2) Assessors/Assertion- All assessors registered in selenium object prototype will be prefixed
by "get" or "is" Ex. getValueFromCompoundTable , isValueFromCompoundTable .It can accept two parameters, one for target and other for value field in test case.
For each Assessor there will be corresponding verification functions prefixed by "verify", "assert" and the wait function prefix by "waitFor"
Example: For Upper Case Text assessors
Step 3) Locator strategy- If we wish to create our own function to locate an element then
we need to extend PageBot prototype with a function with prefix "locateElementBy".
It will take two parameters, first will be the locator string and second will be the document
where it needs to be search.
Example: For Upper Case Text Locator