Skip to main content
Transform your testing process with: Company-wide Licences, Test Observability & App Percy
No Result Found

Modify serialized DOM using domTransformation

Learn how to customize and manipulate serialized DOM using the domTransformation feature.

In certain scenarios, you may need to modify the DOM to ensure it renders correctly in Percy. For example, you might hide ad banners or adjust UI states that are not captured as expected. When Percy sends the serialized DOM to its backend for re-rendering across different browsers and devices, you can modify it by passing a domTransformation function. Learn more about the basics of Percy SDKs workflow by reviewing this guide.

The domTransformation function accepts documentElement as an argument and doesn’t require a return value. Check out the following examples to see how it works.

Examples

If you use the percy snapshot command, follow this configuration.

  • This feature requires Percy CLI v1.24.0 or higher.
  • It’s only available for per-snapshot configuration, and not global configuration.

Percy snapshot

YAML
Copy icon Copy

SDKs

If you’re using any SDKs then you can check the following SDK examples.

  • This applies to both BrowserStack SDK and Percy SDK.
  • Use percy_snapshot function if you’re using the Percy SDK for web projects. For Automate projects with the Percy SDK or when using the BrowserStack SDK, use percy_screenshotfunction.

Selenium

Copy icon Copy
Copy icon Copy
Copy icon Copy
Copy icon Copy

Playwright

Copy icon Copy
Copy icon Copy
Copy icon Copy
Copy icon Copy

Cypress

JavaScript
Copy icon Copy

Puppeteer

JavaScript
Copy icon Copy

Storybook

Note: It only works with enableJavaScript: false

JavaScript
Copy icon Copy

Advanced use case

Accessing DOM elements inside shadow DOM:

JavaScript
Copy icon Copy

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle