|
15 | 15 |
|
16 | 16 | namespace Facebook\WebDriver\Chrome; |
17 | 17 |
|
| 18 | +use Facebook\WebDriver\Exception\WebDriverException; |
18 | 19 | use Facebook\WebDriver\Remote\DesiredCapabilities; |
19 | 20 | use Facebook\WebDriver\Remote\DriverCommand; |
20 | | -use Facebook\WebDriver\Remote\Service\DriverCommandExecutor; |
21 | | -use Facebook\WebDriver\Exception\WebDriverException; |
22 | 21 | use Facebook\WebDriver\Remote\RemoteWebDriver; |
| 22 | +use Facebook\WebDriver\Remote\Service\DriverCommandExecutor; |
23 | 23 | use Facebook\WebDriver\Remote\WebDriverCommand; |
24 | 24 |
|
25 | | -class ChromeDriver extends RemoteWebDriver { |
| 25 | +class ChromeDriver extends RemoteWebDriver |
| 26 | +{ |
| 27 | + public static function start(DesiredCapabilities $desired_capabilities = null, ChromeDriverService $service = null) |
| 28 | + { |
| 29 | + if ($desired_capabilities === null) { |
| 30 | + $desired_capabilities = DesiredCapabilities::chrome(); |
| 31 | + } |
| 32 | + if ($service === null) { |
| 33 | + $service = ChromeDriverService::createDefaultService(); |
| 34 | + } |
| 35 | + $executor = new DriverCommandExecutor($service); |
| 36 | + $driver = new static(); |
| 37 | + $driver->setCommandExecutor($executor) |
| 38 | + ->startSession($desired_capabilities); |
26 | 39 |
|
27 | | - public static function start( |
28 | | - DesiredCapabilities $desired_capabilities = null, |
29 | | - ChromeDriverService $service = null |
30 | | - ) { |
31 | | - if ($desired_capabilities === null) { |
32 | | - $desired_capabilities = DesiredCapabilities::chrome(); |
| 40 | + return $driver; |
33 | 41 | } |
34 | | - if ($service === null) { |
35 | | - $service = ChromeDriverService::createDefaultService(); |
36 | | - } |
37 | | - $executor = new DriverCommandExecutor($service); |
38 | | - $driver = new static(); |
39 | | - $driver->setCommandExecutor($executor) |
40 | | - ->startSession($desired_capabilities); |
41 | | - return $driver; |
42 | | - } |
43 | 42 |
|
44 | | - public function startSession($desired_capabilities) { |
45 | | - $command = new WebDriverCommand( |
46 | | - null, |
47 | | - DriverCommand::NEW_SESSION, |
48 | | - array( |
49 | | - 'desiredCapabilities' => $desired_capabilities->toArray(), |
50 | | - ) |
51 | | - ); |
52 | | - $response = $this->executor->execute($command); |
53 | | - $this->setSessionID($response->getSessionID()); |
54 | | - } |
| 43 | + public function startSession($desired_capabilities) |
| 44 | + { |
| 45 | + $command = new WebDriverCommand( |
| 46 | + null, |
| 47 | + DriverCommand::NEW_SESSION, |
| 48 | + array( |
| 49 | + 'desiredCapabilities' => $desired_capabilities->toArray(), |
| 50 | + ) |
| 51 | + ); |
| 52 | + $response = $this->executor->execute($command); |
| 53 | + $this->setSessionID($response->getSessionID()); |
| 54 | + } |
55 | 55 |
|
56 | | - /** |
57 | | - * Always throws an exception. Use ChromeDriver::start() instead. |
58 | | - * |
59 | | - * @throws WebDriverException |
60 | | - */ |
61 | | - public static function create( |
62 | | - $url = 'http://localhost:4444/wd/hub', |
63 | | - $desired_capabilities = null, |
64 | | - $connection_timeout_in_ms = null, |
65 | | - $request_timeout_in_ms = null, |
66 | | - $http_proxy = null, |
67 | | - $http_proxy_port = null |
68 | | - ) { |
69 | | - throw new WebDriverException('Please use ChromeDriver::start() instead.'); |
70 | | - } |
| 56 | + /** |
| 57 | + * Always throws an exception. Use ChromeDriver::start() instead. |
| 58 | + * |
| 59 | + * @throws WebDriverException |
| 60 | + */ |
| 61 | + public static function create( |
| 62 | + $url = 'http://localhost:4444/wd/hub', |
| 63 | + $desired_capabilities = null, |
| 64 | + $connection_timeout_in_ms = null, |
| 65 | + $request_timeout_in_ms = null, |
| 66 | + $http_proxy = null, |
| 67 | + $http_proxy_port = null |
| 68 | + ) { |
| 69 | + throw new WebDriverException('Please use ChromeDriver::start() instead.'); |
| 70 | + } |
71 | 71 |
|
72 | | - /** |
73 | | - * Always throws an exception. Use ChromeDriver::start() instead. |
74 | | - * |
75 | | - * @param string $session_id The existing session id |
76 | | - * @param string $url The url of the remote server |
77 | | - * |
78 | | - * @throws WebDriverException |
79 | | - */ |
80 | | - public static function createBySessionID( |
81 | | - $session_id, |
82 | | - $url = 'http://localhost:4444/wd/hub' |
83 | | - ) { |
84 | | - throw new WebDriverException('Please use ChromeDriver::start() instead.'); |
85 | | - } |
| 72 | + /** |
| 73 | + * Always throws an exception. Use ChromeDriver::start() instead. |
| 74 | + * |
| 75 | + * @param string $session_id The existing session id |
| 76 | + * @param string $url The url of the remote server |
| 77 | + * |
| 78 | + * @throws WebDriverException |
| 79 | + */ |
| 80 | + public static function createBySessionID( |
| 81 | + $session_id, |
| 82 | + $url = 'http://localhost:4444/wd/hub' |
| 83 | + ) { |
| 84 | + throw new WebDriverException('Please use ChromeDriver::start() instead.'); |
| 85 | + } |
86 | 86 | } |
0 commit comments