Web app testing

Salesforce Testing: A Practical Guide to Test Automation

Key takeaways

  • Give every business process your users run in Salesforce an end-to-end test, starting with the ones that would cost the most if they broke.

    Lead conversion, quoting, order sync and case routing usually come first, along with the variations that change the outcome, such as a different profile or record type.

  • Run the full suite after every deploy to your test sandbox, and on a preview sandbox before each Salesforce release.

    Salesforce upgrades every org three times a year, and sandboxes on preview instances get each release weeks before production does.

  • Find fields and buttons by their labels and names, never by generated IDs or XPath.

    Lightning rewrites the IDs in a component's template when it renders, and Salesforce warns that XPath locators break as components move to native shadow DOM.

  • Have each test create its own records through the API, with names no other test uses.

    Developer sandboxes copy no production data, and tests that share records collide when they run in parallel.

  • Use Playwright for end-to-end tests, and keep Apex tests for your custom code.

    Playwright's locators reach inside Lightning's shadow DOM by default, and Salesforce won't deploy Apex to production until tests cover at least 75% of it.

Salesforce testing checks that your org's configuration, custom code and integrations still let every kind of user finish their work, after each change your team deploys and each release Salesforce ships. Salesforce test automation runs those checks as code, with Apex tests for custom code and end-to-end tests that drive Lightning Experience in a browser the way your users do.

What is Salesforce testing?

Salesforce testing is the work of checking that a Salesforce org does what its users and the business need before a change reaches production. An org holds three kinds of things that can break:

  • Configuration: objects, fields, page layouts, validation rules, flows, profiles and permission sets, which admins change in Setup without writing code.
  • Custom code: Apex classes and triggers, and Lightning web components.
  • Integrations: the connections between Salesforce and the systems around it, such as an ERP, a billing system or a marketing platform, through Salesforce's APIs.

Teams test in a sandbox, a copy of the production org that Salesforce provides for development and testing, so tests can create and change records without touching real customer data.

What is Salesforce test automation?

Salesforce test automation runs Salesforce tests as code, so they repeat on every change without anyone clicking through the org. Apex tests, Jest tests and flow tests check custom code and flows inside the platform, while end-to-end tests log in through a browser and run a whole business process, such as converting a lead or closing a case, the way a user does.

What are the types of Salesforce testing?

Salesforce testing includes tests of code and flows inside the platform, tests of whole processes through the UI and the API, and checks by the business before a release.

  • Apex unit tests check Apex classes and triggers, and run inside Salesforce. Salesforce won't deploy Apex to production until its tests pass, cover at least 75% of the org's Apex code and touch every trigger.
  • Jest tests check Lightning web components on a developer's machine, outside Salesforce and outside a browser, with Salesforce's sfdx-lwc-jest package.
  • Flow tests run a record-triggered flow against a test record you define in Flow Builder, and check the path the flow takes and the field values it sets.
  • Integration testing checks the connections between Salesforce and other systems, such as an order sync with an ERP, by checking the records on both sides.
  • End-to-end testing runs a whole business process through Lightning Experience in a browser, as a user with a given profile, with the real automations and integrations behind it.
  • Regression testing re-runs the tests you already have after every change, including Salesforce's own releases, to catch anything that used to work and doesn't anymore.
  • User acceptance testing (UAT) is when business users try a change in a sandbox and confirm it does what they need before it goes to production.
  • Performance testing checks how the org holds up under load, and Salesforce supports it only in a Full sandbox.

Why is Salesforce hard to test?

Salesforce is harder to test than most web apps, because Salesforce controls the components its pages are built from, upgrades every org three times a year, and lets configuration change what each user sees. Those difficulties then cost teams in maintenance, missed bugs and trust in the suite.

