If you’re writing automated end-to-end tests for the Salesforce platform, you’re likely using Robot Framework, an open source automation framework that exposes its own DSL for creating automated tests.
In this blog post, we’ll cover how developers can get the benefits of a natural language approach like with Robot Framework, but without needing to conform to any predefined syntax, and with a more modern test automation framework.
To start, let’s review an example Robot Framework test that creates a Contact in Salesforce. I took this example from the CumulusCI docs:
Unfortunately, popular testing tools like Playwright have poor support for Salesforce. Let’s cover how with a dose of Generative AI, it is possible to write Playwright tests for Salesforce that incorporate some of the natural language aspects of Robot Framework.
Challenges with using Playwright
Even though Playwright is a popular and well-supported testing framework, it’s historically been quite difficult to make it work when testing Salesforce applications. This has to do with the underlying complexity of Salesforce’s Lightning component framework, which is used by both the Salesforce platform itself, as well as custom applications running in the Salesforce ecosystem.
Shadow DOM. These architectural choices all contribute to making it incredibly difficult to target elements on the page
using CSS/XPath selectors. Further, because Salesforce is a closed ecosystem, you often can’t add
other markup to make it easier for test automation to locate elements.
This is unfortunate, because Playwright has some nice benefits over Robot Framework:
- Playwright has first-class IDE support, including well-supported plugins for VSCode.
- Playwright includes its own Test Runner, which provides a lot of convenience functions for building tests and lots of options for viewing test results.
Writing Salesforce tests with Playwright + AI
Using the new ZeroStep AI library for Playwright, we can execute actions and assertions in Playwright in natural language, while still having the flexibility of a code-first workflow.
Below is a complete Playwright test that uses ZeroStep’s
ai() function to create a new Opportunity within the
Salesforce Sales app:
As you can see, this examples uses both built-in Playwright functions (
page.goto) and the
ai() function to drive the browser and create an Opportunity in Salesforce.
Here’s how the
ai() function works:
- The “prompt” passed in the
ai()function is sent to the ZeroStep backend, along with metadata about the current state of the page
- The ZeroStep AI first determines whether the prompt is one of the following types:
- Action: Executes one or more actions in the web browser (e.g.
Click on the Stage dropdown)
- Assertion: Evaluates the prompt as a boolean operation (e.g.
Assert that the current stage is "Needs Analysis")
- Query: Answers a question about the state of the application (e.g.
What is the current stage of the opportunity?)
- The library executes those actions as Playwright commands.
- If the prompt was evaluated as an assertion or query, the ZeroStep AI returns the true/false response or answer to the question.
Thanks for reading, and happy testing!