Skip to content

Commit 50204fa

Browse files
committed
add $session->isW3C() and flip the $legacy logic
1 parent 864ac32 commit 50204fa

File tree

6 files changed

+39
-42
lines changed

6 files changed

+39
-42
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ public function __call($name, $arguments)
295295
if (preg_match('/^(get|post|delete)/', $name, $matches)) {
296296
$requestMethod = strtoupper($matches[0]);
297297
$webdriverCommand = strtolower(substr($name, strlen($requestMethod)));
298-
$dontcare = getRequestMethod($webDriverCommand); // validation
298+
299+
$this->getRequestMethod($webdriverCommand); // validation
299300
} else {
300301
$webdriverCommand = $name;
301302
$requestMethod = $this->getRequestMethod($webdriverCommand);

lib/WebDriver/Container.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function __construct($url)
3232
{
3333
parent::__construct($url);
3434

35-
$locatorStrategy = new \ReflectionClass('WebDriver\LocatorStrategy');
35+
$locatorStrategy = new \ReflectionClass('WebDriver\LocatorStrategy');
36+
3637
$this->strategies = $locatorStrategy->getConstants();
3738
}
3839

lib/WebDriver/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static function factory($code, $message = null, $previousException = null
185185

186186
$errorDefinition = self::$errs[$code];
187187

188-
if (trim($message) === '') {
188+
if ($message === null || trim($message) === '') {
189189
$message = $errorDefinition[1];
190190
}
191191

lib/WebDriver/Service/CurlService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public function execute($requestMethod, $url, $parameters = null, $extraOptions
9999

100100
curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeaders);
101101

102-
$rawResult = trim(curl_exec($curl));
102+
$rawResult = curl_exec($curl);
103+
$rawResult = is_string($rawResult) ? trim($rawResult) : '';
103104

104105
$info = curl_getinfo($curl);
105106
$info['request_method'] = $requestMethod;

lib/WebDriver/Session.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Session extends Container
6060
/**
6161
* @var boolean
6262
*/
63-
private $legacy = null;
63+
private $w3c = null;
6464

6565
/**
6666
* {@inheritdoc}
@@ -114,6 +114,30 @@ protected function obsoleteMethods()
114114
);
115115
}
116116

117+
/**
118+
* Constructor
119+
*
120+
* @param string $url URL to Selenium server
121+
* @param array|null $capabilities
122+
*/
123+
public function __construct($url, $capabilities)
124+
{
125+
parent::__construct($url);
126+
127+
$this->capabilities = $capabilities;
128+
$this->w3c = !! $capabilities;
129+
}
130+
131+
/**
132+
* Is W3C webdriver?
133+
*
134+
* @return boolean
135+
*/
136+
public function isW3C()
137+
{
138+
return $this->w3c;
139+
}
140+
117141
/**
118142
* Open URL: /session/:sessionId/url (POST)
119143
* An alternative to $session->url($url);
@@ -228,7 +252,7 @@ public function deleteCookie($cookieName)
228252
*/
229253
public function getWindowHandle()
230254
{
231-
$result = $this->curl('GET', $this->legacy ? '/window_handle' : '/window');
255+
$result = $this->curl('GET', $this->w3c ? '/window' : '/window_handle');
232256

233257
return $result['value'];
234258
}
@@ -274,7 +298,7 @@ public function window()
274298
}
275299

276300
// chaining (with optional handle in $arg)
277-
return $this->legacy ? new LegacyWindow($this->url . '/window', $arg) : new Window($this->url . '/window', $arg);
301+
return $this->w3c ? new Window($this->url . '/window', $arg) : new LegacyWindow($this->url . '/window', $arg);
278302
}
279303

280304
/**
@@ -359,7 +383,7 @@ public function timeouts()
359383
$type = func_get_arg(0); // 'script', 'implicit', or 'pageLoad' (legacy: 'pageLoad')
360384
$timeout = func_get_arg(1); // timeout in milliseconds
361385

362-
$arg = $this->legacy ? array('type' => $type, 'ms' => $timeout) : array($type => $timeout);
386+
$arg = $this->w3c ? array($type => $timeout) : array('type' => $type, 'ms' => $timeout);
363387

364388
$this->curl('POST', '/timeouts', $arg);
365389

@@ -489,7 +513,7 @@ public function execute()
489513
{
490514
// execute script
491515
if (func_num_args() > 0) {
492-
$execute = $this->legacy ? new LegacyExecute($this->url) : new Execute($this->url . '/execute');
516+
$execute = $this->w3c ? new Execute($this->url . '/execute') : new LegacyExecute($this->url);
493517
$result = $execute->sync(func_get_arg(0));
494518

495519
return $result;
@@ -507,32 +531,12 @@ public function execute()
507531
*/
508532
public function execute_async()
509533
{
510-
$execute = $this->legacy ? new LegacyExecute($this->url) : new Execute($this->url . '/execute');
534+
$execute = $this->w3c ? new Execute($this->url . '/execute') : new LegacyExecute($this->url);
511535
$result = $execute->async(func_get_arg(0));
512536

513537
return $result;
514538
}
515539

516-
/**
517-
* Set capabilities
518-
*
519-
* @param array $capabilities
520-
*/
521-
public function setCapabilities($capabilities)
522-
{
523-
$this->capabilities = $capabilities;
524-
}
525-
526-
/**
527-
* Set legacy
528-
*
529-
* @param boolean $legacy
530-
*/
531-
public function setLegacy($legacy)
532-
{
533-
$this->legacy = $legacy;
534-
}
535-
536540
/**
537541
* {@inheritdoc}
538542
*/

lib/WebDriver/WebDriver.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class WebDriver extends AbstractWebDriver implements WebDriverInterface
2525
*/
2626
private $capabilities;
2727

28-
/**
29-
* @var boolean
30-
*/
31-
private $legacy;
32-
3328
/**
3429
* {@inheritdoc}
3530
*/
@@ -86,11 +81,8 @@ public function session($browserName = Browser::FIREFOX, $desiredCapabilities =
8681
}
8782

8883
$this->capabilities = isset($result['value']['capabilities']) ? $result['value']['capabilities'] : null;
89-
$this->legacy = ! $this->capabilities; // initially
9084

91-
$session = new Session($result['sessionUrl']);
92-
$session->setCapabilities($this->capabilities);
93-
$session->setLegacy($this->legacy);
85+
$session = new Session($result['sessionUrl'], $this->capabilities);
9486

9587
return $session;
9688
}
@@ -109,9 +101,7 @@ public function sessions()
109101
$sessions = array();
110102

111103
foreach ($result['value'] as $session) {
112-
$session = new Session($this->url . '/session/' . $session['id']);
113-
$session->setCapabilities($this->capabilities);
114-
$session->setLegacy($this->legacy);
104+
$session = new Session($this->url . '/session/' . $session['id'], $this->capabilities);
115105

116106
$sessions[] = $session;
117107
}

0 commit comments

Comments
 (0)