@@ -62,7 +62,9 @@ class W3CClient implements ClientInterface
6262 *
6363 * ```
6464 * $loop = \React\EventLoop\Factory::create();
65+ *
6566 * $browser = new \React\Http\Browser($loop);
67+ * $browser = $browser->withRejectErrorResponse(false);
6668 *
6769 * $hubClient = new \Itnelo\React\WebDriver\Client\W3CClient(
6870 * $browser,
@@ -149,8 +151,8 @@ function (ResponseInterface $response) use ($sessionOpeningDeferred) {
149151 preg_match ('/sessionid[":\s]+([a-z\d]{32})/Ui ' , $ responseBody , $ matches );
150152
151153 if (!isset ($ matches [1 ])) {
152- // todo: locate an error message or set it as "undefined error".
153- throw new RuntimeException ('Unable to locate session identifier in the response. ' );
154+ // todo: locate an error message or set it as "undefined error"
155+ throw new RuntimeException ('Unable to locate a session identifier in the response. ' );
154156 }
155157
156158 $ sessionIdentifier = $ matches [1 ];
@@ -192,9 +194,54 @@ public function removeSession(string $sessionIdentifier): PromiseInterface
192194 */
193195 public function getTabIdentifiers (string $ sessionIdentifier ): PromiseInterface
194196 {
195- // TODO: Implement getTabIdentifiers() method.
197+ $ tabLookupDeferred = new Deferred ();
196198
197- return reject (new RuntimeException ('Not implemented. ' ));
199+ $ requestUri = sprintf (
200+ 'http://%s:%d/wd/hub/session/%s/window/handles ' ,
201+ $ this ->_options ['server ' ]['host ' ],
202+ $ this ->_options ['server ' ]['port ' ],
203+ $ sessionIdentifier
204+ );
205+
206+ $ requestHeaders = [
207+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
208+ ];
209+
210+ $ responsePromise = $ this ->httpClient ->get ($ requestUri , $ requestHeaders );
211+
212+ $ responsePromise ->then (
213+ function (ResponseInterface $ response ) use ($ tabLookupDeferred ) {
214+ try {
215+ $ responseBody = (string ) $ response ->getBody ();
216+ $ bodyDeserialized = json_decode ($ responseBody , true );
217+
218+ if (!array_key_exists ('value ' , $ bodyDeserialized ) || !is_array ($ bodyDeserialized ['value ' ])) {
219+ // todo: locate an error message or set it as "undefined error"
220+ throw new RuntimeException ('Unable to locate tab identifiers in the response. ' );
221+ }
222+
223+ $ tabIdentifiers = $ bodyDeserialized ['value ' ];
224+ $ tabLookupDeferred ->resolve ($ tabIdentifiers );
225+ } catch (Throwable $ exception ) {
226+ $ reason = new RuntimeException (
227+ 'Unable to open a selenium hub session (response deserialization). ' ,
228+ 0 ,
229+ $ exception
230+ );
231+
232+ $ tabLookupDeferred ->reject ($ reason );
233+ }
234+ },
235+ function (Throwable $ rejectionReason ) use ($ tabLookupDeferred ) {
236+ $ reason = new RuntimeException ('Unable to open a selenium hub session (request). ' , 0 , $ rejectionReason );
237+
238+ $ tabLookupDeferred ->reject ($ reason );
239+ }
240+ );
241+
242+ $ tabIdentifierListPromise = $ tabLookupDeferred ->promise ();
243+
244+ return $ tabIdentifierListPromise ;
198245 }
199246
200247 /**
0 commit comments