@@ -492,9 +492,43 @@ public function getActiveElement(string $sessionIdentifier): PromiseInterface
492492 */
493493 public function getElementVisibility (string $ sessionIdentifier , array $ elementIdentifier ): PromiseInterface
494494 {
495- // TODO: Implement getElementVisibility() method.
495+ // todo: safer checks (or hide internals behind a transfer object/contract)
496+ $ elementHandle = array_key_first ($ elementIdentifier );
497+ if (!isset ($ elementIdentifier [$ elementHandle ])) {
498+ throw new RuntimeException ('Unexpected format for the element identifier. ' );
499+ }
496500
497- return reject (new RuntimeException ('Not implemented. ' ));
501+ $ requestUri = sprintf (
502+ 'http://%s:%d/wd/hub/session/%s/element/%s/displayed ' ,
503+ $ this ->_options ['server ' ]['host ' ],
504+ $ this ->_options ['server ' ]['port ' ],
505+ $ sessionIdentifier ,
506+ $ elementIdentifier [$ elementHandle ]
507+ );
508+
509+ $ requestHeaders = [
510+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
511+ ];
512+
513+ $ responsePromise = $ this ->httpClient ->get ($ requestUri , $ requestHeaders );
514+
515+ $ visibilityStatusPromise = $ responsePromise
516+ ->then (
517+ function (ResponseInterface $ response ) {
518+ $ visibilityStatus = $ this ->deserializeResponse ($ response );
519+
520+ return $ visibilityStatus ;
521+ }
522+ )
523+ ->then (
524+ null ,
525+ function (Throwable $ rejectionReason ) {
526+ throw new RuntimeException ('Unable to get visibility status for the element. ' , 0 , $ rejectionReason );
527+ }
528+ )
529+ ;
530+
531+ return $ visibilityStatusPromise ;
498532 }
499533
500534 /**
@@ -515,9 +549,45 @@ public function keypressElement(
515549 array $ elementIdentifier ,
516550 string $ keySequence
517551 ): PromiseInterface {
518- // TODO: Implement keypressElement() method.
552+ // todo: safer checks (or hide internals behind a transfer object/contract)
553+ $ elementHandle = array_key_first ($ elementIdentifier );
554+ if (!is_string ($ elementHandle )) {
555+ throw new RuntimeException ('Unexpected format for the element identifier. ' );
556+ }
519557
520- return reject (new RuntimeException ('Not implemented. ' ));
558+ $ requestUri = sprintf (
559+ 'http://%s:%d/wd/hub/session/%s/element/%s/value ' ,
560+ $ this ->_options ['server ' ]['host ' ],
561+ $ this ->_options ['server ' ]['port ' ],
562+ $ sessionIdentifier ,
563+ $ elementIdentifier [$ elementHandle ]
564+ );
565+
566+ $ requestHeaders = [
567+ 'Content-Type ' => 'application/json; charset=UTF-8 ' ,
568+ ];
569+
570+ $ requestContents = json_encode (['text ' => $ keySequence ]);
571+
572+ $ responsePromise = $ this ->httpClient ->post ($ requestUri , $ requestHeaders , $ requestContents );
573+
574+ $ keypressConfirmationPromise = $ responsePromise
575+ ->then (
576+ function (ResponseInterface $ response ) {
577+ $ this ->onCommandConfirmation ($ response , 'Keypress command is not confirmed. ' );
578+
579+ return null ;
580+ }
581+ )
582+ ->then (
583+ null ,
584+ function (Throwable $ rejectionReason ) {
585+ throw new RuntimeException ('Unable to apply keyboard keys to the element. ' , 0 , $ rejectionReason );
586+ }
587+ )
588+ ;
589+
590+ return $ keypressConfirmationPromise ;
521591 }
522592
523593 /**
0 commit comments