[KShare] Why should we capture Salesforce Objects manually?

Hi Community members, :wave:

We at Product Support team hopes you had wonderful holiday season and a happy new year with your families and loved ones!

We are kicking things off in 2024 with a Salesforce-focus article! Read more below! :point_down:

1. Why do we need to create locators manually for Salesforce?

Manually creating locators is sometimes needed within Salesforce due to the way Salesforce handles HTML within their website. Katalon Studio can locate these objects with great frequency, but there a few instances where manual location may be needed:

  • Starting a new session (be it logging in with a new user, refreshing the page, or running a test case a second time).

  • Loading the same page as a different user.

  • Elements changing values (for example, a title might change from ‘button__1123’ to ‘button__2231’ on a fresh page reload).

Therefore, creating a locator manually can reduce errors that occur from the changes in these values.

Additionally, Salesforce can have multiple tabs open but are all located within the same HTML script, so specifying certain locators can reduce element confusion between multiple tabs.

2. Salesforce HTML Identification and Best Practices

The primary identifiers for HTML are called “tags” or “elements”, these tags identify what the corresponding visual element appears like on an HTML page. Below we will find further information on these tags and elements, and how to use them to locate the elements on the page for use in Katalon Studio.

2.1. HTML Tags & Attributes

Some of the common HTML tag examples are <div> , <a> , <span> , <ui> , and <li> . These handle different functions within the HTML page, for example, <div> handles divisions or sections within the HTML page, structuring the page into multiple sections whereas <a> handles hyperlinks and would typically appear as a hyperlink on the HTML page.

HTML Attributes are details about each HTML tag/element, things like name or title contain the text of the element whereas style alerts an accompanying CSS document about which styling to use for the element.

Combining HTML Tags & Attributes allows us to locate specific elements within an HTML page. For example, for the HTML line: <span title="Attachments" class="slds-truncate slds-m-right--xx-small" data-aura-rendered-by="20545:0">Attachments</span>

When creating a locator for this element, we would not want to use the Attribute ‘data-aura-rednered–by’ as we can see it has a unique number that is likely to change on a page refresh. Therefore, this element can best be located using this combination of Tag and Attribute information to locate it:

//span[@title='Attachments']

The above XPath/HTML locator will find any element on the HTML page that is of tag type span and contains the title with text “Attachments”.

2.2. 2. HTML Containers/Frames (table, div, frame, iframe, etc.)

HTML has several different container, frame, and dividers that split the HTML page into different sections. Typically, we would see these as <div> for different sections of the page, <table> for a cell, column, and row style table, <frame> or <iframe> as an alternate section type from <div>.

Within each of these container or frame types is contained further HTML code, such as an element we may be trying to identify. In the next section, we’ll cover how to locate an element that is nested within one of these containers.

2.3. Combining Tags & Containers for optimal locating

Sometimes when trying to locate an HTML element, it is helpful to include the section that the element is located in to ensure it is found correctly, for example if the element is located in a table we can include the table within the locator information as an outer HTML element, in this example “[1]” is added to identify the first element of type ‘a’:

//table[@data-aura-class="uiVirtualDataTable"]//a[@data-refid="recordId"][1]

As we can see in the created locator and screenshot above, Salesforce HTML uses unique attribute names like ‘data-aura-class’ and ‘data-refid’. These can be used just like the other attributes such as ‘class’ or 'title’ for locating elements.

2.4. 4. Verifying Locators using Chrome Inspect tool

Once we’ve gotten comfortable with the concept of creating the locators, its time to test them out on a real HTML page. Specific to Google Chrome, we can test out our built locator using Command + F or Control + F on the HTML script page in the inspector. We’ll see this will pull up a search bar that we can paste our locator information into, once pasted, if our locator is correct, it will identify the element on the page for us.

If this worked successfully, it is time to move on to Katalon Studio and implementing the element within our test case, if it didn’t work, we may need to spend some time tweaking the locator information.

3. Applying to Katalon Studio

3.1. Inputting locators and determining default locator

Once we have named our Test Object and it opens, we should see several different options for locators.

Select the XPATH option and place our locator within the text field and save. Our Test Object is now ready for use within a Test Case.

4. Combining KS Recorder/Spy with Manual HTML Locating

For the fastest way to handle Salesforce automated testing, it is recommended to first record our desired test steps using Katalon Studio’s Web Recorder. From here, we can follow the exact path through the website we would like to follow and the Web Recorder will save each step we take through the website as a new Test Case.

After creating a new Test Case using this method, if we encounter Test Objects that seem to fail at random or are not being found, we can then take the manual route of locating the element using the steps we covered in the beginning of the article. This should ensure that the elements we want are being located in a specific manner that reduces the chance of the element not being found, while freeing time from having to manually locate each individual element in our Test Cases.

5. Relevant Documentations

:pushpin: HTML Locator: Handling Web element locators using Katalon Studio | Katalon Docs

:pushpin: HTML Locator Advanced Selection Methods: Selection methods for Web objects in Katalon Studio | Katalon Docs


If you find this article helpful, then don’t forget to leave us a big heart! :heart:

4 Likes

Thank you the @support.squad and @jordan.bartley for yet another informative and helpful article!

Jordan profile pic
Jordan Bartley (@jordan.bartley) - Product Support Specialist
Jordan is a Product Support Specialist on Katalon’s US Support Team. He has worked in Quality Assurance, Automated Testing, and Specialist Support roles for several years before joining Katalon. Through his experience, he shows an innate desire to assist clients, take on challenging problems, and work cross functionally with team members to create new solutions.
5 Likes

This is Part 1 of our Salesforce-focused series in January 2024. To read the other articles within this series, you can go to the topic below …

or navigate to the support tag.