Skip to content

Commit e0d07cf

Browse files
committed
Refs #86 - set the w3c flag everywhere
1 parent 348cb6c commit e0d07cf

File tree

7 files changed

+53
-51
lines changed

7 files changed

+53
-51
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ abstract class AbstractWebDriver
5454
*/
5555
private $transientOptions;
5656

57+
/**
58+
* @var boolean
59+
*/
60+
private $w3c;
61+
5762
/**
5863
* Return array of supported method names and corresponding HTTP request methods
5964
*
@@ -74,11 +79,13 @@ protected function obsoleteMethods()
7479
/**
7580
* Constructor
7681
*
77-
* @param string $url URL to Selenium server
82+
* @param boolean $w3c Is w3c driver?
83+
* @param string $url URL to Selenium server
7884
*/
79-
public function __construct($url = 'http://localhost:4444/wd/hub')
85+
public function __construct($w3c, $url = 'http://localhost:4444/wd/hub')
8086
{
8187
$this->url = $url;
88+
$this->w3c = $w3c;
8289
}
8390

8491
/**
@@ -131,6 +138,16 @@ public function setTransientOptions($transientOptions)
131138
$this->transientOptions = is_array($transientOptions) ? $transientOptions : array();
132139
}
133140

141+
/**
142+
* Is w3c driver?
143+
*
144+
* @return boolean
145+
*/
146+
public function isW3c()
147+
{
148+
return $this->w3c;
149+
}
150+
134151
/**
135152
* Curl request to webdriver server.
136153
*

lib/WebDriver/Container.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ abstract class Container extends AbstractWebDriver
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function __construct($url = 'http://localhost:4444/wd/hub')
41+
public function __construct($w3c, $url = 'http://localhost:4444/wd/hub')
4242
{
43-
parent::__construct($url);
43+
parent::__construct($w3c, $url);
4444

4545
$locatorStrategy = new \ReflectionClass('WebDriver\LocatorStrategy');
4646
$this->strategies = $locatorStrategy->getConstants();
@@ -208,13 +208,15 @@ protected function webDriverElement($value)
208208
{
209209
if (array_key_exists(self::LEGACY_ELEMENT_ID, (array) $value)) {
210210
return new Element(
211+
$this->w3c,
211212
$this->getElementPath($value[self::LEGACY_ELEMENT_ID]), // url
212213
$value[self::LEGACY_ELEMENT_ID] // id
213214
);
214215
}
215216

216217
if (array_key_exists(self::WEBDRIVER_ELEMENT_ID, (array) $value)) {
217218
return new Element(
219+
$this->w3c,
218220
$this->getElementPath($value[self::WEBDRIVER_ELEMENT_ID]), // url
219221
$value[self::WEBDRIVER_ELEMENT_ID] // id
220222
);

lib/WebDriver/Element.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ protected function obsoleteMethods()
104104
/**
105105
* Constructor
106106
*
107-
* @param string $url URL
108-
* @param string $id element ID
107+
* @param boolean $w3c Is w3c?
108+
* @param string $url URL
109+
* @param string $id element ID
109110
*/
110-
public function __construct($url, $id)
111+
public function __construct($w3c, $url, $id)
111112
{
112-
parent::__construct($url);
113+
parent::__construct($w3c, $url);
113114

114115
$this->id = $id;
115116
}

lib/WebDriver/LegacyWindow.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ public function getHandle()
7878
/**
7979
* Constructor
8080
*
81-
* @param string $url URL
82-
* @param string $windowHandle Window handle
81+
* @param boolean $w3c Is W3C?
82+
* @param string $url URL
83+
* @param string $windowHandle Window handle
8384
*/
84-
public function __construct($url, $windowHandle)
85+
public function __construct($w3c, $url, $windowHandle)
8586
{
8687
$this->windowHandle = $windowHandle;
8788

88-
parent::__construct($url . '/' . $windowHandle);
89+
parent::__construct($w3c, $url . '/' . $windowHandle);
8990
}
9091
}

