@@ -16,6 +16,7 @@ defmodule WebDriverClient do
16
16
alias WebDriverClient.KeyCodes
17
17
alias WebDriverClient.LogEntry
18
18
alias WebDriverClient.ProtocolMismatchError
19
+ alias WebDriverClient.ServerStatus
19
20
alias WebDriverClient.Session
20
21
alias WebDriverClient.Size
21
22
alias WebDriverClient.UnexpectedResponseError
@@ -782,6 +783,31 @@ defmodule WebDriverClient do
782
783
end
783
784
end
784
785
786
+ @ doc """
787
+ Fetches server status
788
+ """
789
+ @ spec fetch_server_status ( Config . t ( ) ) :: { :ok , ServerStatus . t ( ) } | { :error , reason }
790
+ def fetch_server_status ( % Config { protocol: protocol } = config ) do
791
+ with { :ok , http_response } <-
792
+ send_request_for_protocol ( protocol ,
793
+ jwp: fn -> JWPCommands.FetchServerStatus . send_request ( config ) end ,
794
+ w3c: fn -> W3CCommands.FetchServerStatus . send_request ( config ) end
795
+ ) do
796
+ parse_with_fallbacks (
797
+ http_response ,
798
+ protocol ,
799
+ [
800
+ jwp: & JWPCommands.FetchServerStatus . parse_response / 1 ,
801
+ w3c: & W3CCommands.FetchServerStatus . parse_response / 1
802
+ ] ,
803
+ fn
804
+ { :ok , server_status } -> { :ok , to_server_status ( server_status ) }
805
+ { :error , error } -> { :error , to_error ( error ) }
806
+ end
807
+ )
808
+ end
809
+ end
810
+
785
811
@ spec to_log_entry ( JSONWireProtocolClient.LogEntry . t ( ) ) :: LogEntry . t ( )
786
812
defp to_log_entry ( % JSONWireProtocolClient.LogEntry { } = log_entry ) do
787
813
log_entry
@@ -810,6 +836,22 @@ defmodule WebDriverClient do
810
836
|> ( & struct! ( Cookie , & 1 ) ) . ( )
811
837
end
812
838
839
+ @ spec to_server_status (
840
+ W3CWireProtocolClient.ServerStatus . t ( )
841
+ | JSONWireProtocolClient.ServerStatus . t ( )
842
+ ) :: ServerStatus . t ( )
843
+ defp to_server_status ( % JSONWireProtocolClient.ServerStatus { } = server_status ) do
844
+ server_status
845
+ |> Map . from_struct ( )
846
+ |> ( & struct! ( ServerStatus , & 1 ) ) . ( )
847
+ end
848
+
849
+ defp to_server_status ( % W3CWireProtocolClient.ServerStatus { } = server_status ) do
850
+ server_status
851
+ |> Map . from_struct ( )
852
+ |> ( & struct! ( ServerStatus , & 1 ) ) . ( )
853
+ end
854
+
813
855
defp to_error ( % JSONWireProtocolClient.WebDriverError { reason: reason } ) do
814
856
reason =
815
857
case reason do
0 commit comments