diff --git a/lib/WebDriver/AbstractWebDriver.php b/lib/WebDriver/AbstractWebDriver.php index a0e2122..210bc00 100644 --- a/lib/WebDriver/AbstractWebDriver.php +++ b/lib/WebDriver/AbstractWebDriver.php @@ -154,69 +154,6 @@ protected function serializeArguments(array $arguments) return $arguments; } - /** - * Unserialize result (containing web elements and/or shadow roots) - * - * @param mixed $result - * - * @return mixed - */ - protected function unserializeResult($result) - { - $element = is_array($result) ? $this->makeElement($result) : null; - - if ($element !== null) { - return $element; - } - - if (is_array($result)) { - foreach ($result as $key => $value) { - $result[$key] = $this->unserializeResult($value); - } - } - - return $result; - } - - /** - * Factory method for elements - * - * @param array $value - * - * @return \WebDriver\Element|\WebDriver\Shadow|null - */ - protected function makeElement($value) - { - if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, $value)) { - $identifier = $value[LegacyElement::LEGACY_ELEMENT_ID]; - - return new LegacyElement( - $this->getIdentifierPath('/element/' . $identifier), - $identifier - ); - } - - if (array_key_exists(Element::WEB_ELEMENT_ID, $value)) { - $identifier = $value[Element::WEB_ELEMENT_ID]; - - return new Element( - $this->getIdentifierPath('/element/' . $identifier), - $identifier - ); - } - - if (array_key_exists(Shadow::SHADOW_ROOT_ID, $value)) { - $identifier = $value[Shadow::SHADOW_ROOT_ID]; - - return new Shadow( - $this->getIdentifierPath('/shadow/' . $identifier), - $identifier - ); - } - - return null; - } - /** * Curl request to webdriver server. * diff --git a/lib/WebDriver/Element.php b/lib/WebDriver/Element.php index d572834..b586d59 100644 --- a/lib/WebDriver/Element.php +++ b/lib/WebDriver/Element.php @@ -112,7 +112,7 @@ public function getID() /** * Get the value of an element's attribute: /session/:sessionId/element/:id/attribute/:name * - * @param string name + * @param string $name * * @return mixed */ diff --git a/lib/WebDriver/Execute.php b/lib/WebDriver/Execute.php index 2932981..0cb9815 100644 --- a/lib/WebDriver/Execute.php +++ b/lib/WebDriver/Execute.php @@ -58,6 +58,69 @@ public function sync(array $jsonScript) return $this->unserializeResult($result['value']); } + /** + * Unserialize result (containing web elements and/or shadow roots) + * + * @param mixed $result + * + * @return mixed + */ + protected function unserializeResult($result) + { + $element = is_array($result) ? $this->makeElement($result) : null; + + if ($element !== null) { + return $element; + } + + if (is_array($result)) { + foreach ($result as $key => $value) { + $result[$key] = $this->unserializeResult($value); + } + } + + return $result; + } + + /** + * Factory method for elements + * + * @param array $value + * + * @return \WebDriver\Element|\WebDriver\Shadow|null + */ + protected function makeElement($value) + { + if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, $value)) { + $identifier = $value[LegacyElement::LEGACY_ELEMENT_ID]; + + return new LegacyElement( + $this->getIdentifierPath('/element/' . $identifier), + $identifier + ); + } + + if (array_key_exists(Element::WEB_ELEMENT_ID, $value)) { + $identifier = $value[Element::WEB_ELEMENT_ID]; + + return new Element( + $this->getIdentifierPath('/element/' . $identifier), + $identifier + ); + } + + if (array_key_exists(Shadow::SHADOW_ROOT_ID, $value)) { + $identifier = $value[Shadow::SHADOW_ROOT_ID]; + + return new Shadow( + $this->getIdentifierPath('/shadow/' . $identifier), + $identifier + ); + } + + return null; + } + /** * {@inheritdoc} */ diff --git a/lib/WebDriver/Session.php b/lib/WebDriver/Session.php index f149b8d..39f3a95 100644 --- a/lib/WebDriver/Session.php +++ b/lib/WebDriver/Session.php @@ -158,7 +158,7 @@ public function open($url) */ public function capabilities() { - if (! isset($this->capabilities)) { + if ($this->capabilities === null) { $result = $this->curl('GET', ''); $this->capabilities = $result['value'];