-
Notifications
You must be signed in to change notification settings - Fork 845
/
DriverCommandExecutor.php
53 lines (46 loc) · 1.39 KB
/
DriverCommandExecutor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Facebook\WebDriver\Remote\Service;
use Facebook\WebDriver\Exception\Internal\DriverServerDiedException;
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DriverCommand;
use Facebook\WebDriver\Remote\HttpCommandExecutor;
use Facebook\WebDriver\Remote\WebDriverCommand;
use Facebook\WebDriver\Remote\WebDriverResponse;
/**
* A HttpCommandExecutor that talks to a local driver service instead of a remote server.
*/
class DriverCommandExecutor extends HttpCommandExecutor
{
/**
* @var DriverService
*/
private $service;
public function __construct(DriverService $service)
{
parent::__construct($service->getURL());
$this->service = $service;
}
/**
* @throws \Exception
* @throws WebDriverException
* @return WebDriverResponse
*/
public function execute(WebDriverCommand $command)
{
if ($command->getName() === DriverCommand::NEW_SESSION) {
$this->service->start();
}
try {
$value = parent::execute($command);
if ($command->getName() === DriverCommand::QUIT) {
$this->service->stop();
}
return $value;
} catch (\Exception $e) {
if (!$this->service->isRunning()) {
throw new DriverServerDiedException($e);
}
throw $e;
}
}
}