Skip to content

Commit 6582b5b

Browse files
committed
Get W3C session ID
1 parent 034dfb6 commit 6582b5b

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,12 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
255255

256256
$sessionId = isset($result['sessionId'])
257257
? $result['sessionId']
258-
: (isset($value['webdriver.remote.sessionid'])
259-
? $value['webdriver.remote.sessionid']
260-
: null
258+
: (isset($value['sessionId'])
259+
? $value['sessionId']
260+
: (isset($value['webdriver.remote.sessionid'])
261+
? $value['webdriver.remote.sessionid']
262+
: null
263+
)
261264
);
262265

263266
return array(

lib/WebDriver/Browser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@ final class Browser
3232
{
3333
/**
3434
* Check browser names used in static functions in the selenium source:
35-
* @see http://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java
36-
*
37-
* Note: Capability array takes these browserNames and not the "browserTypes"
35+
* @see https://github.com/SeleniumHQ/selenium/blob/trunk/java/client/src/org/openqa/selenium/remote/BrowserType.java
3836
*
3937
* Also check
4038
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Capabilities_JSON_Object
4139
*/
4240
const ANDROID = 'android';
4341
const CHROME = 'chrome';
42+
const EDGE = 'edge';
43+
const EDGEHTML = 'EdgeHTML';
4444
const FIREFOX = 'firefox';
4545
const HTMLUNIT = 'htmlunit';
4646
const IE = 'internet explorer';
4747
const INTERNET_EXPLORER = 'internet explorer';
4848
const IPHONE = 'iPhone';
4949
const IPAD = 'iPad';
50+
const MSEDGE = 'MicrosoftEdge';
5051
const OPERA = 'opera';
52+
const OPERA_BLINK = 'operablink';
5153
const PHANTOMJS = 'phantomjs';
5254
const SAFARI = 'safari';
5355
}

lib/WebDriver/Session.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ public function window()
249249
* - $session->legacyWindow($name) - set focus
250250
* - $session->legacyWindow($window_handle)->method() - chaining
251251
*
252+
* @deprecated
253+
*
252254
* @return \WebDriver\LegacyWindow|\WebDriver\Session
253255
*/
254256
public function legacyWindow()

lib/WebDriver/WebDriver.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,34 @@ protected function methods()
4747
*/
4848
public function session($requiredCapabilities = Browser::FIREFOX, $desiredCapabilities = array())
4949
{
50-
// for backwards compatibility when the only required capability was browser name
51-
if (! is_array($requiredCapabilities)) {
52-
$desiredCapabilities[Capability::BROWSER_NAME] = $requiredCapabilities ?: Browser::FIREFOX;
50+
if ($this->legacy) {
51+
// for backwards compatibility when the only required capability was browser name
52+
if (! is_array($requiredCapabilities)) {
53+
$desiredCapabilities[Capability::BROWSER_NAME] = $requiredCapabilities ?: Browser::FIREFOX;
5354

54-
$requiredCapabilities = array();
55-
}
55+
$requiredCapabilities = array();
56+
}
5657

57-
// required
58-
$parameters = array(
59-
'desiredCapabilities' => array_merge($desiredCapabilities, $requiredCapabilities)
60-
);
58+
// required
59+
$parameters = array(
60+
'desiredCapabilities' => array_merge($desiredCapabilities, $requiredCapabilities)
61+
);
6162

62-
// optional
63-
if (! empty($requiredCapabilities)) {
64-
$parameters['requiredCapabilities'] = $requiredCapabilities;
63+
// optional
64+
if (! empty($requiredCapabilities)) {
65+
$parameters['requiredCapabilities'] = $requiredCapabilities;
66+
}
67+
} else {
68+
if (! is_array($requiredCapabilities)) {
69+
$parameters = array(
70+
'capabilities' => array(
71+
'firstMatch' => array(
72+
array('browserName' => Browser::CHROME),
73+
array('browserName' => Browser::FIREFOX)
74+
)
75+
)
76+
);
77+
}
6578
}
6679

6780
$result = $this->curl(
@@ -85,10 +98,9 @@ public function session($requiredCapabilities = Browser::FIREFOX, $desiredCapabi
8598
*/
8699
public function sessions()
87100
{
88-
$result = $this->curl('GET', '/sessions');
101+
$result = $this->curl('GET', '/sessions');
89102
$sessions = array();
90103

91-
// @todo initialize $this->legacy if sessions() is called before session()
92104
foreach ($result['value'] as $session) {
93105
$sessions[] = new Session($this->url . '/session/' . $session['id'], $this->legacy);
94106
}

lib/WebDriver/WebDriverInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ interface WebDriverInterface
4242
public function session($requiredCapabilities = Browser::FIREFOX, $desiredCapabilities = array());
4343

4444
/**
45+
* Get Sessions: /sessions (GET)
4546
* Get list of currently active sessions
4647
*
48+
* @deprecated
49+
*
4750
* @return array an array of \WebDriver\Session objects
4851
*/
4952
public function sessions();

0 commit comments

Comments
 (0)