Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 9f3fc33

Browse files
committed
Process status response to RemoteStatus value object
1 parent 3e64169 commit 9f3fc33

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
55

66
### Added
77
- Experimental W3C WebDriver protocol support. The protocol will be used automatically when remote end (like Geckodriver, newer Chromedriver etc.) supports it.
8+
- `getStatus()` method of RemoteWebDriver to get information about remote-end readiness to create new sessions.
89

910
### Changed
1011
- Revert no longer needed workaround for Chromedriver bug [2943](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2943).

lib/Remote/RemoteStatus.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
// Copyright 2004-present Facebook. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Facebook\WebDriver\Remote;
17+
18+
/**
19+
* Represents status of remote end
20+
*
21+
* @see https://www.w3.org/TR/webdriver/#status
22+
*/
23+
class RemoteStatus
24+
{
25+
/** @var bool */
26+
protected $isReady;
27+
/** @var string */
28+
protected $message;
29+
/** @var array */
30+
protected $meta = [];
31+
32+
/**
33+
* @param bool $isReady
34+
* @param string $message
35+
*/
36+
protected function __construct($isReady, $message, array $meta = [])
37+
{
38+
$this->isReady = (bool) $isReady;
39+
$this->message = (string) $message;
40+
41+
$this->setMeta($meta);
42+
}
43+
44+
/**
45+
* @param array $responseBody
46+
* @return RemoteStatus
47+
*/
48+
public static function createFromResponse(array $responseBody)
49+
{
50+
$object = new static($responseBody['ready'], $responseBody['message'], $responseBody);
51+
52+
return $object;
53+
}
54+
55+
/**
56+
* The remote end's readiness state.
57+
* False if an attempt to create a session at the current time would fail.
58+
* However, the value true does not guarantee that a New Session command will succeed.
59+
*
60+
* @return bool
61+
*/
62+
public function isReady()
63+
{
64+
return $this->isReady;
65+
}
66+
67+
/**
68+
* An implementation-defined string explaining the remote end's readiness state.
69+
*
70+
* @return string
71+
*/
72+
public function getMessage()
73+
{
74+
return $this->message;
75+
}
76+
77+
/**
78+
* Arbitrary meta information specific to remote-end implementation.
79+
*
80+
* @return array
81+
*/
82+
public function getMeta()
83+
{
84+
return $this->meta;
85+
}
86+
87+
protected function setMeta(array $meta)
88+
{
89+
unset($meta['ready'], $meta['message']);
90+
91+
$this->meta = $meta;
92+
}
93+
}

lib/Remote/RemoteWebDriver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ public function takeScreenshot($save_as = null)
380380
return $screenshot;
381381
}
382382

383+
/**
384+
* Status returns information about whether a remote end is in a state in which it can create new sessions.
385+
*/
386+
public function getStatus()
387+
{
388+
$response = $this->execute(DriverCommand::STATUS);
389+
390+
return RemoteStatus::createFromResponse($response);
391+
}
392+
383393
/**
384394
* Construct a new WebDriverWait by the current WebDriver instance.
385395
* Sample usage:

tests/functional/RemoteWebDriverTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,20 @@ public function testShouldSaveScreenshotToFile()
271271

272272
unlink($screenshotPath);
273273
}
274+
275+
/**
276+
* @covers ::getStatus
277+
* @covers \Facebook\WebDriver\Remote\RemoteStatus
278+
* @group exclude-saucelabs
279+
* Status endpoint is not supported on Sauce Labs
280+
*/
281+
public function testShouldGetRemoteEndStatus()
282+
{
283+
$status = $this->driver->getStatus();
284+
285+
$this->assertInternalType('boolean', $status->isReady());
286+
$this->assertNotEmpty($status->getMessage());
287+
288+
$this->assertInternalType('array', $status->getMeta());
289+
}
274290
}

0 commit comments

Comments
 (0)