| description | Writing Playwright tests (*.spec.ts) |
|---|
Check playwright ext for reuse before creating utilities/PageObjects
One test per file. Many steps allowed.
- Never
waitForTimeout- wait for specific page elements page.waitForSelector()- elements appearexpect(locator).toBeVisible()- visibilitypage.waitForLoadState()- page state changes- Don't use
page.waitForResponse()- doesn't work in desktop/electron - Don't use
networkidle- not available on desktop/electron - Use
test.stepto organize sequential tests
NEVER use Node.js fs/path or VS Code API - desktop only, not web
Use UI interactions:
- Quick Open:
@salesforce/playwright-vscode-extopenFileByName— palette "Go to File…" (web + desktop); VS Code 1.116+ rows oftenbasename+ segments + trailingfile results— match logicpackages/playwright-vscode-ext/src/utils/fileHelpers.ts Control+Home,Control+s- navigate and savepage.keyboard.type()- edit content- Monaco editor selectors - interact with editor
Tests must work identically in web and desktop.
- Virtual
folderPathmount: Nodefsdoes not see project files; usefolderUri(file://…) or.vscode/vscode-extension-test-disk-root.txt(disk root) when services must resolveSfProject— see JSDoc onpackages/playwright-vscode-ext/src/web/createHeadlessServer.ts - Load extra extensions via
additionalExtensionDirs(e.g. metadata for LWC create). WebheadlessServer+ desktop fixture: emptylwc/+ CustomLabels + emptysnippetsE2E(snippet specs); other bundles via SFDX: Create Lightning Web Component. - LWC LSP ready (
waitForLwcLspReadyinsalesforcedx-vscode-lwctest/playwright/utils/lwcUtils.ts): web —LWC Extensionoutput lineLWC Language Server: indexing complete; desktop — Editor Language Status / legacy status textIndexing complete(language status item often missing on web)
VS Code API (tree views, editors, output panels) only contains visible DOM lines (rest not present until scrolled into view).
- Don't rely on
scrollTo- target element won't exist scrollIntoViewIfNeededprobably won't help
No way to read/interact with context menus (right click) on mac+Desktop+electron. Tests/steps must skip themselves. Windows and Web are fine.
- Prefer
aria(getByRole) over css selectors expectassertions need clear error messages. Importexpectfrom playwright- Fail early, avoid fallbacks/retries
- Reusable locators belong in
locators.ts- check before creating new ones
- Use
f1for commands, not meta-shift-P - Use
Controlfor all. No ControlOrMeta
Prefer package.nls.json for command titles instead of hardcoded strings.
- Protects tests when command labels change or are localized
- Pattern:
import packageNls from '../../../package.nls.json'(adjust path for package root) - Use for
executeCommandWithCommandPalette,executeExplorerContextMenuCommand,executeEditorContextMenuCommand,verifyCommandExists, andwaitForOutputChannelTextexpectedText (e.g.Ended ${packageNls.deploy_this_source_text})