lib/WebDriver/Session.php

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@
6363
*/
6464
final class Session extends Container
6565
{
66-
/**
67-
* @var boolean
68-
*/
69-
private $w3c;
70-
7166
/**
7267
* @var array
7368
*/
@@ -237,7 +232,12 @@ public function deleteCookie($cookieName)
237232
*/
238233
public function window()
239234
{
240-
return new Window($this->url . '/window');
235+
// legacy window methods
236+
if ( ! $this->w3c) {
237+
return call_user_func_array(array($this, 'legacyWindow'), func_get_args());
238+
}
239+
240+
return new Window($this->w3c, $this->url . '/window');
241241
}
242242

243243
/**
@@ -267,7 +267,7 @@ public function legacyWindow()
267267
}
268268

269269
// chaining
270-
return new LegacyWindow($this->url . '/window', $arg);
270+
return new LegacyWindow($this->w3c, $this->url . '/window', $arg);
271271
}
272272

273273
/**
@@ -314,7 +314,7 @@ public function frame()
314314
}
315315

316316
// chaining
317-
return new Frame($this->url . '/frame');
317+
return new Frame($this->w3c, $this->url . '/frame');
318318
}
319319

320320
/**
@@ -347,7 +347,7 @@ public function timeouts()
347347
}
348348

349349
// chaining
350-
return new Timeouts($this->url . '/timeouts');
350+
return new Timeouts($this->w3c, $this->url . '/timeouts');
351351
}
352352

353353
/**
@@ -358,7 +358,7 @@ public function timeouts()
358358
*/
359359
public function ime()
360360
{
361-
return new Ime($this->url . '/ime');
361+
return new Ime($this->w3c, $this->url . '/ime');
362362
}
363363

364364
/**
@@ -383,7 +383,7 @@ public function activeElement()
383383
*/
384384
public function touch()
385385
{
386-
return new Touch($this->url . '/touch');
386+
return new Touch($this->w3c, $this->url . '/touch');
387387
}
388388

389389
/**
@@ -416,7 +416,7 @@ public function session_storage()
416416
*/
417417
public function application_cache()
418418
{
419-
return new ApplicationCache($this->url . '/application_cache');
419+
return new ApplicationCache($this->w3c, $this->url . '/application_cache');
420420
}
421421

422422
/**
@@ -444,7 +444,7 @@ public function log()
444444
}
445445

446446
// chaining
447-
return new Log($this->url . '/log');
447+
return new Log($this->w3c, $this->url . '/log');
448448
}
449449

450450
/**
@@ -455,7 +455,7 @@ public function log()
455455
*/
456456
public function alert()
457457
{
458-
return new Alert($this->url . '/alert');
458+
return new Alert($this->w3c, $this->url . '/alert');
459459
}
460460

461461
/**
@@ -474,7 +474,7 @@ public function execute()
474474
return $result['value'];
475475
}
476476

477-
return new Execute($this->url . '/execute');
477+
return new Execute($this->w3c, $this->url . '/execute');
478478
}
479479

480480
/**
@@ -487,26 +487,6 @@ public function setCapabilities($capabilities)
487487
$this->capabilities = $capabilities;
488488
}
489489

490-
/**
491-
* Set w3c
492-
*
493-
* @param boolean $w3c
494-
*/
495-
public function setW3c($w3c)
496-
{
497-
$this->w3c = $w3c;
498-
}
499-
500-
/**
501-
* Get w3c
502-
*
503-
* @return boolean
504-
*/
505-
public function getW3c()
506-
{
507-
return $this->w3c;
508-
}
509-
510490
/**
511491
* {@inheritdoc}
512492
*/

lib/WebDriver/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ public static function factory($type, $url)
141141
);
142142
}
143143

144-
return new $namespacedClassName($url);
144+
return new $namespacedClassName($this->w3c, $url);
145145
}
146146
}

lib/WebDriver/WebDriver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public function session($requiredCapabilities = Browser::FIREFOX, $desiredCapabi
7171
);
7272

7373
$capabilities = isset($result['value']['capabilities']) ? $result['value']['capabilities'] : null;
74+
$this->w3c = !! $capabilities;
7475

75-
$session = new Session($result['sessionUrl']);
76+
$session = new Session($this->w3c, $result['sessionUrl']);
7677
$session->setCapabilities($capabilities);
77-
$session->setW3c(!! $capabilities);
7878

7979
return $session;
8080
}
@@ -87,8 +87,9 @@ public function sessions()
8787
$result = $this->curl('GET', '/sessions');
8888
$sessions = array();
8989

90+
// @todo initialize $this->w3c if sessions() is called before session()
9091
foreach ($result['value'] as $session) {
91-
$sessions[] = new Session($this->url . '/session/' . $session['id']);
92+
$sessions[] = new Session($this->w3c, $this->url . '/session/' . $session['id']);
9293
}
9394

9495
return $sessions;

0 commit comments

Comments
 (0)