@@ -217,7 +217,7 @@ function (ResponseInterface $response) use ($tabLookupDeferred) {
217217 $ tabLookupDeferred ->resolve ($ tabIdentifiers );
218218 } catch (Throwable $ exception ) {
219219 $ reason = new RuntimeException (
220- 'Unable to open a selenium hub session (response deserialization). ' ,
220+ 'Unable to get tab identifiers (response deserialization). ' ,
221221 0 ,
222222 $ exception
223223 );
@@ -226,25 +226,52 @@ function (ResponseInterface $response) use ($tabLookupDeferred) {
226226 }
227227 },
228228 function (Throwable $ rejectionReason ) use ($ tabLookupDeferred ) {
229- $ reason = new RuntimeException ('Unable to open a selenium hub session (request). ' , 0 , $ rejectionReason );
229+ $ reason = new RuntimeException ('Unable to get tab identifiers (request). ' , 0 , $ rejectionReason );
230230
231231 $ tabLookupDeferred ->reject ($ reason );
232232 }
233233 );
234234
235- $ tabIdentifierListPromise = $ tabLookupDeferred ->promise ();
235+ $ identifierListPromise = $ tabLookupDeferred ->promise ();
236236
237- return $ tabIdentifierListPromise ;
237+ return $ identifierListPromise ;
238238 }
239239
240240 /**
241241 * {@inheritDoc}
242242 */
243243 public function getActiveTabIdentifier (string $ sessionIdentifier ): PromiseInterface
244244 {
245- // TODO: Implement getActiveTabIdentifier() method.
245+ $ requestUri = sprintf (
246+ 'http://%s:%d/wd/hub/session/%s/window ' ,
247+ $ this ->_options ['server ' ]['host ' ],
248+ $ this ->_options ['server ' ]['port ' ],
249+ $ sessionIdentifier
250+ );
246251
247- return reject (new RuntimeException ('Not implemented. ' ));
252+ $ requestHeaders = [
253+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
254+ ];
255+
256+ $ responsePromise = $ this ->httpClient ->get ($ requestUri , $ requestHeaders );
257+
258+ $ tabIdentifierPromise = $ responsePromise
259+ ->then (
260+ function (ResponseInterface $ response ) {
261+ $ tabIdentifier = $ this ->deserializeResponse ($ response );
262+
263+ return $ tabIdentifier ;
264+ }
265+ )
266+ ->then (
267+ null ,
268+ function (Throwable $ rejectionReason ) {
269+ throw new RuntimeException ('Unable to get an identifier for the active tab. ' , 0 , $ rejectionReason );
270+ }
271+ )
272+ ;
273+
274+ return $ tabIdentifierPromise ;
248275 }
249276
250277 /**
@@ -301,9 +328,36 @@ function (Throwable $rejectionReason) {
301328 */
302329 public function getCurrentUri (string $ sessionIdentifier ): PromiseInterface
303330 {
304- // TODO: Implement getUri() method.
331+ $ requestUri = sprintf (
332+ 'http://%s:%d/wd/hub/session/%s/url ' ,
333+ $ this ->_options ['server ' ]['host ' ],
334+ $ this ->_options ['server ' ]['port ' ],
335+ $ sessionIdentifier
336+ );
305337
306- return reject (new RuntimeException ('Not implemented. ' ));
338+ $ requestHeaders = [
339+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
340+ ];
341+
342+ $ responsePromise = $ this ->httpClient ->get ($ requestUri , $ requestHeaders );
343+
344+ $ currentUriPromise = $ responsePromise
345+ ->then (
346+ function (ResponseInterface $ response ) {
347+ $ uriCurrent = $ this ->deserializeResponse ($ response );
348+
349+ return $ uriCurrent ;
350+ }
351+ )
352+ ->then (
353+ null ,
354+ function (Throwable $ rejectionReason ) {
355+ throw new RuntimeException ('Unable to get a current URI. ' , 0 , $ rejectionReason );
356+ }
357+ )
358+ ;
359+
360+ return $ currentUriPromise ;
307361 }
308362
309363 /**
0 commit comments