{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE UndecidableInstances #-}

module Test.Marionette.Commands where

import Data.Aeson
    ( FromJSON
    , KeyValue (..)
    , ToJSON (toJSON)
    , Value (..)
    )
import Data.Aeson qualified as Aeson
import Data.Aeson.KeyMap qualified as Object
import Data.ByteString (ByteString)
import Data.ByteString.Base64 qualified as Base64
import Data.Foldable qualified as Foldable
import Data.Text
import Data.Text.Encoding qualified as Text
import GHC.Generics (Generic)
import GHC.Stack (HasCallStack)
import Test.Marionette.AccessibilityProperties (AccessibilityProperties)
import Test.Marionette.Class
import Test.Marionette.Context (Context)
import Test.Marionette.Cookie (Cookie)
import Test.Marionette.Element (Element (..), Shadow)
import Test.Marionette.Frame (Frame)
import Test.Marionette.Orientation (Orientation)
import Test.Marionette.Protocol
import Test.Marionette.Rect (Rect)
import Test.Marionette.Registry (RegistryEntry)
import Test.Marionette.Selector
    ( Selector
    , SelectorFrom (..)
    , SelectorFromShadowRoot (..)
    )
import Test.Marionette.Timeouts (Timeouts)
import Test.Marionette.WebAuthn
    ( AuthenticatorId (..)
    , Credential
    , CredentialId (..)
    , VirtualAuthenticator
    )
import Test.Marionette.Window
    ( NewWindowResult
    , WindowHandle (..)
    , WindowType (..)
    )
import Prelude hiding (log)

newtype ValueObject a = ValueObject {forall a. ValueObject a -> a
value :: a}
    deriving stock ((forall x. ValueObject a -> Rep (ValueObject a) x)
-> (forall x. Rep (ValueObject a) x -> ValueObject a)
-> Generic (ValueObject a)
forall x. Rep (ValueObject a) x -> ValueObject a
forall x. ValueObject a -> Rep (ValueObject a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (ValueObject a) x -> ValueObject a
forall a x. ValueObject a -> Rep (ValueObject a) x
$cfrom :: forall a x. ValueObject a -> Rep (ValueObject a) x
from :: forall x. ValueObject a -> Rep (ValueObject a) x
$cto :: forall a x. Rep (ValueObject a) x -> ValueObject a
to :: forall x. Rep (ValueObject a) x -> ValueObject a
Generic)
    deriving anyclass (Maybe (ValueObject a)
Value -> Parser [ValueObject a]
Value -> Parser (ValueObject a)
(Value -> Parser (ValueObject a))
-> (Value -> Parser [ValueObject a])
-> Maybe (ValueObject a)
-> FromJSON (ValueObject a)
forall a. FromJSON a => Maybe (ValueObject a)
forall a. FromJSON a => Value -> Parser [ValueObject a]
forall a. FromJSON a => Value -> Parser (ValueObject a)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: forall a. FromJSON a => Value -> Parser (ValueObject a)
parseJSON :: Value -> Parser (ValueObject a)
$cparseJSONList :: forall a. FromJSON a => Value -> Parser [ValueObject a]
parseJSONList :: Value -> Parser [ValueObject a]
$comittedField :: forall a. FromJSON a => Maybe (ValueObject a)
omittedField :: Maybe (ValueObject a)
FromJSON, [ValueObject a] -> Value
[ValueObject a] -> Encoding
ValueObject a -> Bool
ValueObject a -> Value
ValueObject a -> Encoding
(ValueObject a -> Value)
-> (ValueObject a -> Encoding)
-> ([ValueObject a] -> Value)
-> ([ValueObject a] -> Encoding)
-> (ValueObject a -> Bool)
-> ToJSON (ValueObject a)
forall a. ToJSON a => [ValueObject a] -> Value
forall a. ToJSON a => [ValueObject a] -> Encoding
forall a. ToJSON a => ValueObject a -> Bool
forall a. ToJSON a => ValueObject a -> Value
forall a. ToJSON a => ValueObject a -> Encoding
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: forall a. ToJSON a => ValueObject a -> Value
toJSON :: ValueObject a -> Value
$ctoEncoding :: forall a. ToJSON a => ValueObject a -> Encoding
toEncoding :: ValueObject a -> Encoding
$ctoJSONList :: forall a. ToJSON a => [ValueObject a] -> Value
toJSONList :: [ValueObject a] -> Value
$ctoEncodingList :: forall a. ToJSON a => [ValueObject a] -> Encoding
toEncodingList :: [ValueObject a] -> Encoding
$comitField :: forall a. ToJSON a => ValueObject a -> Bool
omitField :: ValueObject a -> Bool
ToJSON)

type role ValueObject representational

-- | Enable or disable accepting new socket connections.
-- This has no effect on existing connections.
acceptConnections :: (HasCallStack, Marionette m) => Bool -> m ()
acceptConnections :: forall (m :: * -> *). (HasCallStack, Marionette m) => Bool -> m ()
acceptConnections Bool
value =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"Marionette:AcceptConnections"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"value" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
value]
            }

-- | Look up accessibility properties of a node in the platform accessibility tree,
-- rather than by a web element reference.
getAccessibilityPropertiesForAccessibilityNode
    :: (HasCallStack, Marionette m)
    => Text
    -- ^ Node identifier @nodeId@
    -> m AccessibilityProperties
