DOM Inspection Tests Are Subject to Change
Where: This release note applies to Lightning Experience and Salesforce Classic.
Why: Parts of Lightning Experience use Lightning web components, which are based on the Web Components standard. This standard includes Shadow DOM, which hides a component's markup, style, and behavior from other components. This encapsulation poses challenges for UI tests, especially tests that rely on globally searching the DOM or reaching into the internals of custom elements.
How: In Spring ’19, we made significant changes to introduce a shadowRoot property that encapsulates an element's DOM subtree. This shadowRoot is represented as a DocumentFragment in the DOM and elements inside this DOM subtree are not available by traditional DOM querying methods. Elements that are rendered by Lightning web components contain this new shadowRoot property, and these elements are hidden from normal DOM queries.
We recommend using unit-testing tools to test individual Aura components and Lightning web components, and only using UI testing tools for end-to-end testing.
For Lightning web components, use lwc-jest to write unit tests.
For end-to-end UI tests, you need to adapt your existing tests for Shadow DOM use. How to do this varies by tool, and is rapidly evolving. At this moment in time, this article is a good example for Selenium WebDriver.