Salesforce Lightning Web Component (LWC) locator support 

We’ve been working hard to deliver solutions which support Lightning Web Component (LWC) testing and we also have improvements in the pipeline designed to enhance this capability in the future. The following includes information about the unique challenges associated with testing Lightning Web Components and your options for testing Lightning Web Components using Provar.

 

The limitations of XPath and CSS locators


In some instances, you may attempt to test web components within a web app and find that traditional XPath and CSS locators are not able to locate an element. This is because web components are encapsulated by the Shadow DOM. Within the Shadow DOM, the elements within a web component are private which means that XPath and CSS locators are unable to access their elements – causing tests to fail. 

 

Using Provar to test Lighting Web Components


If you’ve started to build and use Lightning Web Components in your Salesforce Lightning Experience enabled org, Provar can help. We provide the ability to test Lightning Web Components using two methods. You can use our ProvarX locator or the By Javascript option. Both of these automatically interpret the page structure and generate a unique locator path to locate elements on the page which aren’t possible with standard XPath and CSS locators.

Both of these options simplify testing by providing the capability to locate elements within a Lightning Web Component by generating Shadow DOM compliant locators. This enables you to set, read and assert the value of the element. 

In general, we recommend that you use ProvarX™ when testing Lightning Web Components. ProvarX™ provides a robust and seamless testing experience since it is built to natively adapt to Provar. ProvarX™ is our proprietary implementation of XPath that uniquely navigates the complexities of the Shadow DOM in comparison to other tools which still use the limited functionality of traditional XPath libraries. 

Though, in some situations, you may need to use By Javascript instead. For example, if you are integrating Provar with DevOps platforms and tools that use JavaScript, you can still take advantage of those JavaScript locators within Provar. 

 

Testing Lightning Web Components with ProvarX™


The ProvarX™ locator can also be used to locate a Lightning Web Component on a Salesforce page by constructing a custom page object within Provar and locating the relevant element. Please refer to this support article for detailed information about using ProvarX

 

Testing Lightning Web Components with the By Javascript locator


The By Javascript locator can also be used to locate the Lightning Web Component on a Salesforce page by constructing a custom page object within Provar and locating the relevant element. Please refer to this support article for detailed information about using By Javascript

 

Currently, you can use Provar to test the following Lightning Web Components: 


Elements Interaction
Text Input Field Read/assert, Set
Labels Read/assert
Checkbox Check, Uncheck, toggle
Picklist Set, Set by Index
Lightning-buttons Click, Read Assert
Hyperlink Click, Read Assert
Date field Set
Time field Set

 

If you would like to learn more about using the Provar to test Lightning Web Components, please contact us to discuss your testing strategy and requirements at support@provartesting.com.

 

Documentation library

Other available resources

Looking for something different?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.