getAccessibilityPropertiesForAccessibilityNode :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Text -> m AccessibilityProperties
getAccessibilityPropertiesForAccessibilityNode Text
nodeId =
    Command -> m AccessibilityProperties
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"Marionette:GetAccessibilityPropertiesForAccessibilityNode"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"nodeId" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
nodeId]
            }

-- | Look up the accessibility properties exposed to assistive technology
-- (such as screen readers) for a given element.
getAccessibilityPropertiesForElement
    :: (HasCallStack, Marionette m)
    => Element
    -> m AccessibilityProperties
getAccessibilityPropertiesForElement :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m AccessibilityProperties
getAccessibilityPropertiesForElement Element{Text
elementId :: Text
elementId :: Element -> Text
..} =
    Command -> m AccessibilityProperties
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"Marionette:GetAccessibilityPropertiesForElement"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
            }

-- | Return whether subsequent browsing-context-scoped commands (such as
-- 'navigate' or 'findElement') target privileged browser chrome or ordinary
-- web content.
-- New sessions start in the 'Content' context; use 'setContext' to switch,
-- for example when driving browser UI rather than a web page.
getContext :: (HasCallStack, Marionette m) => m Context
getContext :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Context
getContext = ValueObject Context -> Context
forall a. ValueObject a -> a
value (ValueObject Context -> Context)
-> m (ValueObject Context) -> m Context
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Context)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"Marionette:GetContext"

-- | Return the current orientation of the browser window.
getScreenOrientation :: (HasCallStack, Marionette m) => m Orientation
getScreenOrientation :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Orientation
getScreenOrientation = ValueObject Orientation -> Orientation
forall a. ValueObject a -> a
value (ValueObject Orientation -> Orientation)
-> m (ValueObject Orientation) -> m Orientation
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Orientation)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"Marionette:GetScreenOrientation"

-- | Return the chrome window's @windowtype@ attribute, for example
-- @navigator:browser@ for a normal browser window.
getWindowType :: (HasCallStack, Marionette m) => m Text
getWindowType :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Text
getWindowType = ValueObject Text -> Text
forall a. ValueObject a -> a
value (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"Marionette:GetWindowType"

-- | Shut the browser down: Marionette first stops accepting new
-- connections, then ends the current session, and finally causes the
-- application itself to quit.
quit :: (HasCallStack, Marionette m) => m ()
quit :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
quit = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"Marionette:Quit"

-- | Register a chrome protocol handler for a directory containing XHTML or
-- XUL files, allowing them to be loaded via the @chrome://@ protocol.
-- Return the identifier for the registered handler which can be unregistered
-- with 'unregisterChromeHandler'.
registerChromeHandler :: (HasCallStack, Marionette m) => Text -> [RegistryEntry] -> m Text
registerChromeHandler :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Text -> [RegistryEntry] -> m Text
registerChromeHandler Text
manifestPath [RegistryEntry]
entries =
    Command -> m Text
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"Marionette:RegisterChromeHandler"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"manifestPath" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
manifestPath
                    , Key
"entries" Key -> [RegistryEntry] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [RegistryEntry]
entries
                    ]
            }

-- | Set the context of the subsequent commands. All subsequent requests to
-- commands that in some way involve interaction with a browsing context
-- will target the chosen context.
setContext :: (HasCallStack, Marionette m) => Context -> m ()
setContext :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Context -> m ()
setContext Context
value =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"Marionette:SetContext"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"value" Key -> Context -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Context
value]
            }

-- | Set the current browser orientation.
setScreenOrientation :: (HasCallStack, Marionette m) => Orientation -> m ()
setScreenOrientation :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Orientation -> m ()
setScreenOrientation Orientation
orientation =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"Marionette:SetScreenOrientation"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"orientation" Key -> Orientation -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Orientation
orientation]
            }

-- | Unregister a previously registered chrome protocol handler, given an
-- identifier returned by 'registerChromeHandler'.
unregisterChromeHandler :: (HasCallStack, Marionette m) => Text -> m ()
unregisterChromeHandler :: forall (m :: * -> *). (HasCallStack, Marionette m) => Text -> m ()
unregisterChromeHandler Text
handlerId =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"Marionette:UnregisterChromeHandler"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
handlerId]
            }

-- | Accept a currently displayed dialog modal, or throw if no modal is
-- displayed.
--
-- See <https://w3c.github.io/webdriver/#accept-alert>
acceptAlert :: (HasCallStack, Marionette m) => m ()
acceptAlert :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
acceptAlert = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:AcceptAlert"

-- | Add a single cookie to the cookie store associated with the active
-- document's address.
--
-- See <https://w3c.github.io/webdriver/#add-cookie>
addCookie :: (HasCallStack, Marionette m) => Cookie -> m ()
addCookie :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Cookie -> m ()
addCookie Cookie
cookie =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:AddCookie"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"cookie" Key -> Cookie -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Cookie
cookie]
            }

-- | Cause the browser to traverse one step backward in the joint history
-- of the current browsing context.
--
-- See <https://w3c.github.io/webdriver/#back>
back :: (HasCallStack, Marionette m) => m ()
back :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
back = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:Back"

