Skip to content

Commit 545e8b3

Browse files
cryptiklemurdunglas
authored andcommitted
Allowing customization of host and port for ChromeManager (symfony#22)
* Allowing customization of host and port for ChromeManager * Update ChromeManager.php * Update ChromeManager.php * Update ChromeManager.php * Style fixes * Removing ?
1 parent 8d5cf62 commit 545e8b3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/ProcessManager/ChromeManager.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ final class ChromeManager implements BrowserManagerInterface
2828

2929
private $process;
3030
private $arguments;
31+
private $options;
3132

32-
public function __construct(?string $chromeDriverBinary = null, ?array $arguments = null)
33+
public function __construct(?string $chromeDriverBinary = null, ?array $arguments = null, array $options = [])
3334
{
3435
$this->process = new Process([$chromeDriverBinary ?? $this->findChromeDriverBinary()], null, null, null, null);
3536
$this->arguments = $arguments ?? $this->getDefaultArguments();
37+
$this->options = \array_merge($this->getDefaultOptions(), $options);
3638
}
3739

3840
/**
@@ -42,10 +44,11 @@ public function __construct(?string $chromeDriverBinary = null, ?array $argument
4244
*/
4345
public function start(): WebDriver
4446
{
47+
$url = $this->options['scheme'].'://'.$this->options['host'].':'.$this->options['port'];
4548
if (!$this->process->isRunning()) {
46-
$this->checkPortAvailable('127.0.0.1', 9515);
49+
$this->checkPortAvailable($this->options['host'], $this->options['port']);
4750
$this->process->start();
48-
$this->waitUntilReady($this->process, 'http://127.0.0.1:9515/status');
51+
$this->waitUntilReady($this->process, $url.$this->options['path']);
4952
}
5053

5154
$capabilities = DesiredCapabilities::chrome();
@@ -55,7 +58,7 @@ public function start(): WebDriver
5558
$capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
5659
}
5760

58-
return RemoteWebDriver::create('http://localhost:9515', $capabilities);
61+
return RemoteWebDriver::create($url, $capabilities);
5962
}
6063

6164
public function quit(): void
@@ -89,4 +92,14 @@ private function getDefaultArguments(): array
8992

9093
return $args;
9194
}
95+
96+
private function getDefaultOptions(): array
97+
{
98+
return [
99+
'scheme' => 'http',
100+
'host' => '127.0.0.1',
101+
'port' => 9515,
102+
'path' => '/status',
103+
];
104+
}
92105
}

0 commit comments

Comments
 (0)