2929
3030class WebDriver
3131{
32- private $ _hubUrl = null ;
33- private $ _sessionId = null ;
32+ private $ _hubUrl = null ;
33+ private $ _sessionId = null ;
3434 private $ _screenshotsDirectory = null ;
35- private $ _environment = HttpFactory::PRODUCTIONMODE ;
36- private $ _capabilities = null ;
37- private $ _httpClient = null ;
38- private $ _options = null ;
39- private $ _navigate = null ;
35+ private $ _environment = HttpFactory::PRODUCTIONMODE ;
36+ private $ _capabilities = null ;
37+ private $ _httpClient = null ;
38+ private $ _options = null ;
39+ private $ _navigate = null ;
40+ private $ _targetLocator = null ;
4041
4142 /**
4243 * @param DesiredCapabilities $desiredCapabilities
@@ -45,8 +46,8 @@ class WebDriver
4546 */
4647 public function __construct (DesiredCapabilities $ desiredCapabilities = null , $ host = "http://localhost " , $ port = 4444 )
4748 {
48- $ this ->_hubUrl = $ host . " : " . strval ( $ port) . " /wd/hub " ;
49- if (! isset ($ desiredCapabilities )) { $ desiredCapabilities = new DesiredCapabilities ("firefox " ); }
49+ $ this ->_hubUrl = "{ $ host} : { $ port} /wd/hub " ;
50+ isset ($ desiredCapabilities ) ? : $ desiredCapabilities = new DesiredCapabilities ("firefox " );
5051 $ this ->_httpClient = HttpFactory::getClient ($ this ->_environment );
5152 $ this ->startSession ($ desiredCapabilities );
5253 }
@@ -231,6 +232,7 @@ public function getHttpClient() { return $this->_httpClient; }
231232 */
232233 public function getHubUrl () { return $ this ->_hubUrl ; }
233234
235+
234236 /**
235237 * Get Navigation object
236238 * @return Selenium\Navigation
@@ -254,35 +256,51 @@ public function setNavigate($navigate)
254256 */
255257 public function getSessionId () { return $ this ->_sessionId ; }
256258
257- /**
258- * Get default screenshots directory
259- * @return String
260- */
261- public function getScreenShotsDirectory () { return $ this ->_screenshotsDirectory ; }
262-
263259 /**
264260 * Sets default screenshots directory for files to be stored in
265261 * @param String $value
266262 */
267263 public function setScreenShotsDirectory ($ value ) { $ this ->_screenshotsDirectory = $ value ; }
264+
265+ /**
266+ * Get default screenshots directory
267+ * @return String
268+ */
269+ public function getScreenShotsDirectory () { return $ this ->_screenshotsDirectory ; }
268270
271+ /**
272+ * Get Navigation object
273+ * @return Selenium\Navigation
274+ */
275+ public function navigate ()
276+ {
277+ isset ($ this ->_navigate ) ? : $ this ->_navigate = new Navigation ($ this );
278+ return $ this ->_navigate ;
279+ }
280+
269281 /**
270282 * Gets Options object
271283 * @return SeleniumClient\Options
272284 */
273285 public function manage ()
274286 {
287+
275288 if (!$ this ->_options ) {
276289 $ this ->_options = new Options ($ this );
277290 }
291+ isset ($ this ->_options ) ? : $ this ->_options = new Options ($ this );
278292 return $ this ->_options ;
279293 }
280294
281295 /**
282296 * Creates new target locator to be handled
283297 * @return \SeleniumClient\TargetLocator
284298 */
285- public function switchTo () { return new TargetLocator ($ this ); }
299+ public function switchTo ()
300+ {
301+ isset ($ this ->_targetLocator ) ? : $ this ->_targetLocator = new TargetLocator ($ this );
302+ return $ this ->_targetLocator ;
303+ }
286304
287305 /**
288306 * Starts new Selenium session
@@ -299,7 +317,8 @@ private function startSession(DesiredCapabilities $desiredCapabilities)
299317 $ command = new Commands \StartSession ($ this , $ params );
300318 $ results = $ command ->execute ();
301319 $ this ->_sessionId = $ results ['sessionId ' ];
302- $ this ->_capabilities = $ this ->getCapabilities ();
320+ $ this ->_capabilities = $ results ['value ' ];
321+ return $ this ->_capabilities ;
303322 }
304323
305324 /**
@@ -332,7 +351,16 @@ public function quit()
332351 $ command = new Commands \Quit ($ this );
333352 $ command ->execute ();
334353 }
335-
354+
355+ /**
356+ * Closes current window
357+ */
358+ public function close ()
359+ {
360+ $ command = new Commands \CloseWindow ($ this );
361+ $ command ->execute ();
362+ }
363+
336364 /**
337365 * Navigates to specified url
338366 * @param String $url
@@ -369,7 +397,7 @@ public function status()
369397 * Gets current page source
370398 * @return String
371399 */
372- public function pageSource ()
400+ public function getPageSource ()
373401 {
374402 $ command = new Commands \Source ($ this );
375403 $ results = $ command ->execute ();
@@ -380,7 +408,7 @@ public function pageSource()
380408 * Gets current page title
381409 * @return String
382410 */
383- public function title ()
411+ public function getTitle ()
384412 {
385413 $ command = new Commands \Title ($ this );
386414 $ results = $ command ->execute ();
0 commit comments