Thanksgiving Week Special – Get 50% OFF on FileTranz
Claim Your OfferDiscover why persistent browser profiles speed up local Playwright testing but fail in CI/CD environments. Learn the limitations and better alternatives.
If you've ever tested a Salesforce integration, you know the pain. Every single test run means:
Multiply that by dozens of tests running in parallel, and you're looking at a significant chunk of your test execution time just sitting at the login screen. That's where I started looking into persistent browser profiles—and honestly, it made a noticeable difference during local development.
Think of it like this: you know how your personal Chrome or Firefox browser stays logged into Gmail, GitHub, and all your usual sites? That's because your browser stores your login session, cookies, and authentication tokens in a local profile directory.
Playwright can do the same thing.
Instead of destroying and recreating the browser context for every test (which wipes out all session data), you can tell Playwright to use a folder on disk that persists between runs. The first time you run your tests, Playwright logs in normally. But on subsequent runs, it reuses that saved profile—so the browser opens already logged in. No login page. No waiting.
The setup is straightforward:
Step 1: Create a Profile Directory
Typescript
const userDataDir: string = './salesforce-profile';Step 2: Launch Playwright with the Profile
Typescript
const browser = await chromium.launchPersistentContext(userDataDir, {
headless: false, // Use headed mode to see what is happening
args: ['--disable-sync'], // Disable Chrome sync to avoid interference
});Step 3: Log In Once (and Only Once)
Typescript
const page = await browser.newPage();
await page.goto('https://yourcompany.my.salesforce.com');
// Complete your normal SSO and MFA flow here
// ... (same login steps as usual)
// Close the browser — the profile is now saved
await browser.close();Step 4: Reuse on the Next Run
Typescript
import { chromium } from '@playwright/test';
const userDataDir: string = './salesforce-profile';
// Use the same userDataDir
// The browser opens with the existing session
const browser = await chromium.launchPersistentContext(userDataDir, {
headless: false,
});
const page = await browser.newPage();
await page.goto('https://yourcompany.my.salesforce.com');
// You're already logged in!When I was building and debugging test scenarios, persistent profiles were a genuine time-saver:
Faster iteration: I could tweak a test, re-run it, and jump straight into testing without watching the login dance again. This was huge for my productivity when I was writing new scenarios.
Better debugging experience: Sometimes you need to step through a test, inspect the page, and restart. With a persistent profile, you don't lose your Salesforce session in the middle of debugging. You can pause, take a breath, and continue exactly where you left off.
Realistic browser behavior: It felt like using Salesforce normally. My automation wasn't constantly getting surprised by the authentication flow—it was behaving like a real user who stays logged in across browser sessions.
One-off testing: For manual validation or one-off test runs on my own machine, this approach was perfect. No overhead, no complexity.
Here's where my excitement took a hit. The moment I started thinking about using this in a CI/CD pipeline or sharing it with the team, the issues piled up:
It's machine-specific: The profile is tied to one computer. If you commit it to Git and someone else checks it out, it won't work—the authentication tokens are locked to their machine's browser. Team collaboration becomes a nightmare.
Security nightmare: That profile directory contains active authentication tokens, session cookies, and cached data. Checking it into version control? Absolutely not. Storing it on a shared drive? You'd be exposing sensitive credentials to anyone with access. Plus, if it gets compromised, you're potentially giving someone authenticated access to Salesforce.
Cache corruption and staleness: Over time, the browser cache grows. I noticed occasional weird behavior—pages not loading correctly, outdated assets, inconsistent test results. The cache doesn't have a built-in cleanup mechanism, so it can become a source of flaky tests.
Salesforce still controls the session: Just because you have a saved profile doesn't mean Salesforce won't expire your session. If the server decides your session is stale (which can happen based on time, IP changes, or security policies), that persistent profile becomes useless. The tests would fail, and you'd still need a fallback authentication strategy.
Parallel execution is off the table: Running multiple tests in parallel with the same profile directory causes race conditions. Browsers stepping on each other's toes. Profile corruption. Flaky, unpredictable failures. This killed any hope of using it in a CI environment where tests run in parallel.
After stepping back and thinking about this experiment, I realized:
Persistent profiles have a place—it's just not in production automation. They're fantastic for local development and debugging. If you need to quickly test something on your own machine without the login friction, go for it.
But for team automation and CI environments, you need something more robust, shareable, and secure. Something that doesn't depend on a machine-specific profile sitting on someone's drive.
That's why our team settled on a different approach: saved authentication state (which I already covered in another Blog). It gives you the speed benefits of persistent profiles—no repeated login flows—without the security risks, environment dependency, and parallel execution headaches.
The persistent profile isn't something we abandoned entirely. It's just a tool I grab when I'm developing locally or troubleshooting an issue in real-time. But for the actual automation framework that runs across environments and CI pipelines? State is the way.