-- | Close the currently selected chrome window. If it is the last window
-- currently open, the chrome window is not closed, to prevent an
-- application shutdown.
closeChromeWindow :: (HasCallStack, Marionette m) => m ()
closeChromeWindow :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
closeChromeWindow = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:CloseChromeWindow"

-- | Close the currently selected tab or window. With multiple open tabs,
-- only the selected tab is closed; if it is the last window currently
-- open, the window is not closed, to prevent an application shutdown.
--
-- See <https://w3c.github.io/webdriver/#close-window>
closeWindow :: (HasCallStack, Marionette m) => m ()
closeWindow :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
closeWindow = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:CloseWindow"

-- | Delete all cookies that are visible to a document.
--
-- See <https://w3c.github.io/webdriver/#delete-all-cookies>
deleteAllCookies :: (HasCallStack, Marionette m) => m ()
deleteAllCookies :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
deleteAllCookies = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:DeleteAllCookies"

-- | Delete a cookie by name.
--
-- See <https://w3c.github.io/webdriver/#delete-cookie>
deleteCookie :: (HasCallStack, Marionette m) => Text -> m ()
deleteCookie :: forall (m :: * -> *). (HasCallStack, Marionette m) => Text -> m ()
deleteCookie Text
name =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:DeleteCookie"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name]
            }

-- | Delete the current WebDriver session.
--
-- See <https://w3c.github.io/webdriver/#delete-session>
deleteSession :: (HasCallStack, Marionette m) => m ()
deleteSession :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
deleteSession = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:DeleteSession"

-- | Dismiss a currently displayed modal dialog, or throw if no modal is
-- displayed.
--
-- See <https://w3c.github.io/webdriver/#dismiss-alert>
dismissAlert :: (HasCallStack, Marionette m) => m ()
dismissAlert :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
dismissAlert = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:DismissAlert"

-- | Clear the text of an element.
--
-- See <https://w3c.github.io/webdriver/#element-clear>
elementClear :: (HasCallStack, Marionette m) => Element -> m ()
elementClear :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m ()
elementClear Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:ElementClear"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
            }

-- | Send a click event to an element.
--
-- See <https://w3c.github.io/webdriver/#element-click>
elementClick :: (HasCallStack, Marionette m) => Element -> m ()
elementClick :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m ()
elementClick Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:ElementClick"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
            }

-- | Send key presses to an element after focusing on it.
--
-- See <https://w3c.github.io/webdriver/#element-send-keys>
elementSendKeys :: (HasCallStack, Marionette m) => Element -> Text -> m ()
elementSendKeys :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> Text -> m ()
elementSendKeys Element{Text
elementId :: Element -> Text
elementId :: Text
..} Text
text =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:ElementSendKeys"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId
                    , Key
"text" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
text
                    ]
            }

-- | Execute a JavaScript function asynchronously in the context of the
-- current browsing context, and return the value passed to the callback,
-- which is always the last argument exposed to the script.
--
-- See <https://w3c.github.io/webdriver/#execute-async-script>
executeAsyncScript
    :: (HasCallStack, Marionette m, Foldable f, FromJSON a)
    => Text
    -> f Value
    -> m (Maybe a)
executeAsyncScript :: forall (m :: * -> *) (f :: * -> *) a.
(HasCallStack, Marionette m, Foldable f, FromJSON a) =>
Text -> f Value -> m (Maybe a)
executeAsyncScript Text
script f Value
args =
    (ValueObject (Maybe a) -> Maybe a)
-> m (ValueObject (Maybe a)) -> m (Maybe a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueObject (Maybe a) -> Maybe a
forall a. ValueObject a -> a
value (m (ValueObject (Maybe a)) -> m (Maybe a))
-> (Command -> m (ValueObject (Maybe a))) -> Command -> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Command -> m (ValueObject (Maybe a))
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand (Command -> m (Maybe a)) -> Command -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$
        Command
            { command :: Text
command = Text
"WebDriver:ExecuteAsyncScript"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"script" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
script
                    , Key
"args" Key -> [Value] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= f Value -> [Value]
forall a. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList f Value
args
                    ]
            }

-- | Execute a JavaScript function synchronously in the context of the
-- current browsing context, and return its return value.
--
-- See <https://w3c.github.io/webdriver/#execute-script>
executeScript :: (HasCallStack, Marionette m, Foldable f, FromJSON a) => Text -> f Value -> m a
executeScript :: forall (m :: * -> *) (f :: * -> *) a.
(HasCallStack, Marionette m, Foldable f, FromJSON a) =>
Text -> f Value -> m a
executeScript Text
script f Value
args =
    (ValueObject a -> a) -> m (ValueObject a) -> m a
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueObject a -> a
forall a. ValueObject a -> a
value (m (ValueObject a) -> m a)
-> (Command -> m (ValueObject a)) -> Command -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Command -> m (ValueObject a)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand (Command -> m a) -> Command -> m a
forall a b. (a -> b) -> a -> b
$
        Command
            { command :: Text
command = Text
"WebDriver:ExecuteScript"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"script" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
script
                    , Key
"args" Key -> [Value] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= f Value -> [Value]
forall a. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList f Value
args
                    ]
            }

