Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public function withHost(?string $host): self
return $this;
}

/**
* Sets the URL of an already-running Playwright server (e.g. http://192.168.1.100:9999).
* When set, the plugin connects to this server instead of starting a local one.
*/
public function withPlaywrightServer(?string $serverUrl): self
{
Playwright::setPlaywrightServerUrl($serverUrl);

return $this;
}

/**
* Enables debug mode for assertions.
*/
Expand Down
22 changes: 22 additions & 0 deletions src/Playwright/Playwright.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ final class Playwright
*/
private static ?string $host = null;

/**
* The URL of an already-running Playwright server (e.g. http://192.168.1.100:9999).
* When set, the plugin connects to this server instead of starting a local one.
*/
private static ?string $playwrightServerUrl = null;

/**
* Get a browser factory for the given browser type.
*/
Expand Down Expand Up @@ -155,6 +161,22 @@ public static function host(): ?string
return self::$host;
}

/**
* Set the URL of an external already-running Playwright server.
*/
public static function setPlaywrightServerUrl(?string $serverUrl): void
{
self::$playwrightServerUrl = $serverUrl;
}

/**
* Get the URL of the external Playwright server, if set.
*/
public static function playwrightServerUrl(): ?string
{
return self::$playwrightServerUrl ?? getenv('PEST_BROWSER_PLAYWRIGHT_URL') ?: null;
}

/**
* Get the default color scheme.
*/
Expand Down
11 changes: 10 additions & 1 deletion src/ServerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public static function instance(): self
*/
public function playwright(): PlaywrightServer
{
$serverUrl = Playwright::playwrightServerUrl();
if ($serverUrl) {
$parts = parse_url($serverUrl);
$host = $parts['host'];
$port = $parts['port'] ?? 9999;
AlreadyStartedPlaywrightServer::persist($host, $port);
return $this->playwright ??= new AlreadyStartedPlaywrightServer($host, $port);
}

if (Parallel::isWorker()) {
return AlreadyStartedPlaywrightServer::fromPersisted();
}
Expand Down Expand Up @@ -83,7 +92,7 @@ public function playwright(): PlaywrightServer
*/
public function http(): HttpServer
{
return $this->http ??= match (function_exists('app_path')) {
return $this->http ??= match (class_exists(\Illuminate\Foundation\Application::class)) {
true => new LaravelHttpServer(
self::DEFAULT_HOST, // Always bind to 127.0.0.1 for server
Port::find(),
Expand Down