Reusing test objects in test cases, especially for applications with consistent design patterns or shared components across different modules, can significantly enhance test efficiency and maintainability. This approach is particularly useful in platforms like Salesforce, where similar elements, such as combo boxes, might appear across different objects like Accounts, Leads, etc., with only slight variations in their identifiers or labels.
Strategies for Reusing Test Objects
- Parameterization of Test Objects
- Description: Parameterization involves defining test objects in such a way that they can accept dynamic inputs. For instance, if combo boxes across different Salesforce objects share a similar CSS selector pattern but differ in their IDs, you can create a parameterized test object where the ID part is variable.
- Implementation in Katalon Studio:
- Create a test object in Katalon Studio without specifying the full ID. For example, if the ID changes across objects, use a placeholder in the test object’s selector definition.
- When using this test object in a test case, pass the specific ID as a parameter to create a fully qualified selector for each specific instance. Using the Parameterized Test Object in a Test Case:
groovy
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// Define the ID part dynamically
String dynamicId = 'combo-account' // This could be 'combo-lead', etc.
// Get the generic test object
TestObject comboBox = findTestObject('Object Repository/GenericComboBox')
// Modify its property to match the specific combo box needed
comboBox.modifyProperty('id', ConditionType.EQUALS, dynamicId)
// Use the modified test object in your test
WebUI.click(comboBox)
- Using Regular Expressions in Object Identification
- Description: Utilize regular expressions (regex) in CSS selectors or XPath to identify elements that follow a specific pattern but may have minor differences. This is useful for matching elements that contain consistent parts in their identifiers.
- Implementation in Katalon Studio:
- When defining the test object’s selector, use a regex that matches the common pattern across the different combo boxes. For example, if the ID of the combo boxes follows a pattern but only differs by a numeric value, the regex can match all variations based on the consistent part of the ID.
Example of a Test Object Selector with Regex:
Assuming combo box IDs follow a pattern like combo-account-123, combo-lead-456, where the prefix is consistent, and the suffix is a numeric value.
Copy code
//input[starts-with(@id, 'combo-')]
- Centralized Object Repository
- Description: Maintain a centralized object repository where commonly used elements like combo boxes are defined. This repository acts as a single source of truth for test objects that can be reused across multiple test cases.
- Implementation in Katalon Studio:
- Organize your Object Repository in Katalon Studio with well-named folders representing different modules like Accounts, Leads, etc., and store commonly used test objects in a shared folder.
- Reference these shared test objects in your test scripts whenever you need to interact with elements common across modules.
3. Centralized Object Repository
You structure your Object Repository to have shared objects that are common across different modules:
Object Repository/
├── Shared/
│ └── GenericComboBox
├── Accounts/
│ └── SpecificAccountField
└── Leads/
└── SpecificLeadField
To make it more advanced a object repo simplified setup, for maintenance is created. While it is good that there are self healing capabilities and record a playback I always teach my testers internally and externally to think very well about an xpath and locator strategy, for maintenance purposes.
For this I created a combo object repo and an input field repo and reference the xpath name property as the field name. Most Salesforce master data names are implemented this way(at least for the default application) so this will improve the maintenance
WebUI.setText(findTestObject('Salesforce/Account/Masterdata_fields_Pageobjects/inputfields', [('inputfields') : 'Site']), site)
WebUI.setText(findTestObject('Salesforce/Account/Masterdata_fields_Pageobjects/inputfields', [('inputfields') : 'AnnualRevenue']), annualRevenue)
WebUI.setText(findTestObject('Salesforce/Account/Masterdata_fields_Pageobjects/inputfields', [('inputfields') : 'Phone']), phone)
Challenge
Please try to create your own parameters in salesforce using the https://github.com/learn-automated-testing/Katalon_Salesforce_Course project template