-- | Find an element using the given search strategy.
--
-- See <https://w3c.github.io/webdriver/#find-element>
findElement :: (HasCallStack, Marionette m) => Selector -> m Element
findElement :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Selector -> m Element
findElement Selector
selector =
    ValueObject Element -> Element
forall a. ValueObject a -> a
value
        (ValueObject Element -> Element)
-> m (ValueObject Element) -> m Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Element)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:FindElement"
                , parameters :: Value
parameters = Selector -> Value
forall a. ToJSON a => a -> Value
toJSON Selector
selector
                }

-- | Find an element using the given search strategy, relative to the
-- given element.
--
-- See <https://w3c.github.io/webdriver/#find-element>
findElementFrom :: (HasCallStack, Marionette m) => Element -> Selector -> m Element
findElementFrom :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> Selector -> m Element
findElementFrom Element
element Selector
selector =
    ValueObject Element -> Element
forall a. ValueObject a -> a
value
        (ValueObject Element -> Element)
-> m (ValueObject Element) -> m Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Element)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:FindElement"
                , parameters :: Value
parameters = SelectorFrom -> Value
forall a. ToJSON a => a -> Value
toJSON (SelectorFrom -> Value) -> SelectorFrom -> Value
forall a b. (a -> b) -> a -> b
$ Element -> Selector -> SelectorFrom
SelectorFrom Element
element Selector
selector
                }

-- | Find an element within a shadow root using the given search strategy.
--
-- See <https://w3c.github.io/webdriver/#find-element-from-shadow-root>
findElementFromShadowRoot :: (HasCallStack, Marionette m) => Shadow -> Selector -> m Element
findElementFromShadowRoot :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Shadow -> Selector -> m Element
findElementFromShadowRoot Shadow
shadowRoot Selector
selector =
    ValueObject Element -> Element
forall a. ValueObject a -> a
value
        (ValueObject Element -> Element)
-> m (ValueObject Element) -> m Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Element)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:FindElementFromShadowRoot"
                , parameters :: Value
parameters = SelectorFromShadowRoot -> Value
forall a. ToJSON a => a -> Value
toJSON (SelectorFromShadowRoot -> Value)
-> SelectorFromShadowRoot -> Value
forall a b. (a -> b) -> a -> b
$ Shadow -> Selector -> SelectorFromShadowRoot
SelectorFromShadowRoot Shadow
shadowRoot Selector
selector
                }

-- | Find elements using the given search strategy.
--
-- See <https://w3c.github.io/webdriver/#find-elements>
findElements :: (HasCallStack, Marionette m) => Selector -> m [Element]
findElements :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Selector -> m [Element]
findElements Selector
selector =
    Command -> m [Element]
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:FindElements"
            , parameters :: Value
parameters = Selector -> Value
forall a. ToJSON a => a -> Value
toJSON Selector
selector
            }

-- | Find elements using the given search strategy, relative to the given
-- element.
--
-- See <https://w3c.github.io/webdriver/#find-elements>
findElementsFrom :: (HasCallStack, Marionette m) => Element -> Selector -> m [Element]
findElementsFrom :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> Selector -> m [Element]
findElementsFrom Element
element Selector
selector =
    Command -> m [Element]
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:FindElements"
            , parameters :: Value
parameters = SelectorFrom -> Value
forall a. ToJSON a => a -> Value
toJSON (Element -> Selector -> SelectorFrom
SelectorFrom Element
element Selector
selector)
            }

-- | Find elements within a shadow root using the given search strategy.
--
-- See <https://w3c.github.io/webdriver/#find-elements-from-shadow-root>
findElementsFromShadowRoot :: (HasCallStack, Marionette m) => Shadow -> Selector -> m [Element]
findElementsFromShadowRoot :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Shadow -> Selector -> m [Element]
findElementsFromShadowRoot Shadow
shadowRoot Selector
selector =
    Command -> m [Element]
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:FindElementsFromShadowRoot"
            , parameters :: Value
parameters = SelectorFromShadowRoot -> Value
forall a. ToJSON a => a -> Value
toJSON (SelectorFromShadowRoot -> Value)
-> SelectorFromShadowRoot -> Value
forall a b. (a -> b) -> a -> b
$ Shadow -> Selector -> SelectorFromShadowRoot
SelectorFromShadowRoot Shadow
shadowRoot Selector
selector
            }

-- | Cause the browser to traverse one step forward in the joint history
-- of the current browsing context.
--
-- See <https://w3c.github.io/webdriver/#forward>
forward :: (HasCallStack, Marionette m) => m ()
forward :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
forward = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:Forward"

-- | Set the window to full screen, as if the user had chosen
-- View -> Enter Full Screen. Not supported on Android.
--
-- See <https://w3c.github.io/webdriver/#fullscreen-window>
fullscreenWindow :: (HasCallStack, Marionette m) => m ()
fullscreenWindow :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
fullscreenWindow = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:FullscreenWindow"

-- | Return the active element in the document.
--
-- See <https://w3c.github.io/webdriver/#get-active-element>
getActiveElement :: (HasCallStack, Marionette m) => m Element
getActiveElement :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Element
getActiveElement = ValueObject Element -> Element
forall a. ValueObject a -> a
value (ValueObject Element -> Element)
-> m (ValueObject Element) -> m Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Element)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetActiveElement"

