{-# LANGUAGE OverloadedStrings #-}
module Test.WebDriver.Commands.Logs.Firefox (
getFirefoxLogs
) where
import Data.Aeson
import qualified Data.Foldable as F
import GHC.Stack
import Test.WebDriver.Commands.Logs.Common
import Test.WebDriver.JSON
import Test.WebDriver.Types
import Test.WebDriver.Util.Commands
import UnliftIO.Exception
getFirefoxLogs :: (HasCallStack, WebDriver wd) => LogType -> wd [LogEntry]
getFirefoxLogs :: forall (wd :: * -> *).
(HasCallStack, WebDriver wd) =>
LogType -> wd [LogEntry]
getFirefoxLogs LogType
logType = LogType -> wd [LogEntry]
forall (wd :: * -> *).
(HasCallStack, WebDriver wd) =>
LogType -> wd [LogEntry]
getLegacyFirefoxLogs LogType
logType
getLegacyFirefoxLogs :: (HasCallStack, WebDriver wd) => LogType -> wd [LogEntry]
getLegacyFirefoxLogs :: forall (wd :: * -> *).
(HasCallStack, WebDriver wd) =>
LogType -> wd [LogEntry]
getLegacyFirefoxLogs LogType
logType = do
wd Value -> wd (Either SomeException Value)
forall (m :: * -> *) a.
MonadUnliftIO m =>
m a -> m (Either SomeException a)
tryAny (Method -> Text -> Value -> wd Value
forall (wd :: * -> *) a b.
(HasCallStack, WebDriver wd, ToJSON a, FromJSON b) =>
Method -> Text -> a -> wd b
doSessCommand Method
methodPost Text
"/log" (Value -> wd Value) -> Value -> wd Value
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Key
"type" Key -> LogType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= LogType
logType]) wd (Either SomeException Value)
-> (Either SomeException Value -> wd [LogEntry]) -> wd [LogEntry]
forall a b. wd a -> (a -> wd b) -> wd b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right (Array Array
logs) -> (Value -> wd LogEntry) -> [Value] -> wd [LogEntry]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Value -> wd LogEntry
forall (m :: * -> *) a. (MonadIO m, FromJSON a) => Value -> m a
fromJSON' (Array -> [Value]
forall a. Vector a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Array
logs)
Either SomeException Value
_ -> [LogEntry] -> wd [LogEntry]
forall a. a -> wd a
forall (m :: * -> *) a. Monad m => a -> m a
return []