Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions cli/src/commands/wheels/playwright/init.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Initialize Playwright for end-to-end testing
*
* This command wraps `npx create-playwright` to set up Playwright testing
* in your Wheels application.
*
* The command runs interactively and will ask you a few questions:
* - Language preference (TypeScript or JavaScript)
* - Where to put your tests
* - Whether to add GitHub Actions workflow
* - Whether to install Playwright browsers (default: NO, do this manually)
*
* {code:bash}
* wheels playwright:init
* {code}
*
* Note: Browser installation is skipped by default due to Playwright webkit
* requiring macOS 14+. After setup, run:
* {code:bash}
* wheels playwright install
* {code}
*/
component aliases="wheels playwright:init, wheels playwright init" extends="../base" {

property name="detailOutput" inject="DetailOutputService@wheels-cli";

function run() {
try {
requireWheelsApp(getCWD());

detailOutput.header("Playwright Setup");

if (!isNodeAvailable()) {
detailOutput.error("Node.js is required. Please install Node.js first.");
print.line("Visit https://nodejs.org to download and install Node.js");
setExitCode(1);
return;
}

runInteractive();

} catch (any e) {
detailOutput.error("Setup failed: #e.message#");
setExitCode(1);
}
}

private boolean function isNodeAvailable() {
try {
command("!node -v").run();
return true;
} catch (any e) {
return false;
}
}

private void function runInteractive() {
detailOutput.output("Launching Playwright setup wizard...")
.line();
print.cyanLine("This will initialize Playwright with interactive prompts.")
.line();
print.cyanLine("The wizard will ask you about:");
print.cyanLine(" - TypeScript or JavaScript");
print.cyanLine(" - Test directory location");
print.cyanLine(" - GitHub Actions setup");
print.cyanLine(" - Browser installation (answer NO - use 'wheels playwright install' instead)")
.line();

var confirmed = ask(("Proceed with Playwright setup? [y/n]"));
if (lCase(trim(confirmed)) != "y") {
detailOutput.output("Operation cancelled by user.");
return;
}

detailOutput.line();
detailOutput.output("Running: npx create-playwright");
detailOutput.line();

try {
command("!npx create-playwright").run();

detailOutput.success("Playwright setup complete!");
detailOutput.line();
detailOutput.nextSteps([
"Install browsers: wheels playwright install",
"Run tests: npx playwright test",
"Open UI mode: npx playwright test --ui"
]);

} catch (any e) {
var errorMsg = e.message;
detailOutput.error("Playwright setup failed: #errorMsg#");
detailOutput.line();

if (findNoCase("webkit", errorMsg) || findNoCase("does not support", errorMsg)) {
print.cyanLine("This usually happens when webkit fails to install on older macOS versions.")
.line();
}

detailOutput.output("To complete setup without browser installation:")
.line();
print.greenLine(" wheels playwright install")
.line();

setExitCode(1);
}
}
}
141 changes: 141 additions & 0 deletions cli/src/commands/wheels/playwright/install.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Install Playwright browsers
*
* Use this command after running `wheels playwright:init` if:
* - Browser installation failed during the wizard
* - You need to install specific browsers
*
* {code:bash}
* wheels playwright install
* {code}
*
* Install specific browsers:
* {code:bash}
* wheels playwright install --chromium --firefox
* {code}
*
* Note: On macOS 13 or earlier, webkit will be skipped automatically
* as it requires macOS 14+.
*/
component aliases="wheels playwright:install, wheels playwright install" extends="../base" {

property name="detailOutput" inject="DetailOutputService@wheels-cli";

/**
* @chromium Install Chromium browser (default: true)
* @firefox Install Firefox browser (default: true)
* @webkit Install Webkit browser (default: false, macOS 14+ only)
*/
function run(
boolean chromium = true,
boolean firefox = true,
boolean webkit = false
) {
try {
requireWheelsApp(getCWD());

detailOutput.header("Playwright Browser Installation");

if (!isNodeAvailable()) {
detailOutput.error("Node.js is required. Please install Node.js first.");
print.line("Visit https://nodejs.org to download and install Node.js");
setExitCode(1);
return;
}

var browsers = [];
if (arguments.chromium) {
arrayAppend(browsers, "chromium");
}
if (arguments.firefox) {
arrayAppend(browsers, "firefox");
}
if (arguments.webkit) {
if (isMacOS13OrEarlier()) {
detailOutput.statusWarning("Webkit requires macOS 14+. Skipping webkit installation.");
} else {
arrayAppend(browsers, "webkit");
}
}

if (arrayIsEmpty(browsers)) {
detailOutput.output("No browsers selected for installation.")
.line();
return;
}

detailOutput.output("Installing browsers: " & arrayToList(browsers, ", "))
.line();

local.browserList = browsers.toList(" ");
detailOutput.output("Running: npx playwright install #local.browserList#")
.line();

try {
command("!npx playwright install #local.browserList#").run();

detailOutput.success("Playwright browsers installed successfully!");
detailOutput.nextSteps([
"Run tests: npx playwright test",
"Open UI mode: npx playwright test --ui"
]);

} catch (any e) {
handleInstallError(e);
}

} catch (any e) {
detailOutput.error("Installation failed: #e.message#");
setExitCode(1);
}
}

private boolean function isNodeAvailable() {
try {
command("!node -v").run();
return true;
} catch (any e) {
return false;
}
}

private boolean function isMacOS13OrEarlier() {
try {
var result = command("!sw_vers -productVersion").run(returnOutput=true);
var version = trim(result);

var major = listFirst(version, ".");
var minor = 0;
if (listLen(version, ".") >= 2) {
minor = listGetAt(version, 2, ".");
}

if (major < 14) {
return true;
}
return false;
} catch (any e) {
return false;
}
}

private void function handleInstallError(required any e) {
var errorMsg = arguments.e.message;

if (findNoCase("webkit", errorMsg) && findNoCase("macOS", errorMsg)) {
detailOutput.error("Webkit installation failed: requires macOS 14+");
detailOutput.line();
detailOutput.output("To install only Chromium and Firefox:");
detailOutput.output(" wheels playwright install --chromium --firefox")
.line();
} else if (findNoCase("does not support", errorMsg)) {
detailOutput.error("Browser installation failed due to system compatibility.");
detailOutput.line();
print.cyanLine("Tip: Check https://playwright.dev/docs/browsers for system requirements.");
} else {
detailOutput.error("Browser installation failed: #errorMsg#");
}

setExitCode(1);
}
}
5 changes: 4 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
* Testing Commands
* [wheels test run](command-line-tools/commands/test/test-run.md)
* [wheels advanced testing](command-line-tools/commands/test/test-advanced.md)
* Playwright Commands
* [wheels playwright:init](command-line-tools/commands/playwright/playwright-init.md)
* [wheels playwright:install](command-line-tools/commands/playwright/playwright-install.md)
* Environment Management
* [wheels env setup](command-line-tools/commands/environment/env-setup.md)
* [wheels env list](command-line-tools/commands/environment/env-list.md)
Expand Down Expand Up @@ -214,4 +217,4 @@

* [Installing and Using Plugins](plugins/installing-and-using-plugins.md)
* [Developing Plugins](plugins/developing-plugins.md)
* [Publishing Plugins](plugins/publishing-plugins.md)
* [Publishing Plugins](plugins/publishing-plugins.md)
10 changes: 10 additions & 0 deletions docs/src/command-line-tools/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ Commands for running and managing tests.
- **`wheels test watch`** - Rerun tests on any change
[Documentation](test/test-advanced.md)

## Playwright Commands

Commands for end-to-end testing with Playwright.

- **`wheels playwright:init`** (alias: `wheels playwright init`) - Initialize Playwright project
[Documentation](playwright/playwright-init.md)

- **`wheels playwright:install`** (alias: `wheels playwright install`) - Install Playwright browsers
[Documentation](playwright/playwright-install.md)

## Environment Management

Commands for managing development environments and application context.
Expand Down
Loading
Loading