-- | Return the message shown in a currently displayed modal, or throw if
-- no modal is displayed.
--
-- See <https://w3c.github.io/webdriver/#get-alert-text>
getAlertText :: (HasCallStack, Marionette m) => m Text
getAlertText :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Text
getAlertText = ValueObject Text -> Text
forall a. ValueObject a -> a
value (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetAlertText"

-- | Determine the accessibility label for an element.
--
-- See <https://w3c.github.io/webdriver/#get-computed-label>
getComputedLabel :: (HasCallStack, Marionette m) => Element -> m Text
getComputedLabel :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Text
getComputedLabel Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Text -> Text
forall a. ValueObject a -> a
value
        (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetComputedLabel"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Determine the accessibility role for an element.
--
-- See <https://w3c.github.io/webdriver/#get-computed-role>
getComputedRole :: (HasCallStack, Marionette m) => Element -> m Text
getComputedRole :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Text
getComputedRole Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Text -> Text
forall a. ValueObject a -> a
value
        (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetComputedRole"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Get all the cookies for the current domain. Equivalent to calling
-- @document.cookie@ and parsing the result.
--
-- See <https://w3c.github.io/webdriver/#get-all-cookies>
getCookies :: (HasCallStack, Marionette m) => m [Cookie]
getCookies :: forall (m :: * -> *). (HasCallStack, Marionette m) => m [Cookie]
getCookies = Command -> m [Cookie]
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetCookies"

-- | Get a string representing the current URL, equivalent to
-- @document.location.href@. When in the chrome context, return the
-- canonical URL of the current resource.
--
-- See <https://w3c.github.io/webdriver/#get-current-url>
getCurrentURL :: (HasCallStack, Marionette m) => m Text
getCurrentURL :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Text
getCurrentURL = ValueObject Text -> Text
forall a. ValueObject a -> a
value (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetCurrentURL"

-- | Get the value of the given attribute of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-attribute>
getElementAttribute :: (HasCallStack, Marionette m) => Text -> Element -> m (Maybe Text)
getElementAttribute :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Text -> Element -> m (Maybe Text)
getElementAttribute Text
attr Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject (Maybe Text) -> Maybe Text
forall a. ValueObject a -> a
value
        (ValueObject (Maybe Text) -> Maybe Text)
-> m (ValueObject (Maybe Text)) -> m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject (Maybe Text))
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetElementAttribute"
                , parameters :: Value
parameters =
                    [Pair] -> Value
Aeson.object
                        [ Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId
                        , Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
attr
                        ]
                }

-- | Get the given CSS property of the computed style of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-css-value>
getElementCSSValue :: (HasCallStack, Marionette m) => Element -> Text -> m (Maybe Text)
getElementCSSValue :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> Text -> m (Maybe Text)
getElementCSSValue Element{Text
elementId :: Element -> Text
elementId :: Text
..} Text
propertyName =
    ValueObject (Maybe Text) -> Maybe Text
forall a. ValueObject a -> a
value
        (ValueObject (Maybe Text) -> Maybe Text)
-> m (ValueObject (Maybe Text)) -> m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject (Maybe Text))
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetElementCSSValue"
                , parameters :: Value
parameters =
                    [Pair] -> Value
Aeson.object
                        [ Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId
                        , Key
"propertyName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
propertyName
                        ]
                }

-- | Get the value of the given property of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-property>
getElementProperty :: (HasCallStack, Marionette m) => Element -> Text -> m (Maybe Text)
getElementProperty :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> Text -> m (Maybe Text)
getElementProperty Element{Text
elementId :: Element -> Text
elementId :: Text
..} Text
name =
    ValueObject (Maybe Text) -> Maybe Text
forall a. ValueObject a -> a
value
        (ValueObject (Maybe Text) -> Maybe Text)
-> m (ValueObject (Maybe Text)) -> m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject (Maybe Text))
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetElementProperty"
                , parameters :: Value
parameters =
                    [Pair] -> Value
Aeson.object
                        [ Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId
                        , Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
name
                        ]
                }

-- | Get the dimensions and coordinates of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-rect>
getElementRect :: (HasCallStack, Marionette m) => Element -> m Rect
getElementRect :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Rect
getElementRect Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    Command -> m Rect
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:GetElementRect"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
            }

