Step-by-Step: Setup Playforce

1. Installation

Prerequisites

Node.js installed

Playwright installed and configured

Install Playforce via NPM
npm install playforce

2. Obtain your Playforce License

See licensing for further information

3. Set Environment Variables

Configure the required environment variables either directly in your shell or by adding them to a .env file in your project root (if your setup supports it).

set SALESFORCE_TOKEN_URL=https://login.salesforce.com/services/oauth2/token
set SALESFORCE_CONSUMER_KEY=<your consumer key here>
set SALESFORCE_CONSUMER_SECRET=<your consumer secret here>
set SALESFORCE_API_VERSION=59.0 (optional override. Default will be what Salesforce returns)
set PLAYFORCE_LICENSE=<your emailed playforce license here>

4. Create Playwright Global Setup

Create a file named global-setup.ts in your project root and add the following code:

// global-setup.ts - Connects to Salesforce and gets an Access Token
import { FullConfig } from "@playwright/test";
import { getSalesforceToken } from "playforce";

export default async function globalSetup(config: FullConfig) {
  await getSalesforceToken();  
}

In your playwright.config.ts, add the following to include the global setup script:

export default defineConfig({
  globalSetup: ['./global-setup'],
  // ... other settings
});

5. Congratulations

✅ You are all set!

Run your Playwright tests using a command like:

npx playwright test

Next Steps - Generate Salesforce Object Definition and API Files