From 7c8f5835642939362097aaf87dfd0060ea4c7bdb Mon Sep 17 00:00:00 2001 From: David Hewson Date: Tue, 12 Dec 2023 17:19:14 +0000 Subject: [PATCH] provide access to the capabilities returned on session create this lets us use the caps we were given without having to more network calls --- src/Test/WebDriver/Commands.hs | 9 ++++----- src/Test/WebDriver/Config.hs | 3 ++- src/Test/WebDriver/Session.hs | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Test/WebDriver/Commands.hs b/src/Test/WebDriver/Commands.hs index c94fe77..dbb2a11 100644 --- a/src/Test/WebDriver/Commands.hs +++ b/src/Test/WebDriver/Commands.hs @@ -110,9 +110,8 @@ import Prelude -- hides some "unused import" warnings createSession :: (HasCallStack, WebDriver wd) => Capabilities -> wd WDSession createSession caps = do let connect = withAuthHeaders $ doCommand methodPost "/session" . single "desiredCapabilities" $ caps - body <- connect `L.catch` \(_ex :: FailedCommand) -> connect - s <- getSession - putSession s { wdSessCreationResponse = Just body } + resp <- connect `L.catch` \(_ex :: FailedCommand) -> connect + modifySession $ \s -> s { wdSessCreateResponse = Just resp } getSession -- |Retrieve a list of active sessions and their 'Capabilities'. @@ -126,9 +125,9 @@ getActualCaps :: (HasCallStack, WebDriver wd) => wd Capabilities getActualCaps = doSessCommand methodGet "" Null -- |Get the 'Capabilities' that were sent when the session was creted. -getSessionCaps :: (HasCallStack, WebDriver wd) => wd (Maybe Capabilities) +getSessionCaps :: (HasCallStack, WDSessionState s) => s (Maybe Capabilities) getSessionCaps = do - caps <- wdSessCreationResponse <$> getSession + caps <- wdSessCreateResponse <$> getSession return $ parseMaybe parseJSON =<< caps -- |Close the current session and the browser associated with it. diff --git a/src/Test/WebDriver/Config.hs b/src/Test/WebDriver/Config.hs index ad51f20..b1ca884 100644 --- a/src/Test/WebDriver/Config.hs +++ b/src/Test/WebDriver/Config.hs @@ -92,6 +92,7 @@ instance WebDriverConfig WDConfig where , wdSessHistUpdate = wdHistoryConfig , wdSessHTTPManager = manager , wdSessHTTPRetryCount = wdHTTPRetryCount - , wdSessCreationResponse = Nothing } + , wdSessCreateResponse = Nothing + } where createManager = liftBase $ newManager defaultManagerSettings diff --git a/src/Test/WebDriver/Session.hs b/src/Test/WebDriver/Session.hs index 9fc1a08..2586208 100644 --- a/src/Test/WebDriver/Session.hs +++ b/src/Test/WebDriver/Session.hs @@ -77,7 +77,8 @@ data WDSession = WDSession { -- |Custom request headers to add *only* to session creation requests. This is usually done -- when a WebDriver server requires HTTP auth. , wdSessAuthHeaders :: RequestHeaders - , wdSessCreationResponse :: Maybe Value + -- |Value received in response to the session create HTTP request + , wdSessCreateResponse :: Maybe Value }