-- | Get the local tag name of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-tag-name>
getElementTagName :: (HasCallStack, Marionette m) => Element -> m Text
getElementTagName :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Text
getElementTagName Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Text -> Text
forall a. ValueObject a -> a
value
        (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetElementTagName"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Get the rendered text of an element, including the text of all its
-- child elements.
--
-- See <https://w3c.github.io/webdriver/#get-element-text>
getElementText :: (HasCallStack, Marionette m) => Element -> m Text
getElementText :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Text
getElementText Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Text -> Text
forall a. ValueObject a -> a
value
        (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetElementText"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Get the page source of the content document, serialised as a string.
--
-- See <https://w3c.github.io/webdriver/#get-page-source>
getPageSource :: (HasCallStack, Marionette m) => m Text
getPageSource :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Text
getPageSource = ValueObject Text -> Text
forall a. ValueObject a -> a
value (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetPageSource"

-- | Get the shadow root of an element.
--
-- See <https://w3c.github.io/webdriver/#get-element-shadow-root>
getShadowRoot :: (HasCallStack, Marionette m) => Element -> m Shadow
getShadowRoot :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Shadow
getShadowRoot Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Shadow -> Shadow
forall a. ValueObject a -> a
value
        (ValueObject Shadow -> Shadow)
-> m (ValueObject Shadow) -> m Shadow
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Shadow)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:GetShadowRoot"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Get the timeouts for page loading, searching, and scripts.
--
-- See <https://w3c.github.io/webdriver/#get-timeouts>
getTimeouts :: (HasCallStack, Marionette m) => m Timeouts
getTimeouts :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Timeouts
getTimeouts = Command -> m Timeouts
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetTimeouts"

-- | Get the current title of the window.
--
-- See <https://w3c.github.io/webdriver/#get-title>
getTitle :: (HasCallStack, Marionette m) => m Text
getTitle :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Text
getTitle = ValueObject Text -> Text
forall a. ValueObject a -> a
value (ValueObject Text -> Text) -> m (ValueObject Text) -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetTitle"

-- | Get the current window's handle: an opaque, server-assigned
-- identifier that can be used to switch back to this window later with
-- 'switchToWindow'.
--
-- See <https://w3c.github.io/webdriver/#get-window-handle>
getWindowHandle :: (HasCallStack, Marionette m) => m WindowHandle
getWindowHandle :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
m WindowHandle
getWindowHandle = ValueObject WindowHandle -> WindowHandle
forall a. ValueObject a -> a
value (ValueObject WindowHandle -> WindowHandle)
-> m (ValueObject WindowHandle) -> m WindowHandle
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject WindowHandle)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetWindowHandle"

-- | Get the unordered list of window handles of every open top-level
-- browsing context.
--
-- See <https://w3c.github.io/webdriver/#get-window-handles>
getWindowHandles :: (HasCallStack, Marionette m) => m [WindowHandle]
getWindowHandles :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
m [WindowHandle]
getWindowHandles = Command -> m [WindowHandle]
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetWindowHandles"

-- | Get the position and size of the browser window currently in focus.
-- The width and height refer to the window's @outerWidth@ and
-- @outerHeight@, which include scroll bars, title bars, and so on.
--
-- See <https://w3c.github.io/webdriver/#get-window-rect>
getWindowRect :: (HasCallStack, Marionette m) => m Rect
getWindowRect :: forall (m :: * -> *). (HasCallStack, Marionette m) => m Rect
getWindowRect = Command -> m Rect
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand Command
"WebDriver:GetWindowRect"

-- | Check whether an element is displayed.
--
-- See <https://w3c.github.io/webdriver/#element-displayedness>
isElementDisplayed :: (HasCallStack, Marionette m) => Element -> m Bool
isElementDisplayed :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Bool
isElementDisplayed Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Bool -> Bool
forall a. ValueObject a -> a
value
        (ValueObject Bool -> Bool) -> m (ValueObject Bool) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Bool)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:IsElementDisplayed"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Check whether an element is enabled.
--
-- See <https://w3c.github.io/webdriver/#is-element-enabled>
isElementEnabled :: (HasCallStack, Marionette m) => Element -> m Bool
isElementEnabled :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Bool
isElementEnabled Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Bool -> Bool
forall a. ValueObject a -> a
value
        (ValueObject Bool -> Bool) -> m (ValueObject Bool) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Bool)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:IsElementEnabled"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Check whether an element is selected.
--
-- See <https://w3c.github.io/webdriver/#is-element-selected>
isElementSelected :: (HasCallStack, Marionette m) => Element -> m Bool
isElementSelected :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Element -> m Bool
isElementSelected Element{Text
elementId :: Element -> Text
elementId :: Text
..} =
    ValueObject Bool -> Bool
forall a. ValueObject a -> a
value
        (ValueObject Bool -> Bool) -> m (ValueObject Bool) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Bool)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:IsElementSelected"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
elementId]
                }

-- | Maximise the window, as if the user had pressed the maximise button.
-- Not supported on Android.
--
-- See <https://w3c.github.io/webdriver/#maximize-window>
maximizeWindow :: (HasCallStack, Marionette m) => m ()
maximizeWindow :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
maximizeWindow = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:MaximizeWindow"

-- | Minimise the window, as if the user had pressed the minimise button.
-- Not supported on Android.
--
-- See <https://w3c.github.io/webdriver/#minimize-window>
minimizeWindow :: (HasCallStack, Marionette m) => m ()
minimizeWindow :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
minimizeWindow = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:MinimizeWindow"

-- | Navigate to the given URL, waiting for the document to load or the
-- session's page load timeout to elapse before returning.
--
-- See <https://w3c.github.io/webdriver/#navigate-to>
navigate :: (HasCallStack, Marionette m) => Text -> m ()
navigate :: forall (m :: * -> *). (HasCallStack, Marionette m) => Text -> m ()
navigate Text
url =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:Navigate"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"url" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
url]
            }

-- | Create a new WebDriver session. Must be called before performing any
-- other command.
--
-- See <https://w3c.github.io/webdriver/#new-session>
newSession :: (HasCallStack, Marionette m) => m ()
newSession :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
newSession = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:NewSession"

