A single-test Playwright project that automatically creates a new Account record in any Salesforce org.
Playwright is an excellent choice for automating Salesforce tests, and one of its great advantages is built-in test script recording and code generation. <u>This means you don't have to write test code manually from scratch.</u>
- Record actions as you interact with the browser normally
- Auto-generate JavaScript test code from your recordings
- Prototype tests faster without writing code by hand
- Great for Salesforce Developers/QA Engineers who want to build tests quickly
This repository includes a ready-to-use account creation test script that you can:
- β Run immediately to test your Salesforce org
- β Learn from to understand Playwright test structure
- β Modify and extend for your own testing scenarios
If you want to record your own test scripts instead of writing them manually, refer to the Recording commands section below for the npx playwright codegen commands.
| Step | Action |
|---|---|
| 1 | Opens a real Chromium browser (visible on screen) |
| 2 | Logs in to Salesforce with your credentialsor a session URL |
| 3 | Detects MFA / verification-code screens andpauses so you can enter the code |
| 4 | Navigates to theAccounts tab |
| 5 | ClicksNew β Standard and fills in a randomly-generated account name, phone, and US billing address |
| 6 | Saves the record and confirms it was created |
| 7 | Shows a green success banner and takes a final screenshot |
| 8 | Generates a fullHTML report with screenshots and a video recording |
| Tool | Minimum version | How to check |
|---|---|---|
| Node.js | 18 LTS | node -v |
Installing Node.js β download the LTS installer from https://nodejs.org and run it. After installation open a new terminal and verify with
node -v.
Open .env in any text editor and choose one of the two login options.
SF_LOGIN_URL=https://login.salesforce.com
SF_USERNAME=your_username@example.com
SF_PASSWORD=YourPassword
SF_SESSION_URL=
SF_HOME_URL=For a Sandbox org use
SF_LOGIN_URL=https://test.salesforce.com
If you have a Salesforce session ID, you can use this format:
SF_SESSION_URL=https://<your_instance_url>/secur/frontdoor.jsp?sid=<session_id>&retURL=<optional_target_page>
SF_USERNAME=
SF_PASSWORD=When SF_SESSION_URL is set, the username/password fields are ignored.
# 1. Enter the project folder
cd sf-account-automation
# 2. Install Node dependencies
npm install
# 3. Install Playwright + Chromium browser
npx playwright install chromium
# 4. Run the test
npm run testAccountSpecAn HTML report will open automatically in your browser when the test finishes.
Salesforce sometimes asks for an email verification code The test detects this automatically and pauses:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
VERIFICATION CODE REQUIRED β ACTION NEEDED IN BROWSER
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Check your email/phone for the Salesforce verification code.
2. Type the code into the browser window that just opened.
3. Click the "Verify" button.
The test will wait up to 5 minutesβ¦
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Look at the Chromium browser window that opened on screen.
- Check your email or phone, enter the 6-digit code, and click Verify.
- The test detects the page change and continues automatically.
| Package | Version | Purpose |
|---|---|---|
@playwright/test |
^1.44 | Test framework + Chromium browser driver |
dotenv |
^16 | Load credentials from .env without hard-coding them |
Playwright bundles its own Chromium browser β you do not need to install Chrome separately. The
npx playwright install chromiumcommand downloads the correct Chromium build for your OS.
| Command | What it does |
|---|---|
npm install |
Installs Node dependencies |
npx playwright install chromium |
Downloads the Chromium browser |
npm run testAccountSpec |
Runs the account creation test |
npm run test:report |
Re-opens the HTML report |
npx playwright codegen |
Opens the Playwright Inspector to record and generate test code |
npx playwright codegen <URL> |
Record tests for a specific URL |
If you'd like to record your own test scripts instead of writing them manually, use these commands:
npx playwright codegenThis opens the Playwright Inspector with a blank browser. You can then:
- Navigate and interact with any website
- Watch your actions generate as test code in real-time
- Copy or save the generated JavaScript code
npx playwright codegen https://login.salesforce.comThis launches the Inspector pointing to your Salesforce login URL. Great for:
- Recording login workflows
- Capturing custom Salesforce automation flows
- Learning Playwright syntax by example
- Quickly prototyping new test scenarios before adding them to your project
The generated code can then be copied into your test files and modified as needed!