@@ -279,9 +279,38 @@ function (Throwable $rejectionReason) {
279279 */
280280 public function setActiveTab (string $ sessionIdentifier , string $ tabIdentifier ): PromiseInterface
281281 {
282- // TODO: Implement setActiveTab() method.
282+ $ requestUri = sprintf (
283+ 'http://%s:%d/wd/hub/session/%s/window ' ,
284+ $ this ->_options ['server ' ]['host ' ],
285+ $ this ->_options ['server ' ]['port ' ],
286+ $ sessionIdentifier
287+ );
283288
284- return reject (new RuntimeException ('Not implemented. ' ));
289+ $ requestHeaders = [
290+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
291+ ];
292+
293+ $ requestContents = json_encode (['handle ' => $ tabIdentifier ]);
294+
295+ $ responsePromise = $ this ->httpClient ->post ($ requestUri , $ requestHeaders , $ requestContents );
296+
297+ $ switchConfirmationPromise = $ responsePromise
298+ ->then (
299+ function (ResponseInterface $ response ) {
300+ $ this ->onCommandConfirmation ($ response , 'Tab switch command is not confirmed. ' );
301+
302+ return null ;
303+ }
304+ )
305+ ->then (
306+ null ,
307+ function (Throwable $ rejectionReason ) {
308+ throw new RuntimeException ('Unable to focus a tab. ' , 0 , $ rejectionReason );
309+ }
310+ )
311+ ;
312+
313+ return $ switchConfirmationPromise ;
285314 }
286315
287316 /**
@@ -365,9 +394,36 @@ function (Throwable $rejectionReason) {
365394 */
366395 public function getSource (string $ sessionIdentifier ): PromiseInterface
367396 {
368- // TODO: Implement getSource() method.
397+ $ requestUri = sprintf (
398+ 'http://%s:%d/wd/hub/session/%s/source ' ,
399+ $ this ->_options ['server ' ]['host ' ],
400+ $ this ->_options ['server ' ]['port ' ],
401+ $ sessionIdentifier
402+ );
369403
370- return reject (new RuntimeException ('Not implemented. ' ));
404+ $ requestHeaders = [
405+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
406+ ];
407+
408+ $ responsePromise = $ this ->httpClient ->get ($ requestUri , $ requestHeaders );
409+
410+ $ sourceCodePromise = $ responsePromise
411+ ->then (
412+ function (ResponseInterface $ response ) {
413+ $ sourceCode = $ this ->deserializeResponse ($ response );
414+
415+ return $ sourceCode ;
416+ }
417+ )
418+ ->then (
419+ null ,
420+ function (Throwable $ rejectionReason ) {
421+ throw new RuntimeException ('Unable to get source code of the web resource. ' , 0 , $ rejectionReason );
422+ }
423+ )
424+ ;
425+
426+ return $ sourceCodePromise ;
371427 }
372428
373429 /**
0 commit comments