-- | Open a new top-level browsing context of type window.
--
-- See <https://w3c.github.io/webdriver/#new-window>
newWindow :: (HasCallStack, Marionette m) => m NewWindowResult
newWindow :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
m NewWindowResult
newWindow =
    Command -> m NewWindowResult
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:NewWindow"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"type" Key -> WindowType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= WindowType
Window]
            }

-- | Open a new top-level browsing context of type tab.
--
-- See <https://w3c.github.io/webdriver/#new-window>
newTab :: (HasCallStack, Marionette m) => m NewWindowResult
newTab :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
m NewWindowResult
newTab =
    Command -> m NewWindowResult
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
        Command
            { command :: Text
command = Text
"WebDriver:NewWindow"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"type" Key -> WindowType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= WindowType
Tab]
            }

-- | Perform a series of grouped input actions at the specified points in
-- time.
--
-- See <https://w3c.github.io/webdriver/#perform-actions>
performActions :: (HasCallStack, Marionette m) => m ()
performActions :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
performActions = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:PerformActions"

-- | Print the current page, returning it as a base64-encoded PDF.
--
-- See <https://w3c.github.io/webdriver/#print-page>
print :: (HasCallStack, Marionette m) => m ()
print :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
print = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:Print"

-- | Reload the page in the current top-level browsing context.
--
-- See <https://w3c.github.io/webdriver/#refresh>
refresh :: (HasCallStack, Marionette m) => m ()
refresh :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
refresh = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:Refresh"

-- | Release all the keys and pointer buttons that are currently
-- depressed.
--
-- See <https://w3c.github.io/webdriver/#release-actions>
releaseActions :: (HasCallStack, Marionette m) => m ()
releaseActions :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
releaseActions = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:ReleaseActions"

-- | Send keys to the input field of a currently displayed modal, or
-- throw if no modal is displayed, or the modal has no means for text
-- input.
--
-- See <https://w3c.github.io/webdriver/#send-alert-text>
sendAlertText :: (HasCallStack, Marionette m) => Text -> m ()
sendAlertText :: forall (m :: * -> *). (HasCallStack, Marionette m) => Text -> m ()
sendAlertText Text
text =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:SendAlertText"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"text" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
text]
            }

-- | Simulate user modification of a permission descriptor's permission
-- state.
--
-- See <https://www.w3.org/TR/permissions/#webdriver-command-set-permission>
setPermission :: (HasCallStack, Marionette m) => m ()
setPermission :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
setPermission = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:SetPermission"

-- | Set the timeouts for page loading, searching, and scripts.
--
-- See <https://w3c.github.io/webdriver/#set-timeouts>
setTimeouts :: (HasCallStack, Marionette m) => Timeouts -> m ()
setTimeouts :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Timeouts -> m ()
setTimeouts Timeouts
timeouts =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:SetTimeouts"
            , parameters :: Value
parameters = Timeouts -> Value
forall a. ToJSON a => a -> Value
toJSON Timeouts
timeouts
            }

-- | Set the position and size of the window on the operating system's
-- window manager. The width and height refer to the window's
-- @outerWidth@ and @outerHeight@, which include browser chrome and
-- OS-level window borders.
--
-- See <https://w3c.github.io/webdriver/#set-window-rect>
setWindowRect :: (HasCallStack, Marionette m) => Rect -> m ()
setWindowRect :: forall (m :: * -> *). (HasCallStack, Marionette m) => Rect -> m ()
setWindowRect Rect
rect =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:SetWindowRect"
            , parameters :: Value
parameters = Rect -> Value
forall a. ToJSON a => a -> Value
toJSON Rect
rect
            }

-- | Switch to the given frame within the current window.
--
-- See <https://w3c.github.io/webdriver/#switch-to-frame>
switchToFrame :: (HasCallStack, Marionette m) => Frame -> m ()
switchToFrame :: forall (m :: * -> *). (HasCallStack, Marionette m) => Frame -> m ()
switchToFrame Frame
frame =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:SwitchToFrame"
            , parameters :: Value
parameters = Frame -> Value
forall a. ToJSON a => a -> Value
toJSON Frame
frame
            }

-- | Set the current browsing context for future commands to the parent
-- of the current browsing context.
--
-- See <https://w3c.github.io/webdriver/#switch-to-parent-frame>
switchToParentFrame :: (HasCallStack, Marionette m) => m ()
switchToParentFrame :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ()
switchToParentFrame = Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_ Command
"WebDriver:SwitchToParentFrame"

-- | Switch to the top-level browsing context identified by the given
-- window handle.
--
-- See <https://w3c.github.io/webdriver/#switch-to-window>
switchToWindow :: (HasCallStack, Marionette m) => WindowHandle -> m ()
switchToWindow :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
WindowHandle -> m ()
switchToWindow WindowHandle
window =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebDriver:SwitchToWindow"
            , parameters :: Value
parameters = WindowHandle -> Value
forall a. ToJSON a => a -> Value
toJSON WindowHandle
window
            }

-- | Take a screenshot of the current frame, returned as a lossless PNG
-- image.
--
-- See <https://w3c.github.io/webdriver/#take-screenshot>
takeScreenshot :: (HasCallStack, Marionette m) => m ByteString
takeScreenshot :: forall (m :: * -> *). (HasCallStack, Marionette m) => m ByteString
takeScreenshot =
    ByteString -> ByteString