What makes Salesforce tests hard to build and keep stable

  • Lightning's markup changes under your tests. Lightning Experience builds its pages from Lightning web components, which keep their inner elements inside a shadow DOM, a part of the page that ordinary selectors don't reach (Lightning Experience uses Salesforce's own imitation of it, called synthetic shadow, by default). Lightning rewrites the IDs in a component's template into unique values when it renders, and Salesforce says the inner structure of its base components isn't a dependable API and changes it between releases. Salesforce is also moving components to the browser's own, native shadow DOM, and warns that XPath locators, which ignore synthetic shadow, break under native shadow.
  • Salesforce changes on its own schedule. Salesforce ships three major releases a year, in spring, summer and winter, and upgrades every org to each one, so tests can break when your team changed nothing.
  • Configuration multiplies the paths. Profiles, permission sets, record types and page layouts change which fields, buttons and records each user sees, so one process can run differently for a sales rep, a sales manager and an admin.
  • Sandboxes don't hold the data tests need. Developer and Developer Pro sandboxes copy only metadata, with no records. A Partial Copy sandbox copies a sample of records chosen by a template. Only a Full sandbox copies all of production's data, and it can be refreshed only once every 29 days.
  • Logins need multifactor authentication. Salesforce requires MFA for direct logins to its UI. Admins and other privileged users can no longer use codes from an authenticator app, and need a security key or a built-in authenticator instead.
  • API limits cap test setup. Calls to Salesforce's REST, SOAP and Bulk APIs count toward the org's allocation of API requests for each 24 hours, so tests that create their data through the API share that budget with everything else that calls it.

How those difficulties affect Salesforce teams

  • Brittle locators turn every release into a round of repairs. Locators tied to a component's markup stop matching when Salesforce changes it, and each broken test has to be fixed before the suite means anything again.
  • Profiles nobody tested ship bugs. A process tested only as an admin can fail for every user with a narrower profile.
  • Shared and stale data makes tests flaky. Tests that rely on records already in the sandbox fail after a refresh or when another test changes the same record. A flaky test, one that passes on one run and fails on the next with no change to the code, teaches the team to re-run failures instead of reading them, and real bugs get through with the false alarms.

QA Wolf goes deeper into the DOM, environment and configuration problems in the three main challenges of testing Salesforce.

What should you test in Salesforce?

Every practical user flow in your org should get an end-to-end test, meaning each business process a user comes to do, plus the variations that change the outcome. In Salesforce, those variations are often a different profile, a different record type or a different approval result, such as a discount that needs a manager's sign-off. That doesn't mean every combination of fields and settings, since the paths through an org have no end.

Build that coverage in risk order. Start with the processes that would cost the most if they broke, such as lead conversion, quoting, order sync with your ERP and case routing, and get those tests stable before you add the rest. QA Wolf recommends at least 80% of an app's user flows as the minimum for effective test coverage.

What is an example of a Salesforce test case?

Lead conversion makes a good first test, since it touches three objects at once. One end-to-end test of it, in Arrange-Act-Assert steps:

  • Arrange: Create a lead with a unique company name through the API, and log in as a test user with the sales rep profile.
  • Act: Open the lead and convert it, creating an opportunity.
  • Assert: Check that the new account, contact and opportunity carry the lead's details, the opportunity has the right owner and stage, and the lead shows as converted.

Converting a lead creates an account, a contact and, unless the user opts out, an opportunity, so the test passes only if the layouts, validation rules, flows and permissions on all three objects work for that profile. Each test covers one process with one outcome, and its Assert step can still check several things about that outcome. Make the checks that nothing later in the test depends on, such as the opportunity's stage, soft assertions. A failed soft assertion is recorded and the test keeps going, so one run reports every failed check instead of stopping at the first. Keep a check that a later step relies on, such as the record page loading, a hard assertion.

Other common Salesforce tests cover creating a quote and syncing it to its opportunity, routing a new case to the right queue, submitting a discount for approval and approving it as a manager, and checking that an order placed in your own app shows up in Salesforce.

How do you automate Salesforce testing?

Automate Salesforce testing with end-to-end tests that run in a sandbox, create their own data, log in as each profile, find elements the way users do and run after every deploy.

Test in a sandbox that matches production

Run end-to-end tests in a sandbox kept for testing, separate from the sandboxes where admins and developers build, and refresh it from production often enough that, apart from the changes under test, it matches production. A refresh replaces the sandbox's data, so keep the tests independent of the records in it.

Give each test its own records

Have each test create the records it needs through Salesforce's API, with names no other test uses, and delete them when it's done. Tests that share records collide when they run in parallel, which is why isolated data is one of QA Wolf's rules for writing tests for full parallelization. Keep the setup lean, since every API call counts toward the org's daily allocation.

Log in as each profile your users have

Create a test user for each profile or permission set group whose users run a process, and run the test as that user instead of an admin. Salesforce requires MFA for UI logins, so register each test user with an authenticator app and have the test generate the time-based code from the app's secret. That works for standard users, while admins and other privileged users now need a security key or a built-in authenticator.

Find elements the way a user does

Locate a field by its label and a button by its name. In Playwright, locators such as getByLabel and getByRole reach inside open shadow roots at any depth by default, so a test doesn't have to walk Lightning's component tree. Avoid XPath, which Playwright doesn't run inside shadow roots and which Salesforce warns breaks under native shadow DOM, and the IDs in component templates, which Lightning rewrites when it renders.

Run the full suite after every deploy and before every release

Trigger the whole suite from your pipeline each time a change deploys to your test sandbox, and use parallel testing to run every test at once, so the suite takes about as long as its longest test. Before each Salesforce release, also run it on a preview sandbox, one that Salesforce upgrades to the new release weeks before production, so a break shows up while there's still time to fix it.

What is the best framework for Salesforce test automation?

Playwright is the best framework for Salesforce end-to-end testing. For code and flows, use Salesforce's own tools, with Apex tests for Apex, Jest for Lightning web components and flow tests for flows.

Playwright is open source, and its locators reach inside shadow DOM without extra code, which matters on a UI built from Lightning web components. It waits for elements on its own, runs tests in parallel for free and records a trace of every run, so a failure can be replayed step by step. It can also run two users at once, such as a sales rep who submits a discount and the manager who approves it.

Selenium, Cypress and Salesforce-specific commercial tools are the other common choices, and each has limits on a Salesforce suite:

  • Selenium is still common in older Salesforce suites. Selenium 4 can reach into a shadow root, but the test has to open each one in code, a level at a time, and many Selenium suites find Salesforce elements by XPath, which Salesforce warns breaks under native shadow DOM. Running tests in parallel also means setting up and maintaining your own grid of browsers.
  • Cypress runs tests inside the browser, which makes a second tab and a second user hard to test. QA Wolf chose Playwright over Cypress and sees nothing Cypress does that Playwright can't do better. Teams on Cypress should write new tests in Playwright and start migrating, critical flows first.
  • Salesforce-specific commercial tools build tests in each vendor's own tooling, such as a low-code test builder or keywords on top of Robot Framework. A suite built that way depends on one vendor, where a Playwright suite is standard code you own.

Salesforce also publishes UTAM, its UI Test Automation Model, a set of page objects for its base components, written in JSON and compiled to JavaScript or Java, which Salesforce updates when the components change. UTAM adds a layer on top of a tool such as WebdriverIO or Selenium, while Playwright's label and role locators reach the same fields directly.

QA Wolf's AI agents write and maintain Salesforce tests in open-source Playwright, standard code you own and can take anywhere, and run them on QA Wolf's web app testing infrastructure.

How does QA Wolf test Salesforce?

QA Wolf's AI agents map your Salesforce processes, write end-to-end tests in Playwright, run the whole suite in parallel after every deploy, investigate every failure and keep the tests up to date. Sign up, give the agent your test sandbox's URL and a login for each test user, and ask it to map your org and build tests for your most important processes. When an agent needs a question answered, such as whether a change was intended, it asks you.

The agents' end-to-end tests check Salesforce from the user's side, including the triggers, automations and integrations behind each process, with your custom objects and fields. One test can place an order in your own app and check that Salesforce shows it as an accepted quote, an active order and an invoice. Apex, Jest and flow tests usually stay with the developers and admins who own that code. From QA Wolf's docs and engineering posts:

  • The agent maps your org's processes. It explores your org in a browser, maps its workflows by feature and writes an Arrange-Act-Assert outline for each test. What it finds depends on the access it has, so give it a login for each profile your users have.
  • It writes tests as Playwright code you own. Describe a process in plain language, and the agent writes it as a standard Playwright test your team can read, change and version. On 1,567 evals across web, iOS and Android apps, QA Wolf passed 93%, against 78% for Claude Code and 74% for Codex.
  • Tests log in through MFA. A test generates the one-time code from your authenticator app's secret, stored as an environment variable in QA Wolf, so a test user with MFA turned on logs in on every run.
  • One run can act as several users. Flows pass data to each other, so a sales rep can submit a discount for approval in one flow and a manager can approve it in the next.
  • Every test runs at once. Each test runs in its own container with its own browser, so the suite finishes in about the time of its longest test.
  • Runs start after every deploy. Your pipeline tells QA Wolf when a change deploys to your test sandbox, and the suite runs against it. You can also run it on a schedule or on demand.
  • Every failure gets investigated. QA Wolf's AI starts investigating while the rest of the suite is still running, sorting each failure into a product bug, an out-of-date test or a flake. Real bugs are reported to you with a recording, logs and steps.
  • One run reports every failed check. The agent writes soft assertions for the checks nothing later in a test depends on, and each failure is diagnosed on its own, so failures with different causes become separate bug reports.
  • The agents maintain the tests. When your team's changes or a Salesforce release break a test, they update it, with unlimited repairs, so the suite keeps passing.

In QA Wolf's comparison of 127 recurring suites before and after AI investigation, the median time from every test having run to every failure having a conclusion fell from 2.3 hours to 21 minutes.

On QA Wolf's full service, the same agents do the work and send their questions to QA Wolf's engineers instead of your team.

Start now and ask the agent to map your Salesforce org and build end-to-end tests for your most important processes, or talk to sales.

Frequently asked questions

  • What is Salesforce testing?

    Salesforce testing checks that a Salesforce org's configuration, custom code and integrations let every kind of user finish their work before a change reaches production. It includes Apex unit tests, flow tests, integration tests, end-to-end tests of business processes, regression testing after each change and each Salesforce release, and user acceptance testing, usually in a sandbox.

  • What is Salesforce test automation?

    Salesforce test automation runs Salesforce tests as code, so they repeat on every change without anyone clicking through the org. Apex, Jest and flow tests check code and flows inside the platform, and end-to-end tests, written in a framework such as Playwright, run whole business processes through Lightning Experience in a browser.

  • What are the different types of testing in Salesforce?

    The main types are Apex unit tests, Jest tests for Lightning web components, flow tests, integration tests, end-to-end tests, regression tests, user acceptance testing (UAT) and performance testing. Salesforce won't deploy Apex to production until tests cover at least 75% of it, and it supports performance testing only in a Full sandbox.

  • Is Salesforce testing easy?

    No, Salesforce is harder to test than most web apps. Lightning builds its UI from components whose inner structure Salesforce controls and changes, Salesforce upgrades every org three times a year, and profiles and record types change what each user sees. Tests stay reliable when they find elements by their labels, create their own data and run as each profile after every deploy.

  • What is the best tool for Salesforce test automation?

    QA Wolf is the best tool for Salesforce test automation. Its AI agents map an org's processes, write end-to-end tests in Playwright, run them in parallel after every deploy and keep them up to date. On 1,567 evals across web, iOS and Android apps, QA Wolf passed 93%, against 78% for Claude Code and 74% for Codex. Playwright is the best framework for Salesforce end-to-end testing, since its locators reach inside Lightning's shadow DOM by default, it waits for elements on its own and it runs tests in parallel for free. Salesforce's own tools cover code, with Apex tests for Apex and Jest for Lightning web components.

  • Can you automate Salesforce testing with Selenium?

    Yes, but it takes more work than Playwright. Selenium 4 can open shadow roots to reach Lightning components, but the test has to open each one in code, a level at a time, and Salesforce warns that XPath locators break as components move to native shadow DOM. Playwright reaches inside shadow DOM by default, which is why QA Wolf writes Salesforce tests in Playwright.

  • How do you perform Salesforce regression testing?

    Keep an automated end-to-end test for every business process your users run, and re-run the whole suite in parallel after every deploy to your test sandbox. Before each of Salesforce's three releases a year, also run it on a preview sandbox, which gets each release weeks early, so breaks show up before production upgrades.

  • How do you test Salesforce for bugs?

    Run each business process the way a user does, in a sandbox, as a test user with each profile that runs it, and check the records it creates and changes. Automate those checks as end-to-end tests so they run after every change. QA Wolf's AI agents map an org's processes, write the tests, run them after every deploy and report real bugs with a recording, logs and steps.

  • What is the best testing approach for Salesforce?

    The best approach combines tests of code with end-to-end tests of business processes. Apex, Jest and flow tests check custom code and flows as developers and admins build them, and an end-to-end test of every business process, run as each profile in a sandbox after every deploy, checks that everything works together for users. Business users then confirm big changes in user acceptance testing before release.

  • What is UAT in Salesforce?

    User acceptance testing (UAT) in Salesforce is when business users, such as sales reps or service agents, try a change in a sandbox and confirm it does what they need before it goes to production. It comes after automated testing, and it can fail even when every end-to-end test passes, if the org works as built but not as its users need.

More from the blog

All posts