Base64.decodeLenient
        (ByteString -> ByteString)
-> (ValueObject Text -> ByteString)
-> ValueObject Text
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
Text.encodeUtf8
        (Text -> ByteString)
-> (ValueObject Text -> Text) -> ValueObject Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueObject Text -> Text
forall a. ValueObject a -> a
value
        (ValueObject Text -> ByteString)
-> m (ValueObject Text) -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject Text)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebDriver:TakeScreenshot"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object []
                }

-- | Add a credential to a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-add-credential>
addCredential :: (HasCallStack, Marionette m) => AuthenticatorId -> Credential -> m ()
addCredential :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> Credential -> m ()
addCredential AuthenticatorId
authenticatorId Credential
credential =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebAuthn:AddCredential"
            , parameters :: Value
parameters =
                Object -> Value
Aeson.Object (Object -> Value) -> ([Object] -> Object) -> [Object] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat ([Object] -> Value) -> [Object] -> Value
forall a b. (a -> b) -> a -> b
$
                    [ [Pair] -> Object
forall v. [(Key, v)] -> KeyMap v
Object.fromList [Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId]
                    , case Credential -> Value
forall a. ToJSON a => a -> Value
toJSON Credential
credential of
                        Aeson.Object Object
o -> Object
o
                        Value
_ -> Object
forall a. Monoid a => a
mempty
                    ]
            }

-- | Add a virtual authenticator, returning its identifier.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-add-virtual-authenticator>
addVirtualAuthenticator :: (HasCallStack, Marionette m) => VirtualAuthenticator -> m AuthenticatorId
addVirtualAuthenticator :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
VirtualAuthenticator -> m AuthenticatorId
addVirtualAuthenticator VirtualAuthenticator
authenticator =
    ValueObject AuthenticatorId -> AuthenticatorId
forall a. ValueObject a -> a
value
        (ValueObject AuthenticatorId -> AuthenticatorId)
-> m (ValueObject AuthenticatorId) -> m AuthenticatorId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject AuthenticatorId)
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebAuthn:AddVirtualAuthenticator"
                , parameters :: Value
parameters = VirtualAuthenticator -> Value
forall a. ToJSON a => a -> Value
toJSON VirtualAuthenticator
authenticator
                }

-- | Get the credentials stored in a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-get-credentials>
getCredentials :: (HasCallStack, Marionette m) => AuthenticatorId -> m [Credential]
getCredentials :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> m [Credential]
getCredentials AuthenticatorId
authenticatorId =
    ValueObject [Credential] -> [Credential]
forall a. ValueObject a -> a
value
        (ValueObject [Credential] -> [Credential])
-> m (ValueObject [Credential]) -> m [Credential]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Command -> m (ValueObject [Credential])
forall a. (HasCallStack, FromJSON a) => Command -> m a
forall (m :: * -> *) a.
(Marionette m, HasCallStack, FromJSON a) =>
Command -> m a
sendCommand
            Command
                { command :: Text
command = Text
"WebAuthn:GetCredentials"
                , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId]
                }

-- | Remove all credentials from a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-remove-all-credentials>
removeAllCredentials :: (HasCallStack, Marionette m) => AuthenticatorId -> m ()
removeAllCredentials :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> m ()
removeAllCredentials AuthenticatorId
authenticatorId =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebAuthn:RemoveAllCredentials"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId]
            }

-- | Remove a credential from a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-remove-credential>
removeCredential :: (HasCallStack, Marionette m) => AuthenticatorId -> CredentialId -> m ()
removeCredential :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> CredentialId -> m ()
removeCredential AuthenticatorId
authenticatorId CredentialId
credentialId =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebAuthn:RemoveCredential"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId
                    , Key
"credentialId" Key -> CredentialId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= CredentialId
credentialId
                    ]
            }

-- | Remove a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-remove-virtual-authenticator>
removeVirtualAuthenticator :: (HasCallStack, Marionette m) => AuthenticatorId -> m ()
removeVirtualAuthenticator :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> m ()
removeVirtualAuthenticator AuthenticatorId
authenticatorId =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebAuthn:RemoveVirtualAuthenticator"
            , parameters :: Value
parameters = [Pair] -> Value
Aeson.object [Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId]
            }

-- | Set the user-verified flag on a virtual authenticator.
--
-- See <https://www.w3.org/TR/webauthn-3/#sctn-automation-set-user-verified>
setUserVerified :: (HasCallStack, Marionette m) => AuthenticatorId -> Bool -> m ()
setUserVerified :: forall (m :: * -> *).
(HasCallStack, Marionette m) =>
AuthenticatorId -> Bool -> m ()
setUserVerified AuthenticatorId
authenticatorId Bool
verified =
    Command -> m ()
forall (m :: * -> *).
(HasCallStack, Marionette m) =>
Command -> m ()
sendCommand_
        Command
            { command :: Text
command = Text
"WebAuthn:SetUserVerified"
            , parameters :: Value
parameters =
                [Pair] -> Value
Aeson.object
                    [ Key
"authenticatorId" Key -> AuthenticatorId -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AuthenticatorId
authenticatorId
                    , Key
"isUserVerified" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
verified
                    ]
            }