{-|
Module      : WebDriverPreCore.HTTP.SpecDefinition 
Description : Deprecated in favour of "WebDriverPreCore.HTTP.API"


-}

module WebDriverPreCore.HTTP.SpecDefinition 
  {-# DEPRECATED "Deprecated in favour of \"WebDriverPreCore.HTTP.API\". SpecDefinition module will be removed in a future release ~ 2027-02-01. See ChangeLog.md for upgrade instructions" #-}
  ( -- * The HttpSpec Type
    HttpSpec (..),

    -- * The API

    -- ** Root Methods
    newSession,
    newSession',
    status,

    -- ** Session Methods
    deleteSession,
    getTimeouts,
    setTimeouts,
    navigateTo,
    getCurrentUrl,
    back,
    forward,
    refresh,
    getTitle,
    getWindowHandle,
    newWindow,
    closeWindow,
    switchToWindow,
    switchToFrame,
    getPageSource,
    executeScript,
    executeScriptAsync,
    addCookie,
    getAllCookies,
    getNamedCookie,
    deleteCookie,
    deleteAllCookies,
    performActions,
    releaseActions,
    dismissAlert,
    acceptAlert,
    getAlertText,
    sendAlertText,
    takeScreenshot,
    printPage,

    -- ** Window Methods
    getWindowHandles,
    getWindowRect,
    setWindowRect,
    maximizeWindow,
    minimizeWindow,
    fullscreenWindow,

    -- ** Frame Methods
    switchToParentFrame,

    -- ** Element(s) Methods
    getActiveElement,
    findElement,
    findElements,

    -- ** Element Instance Methods
    findElementFromElement,
    findElementsFromElement,
    isElementSelected,
    getElementAttribute,
    getElementProperty,
    getElementCssValue,
    getElementShadowRoot,
    getElementText,
    getElementTagName,
    getElementRect,
    isElementEnabled,
    getElementComputedRole,
    getElementComputedLabel,
    elementClick,
    elementClear,
    elementSendKeys,
    takeElementScreenshot,

    -- ** Shadow DOM Methods
    findElementFromShadowRoot,
    findElementsFromShadowRoot,
  )
where

import Data.Aeson as A
  ( FromJSON (..),
    KeyValue ((.=)),
    Result (..),
    ToJSON (toJSON),
    Value (..),
    object, (.:),
  )
import Data.Aeson.Types (parse, Parser)
import Data.Text (Text, unpack)
import WebDriverPreCore.HTTP.HttpResponse (HttpResponse (..))
import WebDriverPreCore.HTTP.Protocol
  ( Actions (..),
    Cookie (..),
    ElementId (..),
    FrameReference (..),
    FullCapabilities (..),
    Handle (..),
    Script (..),
    Selector (..),
    Session (..),
    SessionResponse (..),
    ShadowRootElementId (..),
    Status (..),
    Timeouts (..),
    URL (..),
    WindowHandleSpec (..),
    WindowRect (..)
  )
import AesonUtils (jsonToText)
import Utils (UrlPath (..))
import Prelude hiding (id, lookup)
import Data.Aeson (withObject)
import Control.Monad (when)
import Data.Function ((&))

-- |
--  The 'HttpSpec' type is a specification for a WebDriver Http command.
--  Every endpoint function in this module returns a 'HttpSpec' object.
data HttpSpec a
  = Get
      { forall a. HttpSpec a -> Text
description :: Text,
        forall a. HttpSpec a -> UrlPath
path :: UrlPath,
        forall a. HttpSpec a -> HttpResponse -> Result a
parser :: HttpResponse -> Result a
      }
  | Post
      { description :: Text,
        path :: UrlPath,
        forall a. HttpSpec a -> Value
body :: Value,
        parser :: HttpResponse -> Result a
      }
  | PostEmpty
      { description :: Text,
        path :: UrlPath,
        parser :: HttpResponse -> Result a
      }
  | Delete
      { description :: Text,
        path :: UrlPath,
        parser :: HttpResponse -> Result a
      }

get :: forall a. (FromJSON a) => Text -> UrlPath -> HttpSpec a
get :: forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
description UrlPath
path =
  Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
forall a.
Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
Get Text
description UrlPath
path (Bool -> HttpResponse -> Result a
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
False)

post :: forall c r. (ToJSON c, FromJSON r) => Text -> UrlPath -> c -> HttpSpec r
post :: forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
description UrlPath
path c
body =
  Text
-> UrlPath -> Value -> (HttpResponse -> Result r) -> HttpSpec r
forall a.
Text
-> UrlPath -> Value -> (HttpResponse -> Result a) -> HttpSpec a
Post Text
description UrlPath
path (c -> Value
forall a. ToJSON a => a -> Value
toJSON c
body) (Bool -> HttpResponse -> Result r
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
False)

post_ :: forall c. (ToJSON c) => Text -> UrlPath -> c -> HttpSpec ()
post_ :: forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
description UrlPath
path c
body =
  Text
-> UrlPath -> Value -> (HttpResponse -> Result ()) -> HttpSpec ()
forall a.
Text
-> UrlPath -> Value -> (HttpResponse -> Result a) -> HttpSpec a
Post Text
description UrlPath
path (c -> Value
forall a. ToJSON a => a -> Value
toJSON c
body) (Bool -> HttpResponse -> Result ()
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
True)

postEmpty :: forall a. (FromJSON a) => Text -> UrlPath -> HttpSpec a
postEmpty :: forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
description UrlPath
path =
  Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
forall a.
Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
PostEmpty Text
description UrlPath
path (Bool -> HttpResponse -> Result a
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
False)

postEmpty_ :: Text -> UrlPath -> HttpSpec ()
postEmpty_ :: Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
description UrlPath
path =
  Text -> UrlPath -> (HttpResponse -> Result ()) -> HttpSpec ()
forall a.
Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
PostEmpty Text
description UrlPath
path (Bool -> HttpResponse -> Result ()
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
True)

delete :: forall a. (FromJSON a) => Text -> UrlPath -> HttpSpec a
delete :: forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
delete Text
description UrlPath
path =
  Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
forall a.
Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
Delete Text
description UrlPath
path (Bool -> HttpResponse -> Result a
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
False)

delete_ :: Text -> UrlPath -> HttpSpec ()
delete_ :: Text -> UrlPath -> HttpSpec ()
delete_ Text
description UrlPath
path =
  Text -> UrlPath -> (HttpResponse -> Result ()) -> HttpSpec ()
forall a.
Text -> UrlPath -> (HttpResponse -> Result a) -> HttpSpec a
Delete Text
description UrlPath
path (Bool -> HttpResponse -> Result ()
forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
True)

-- this is to shim the deprecated API with the new
getParser :: forall a. (FromJSON a) => Bool -> HttpResponse -> Result a
getParser :: forall a. FromJSON a => Bool -> HttpResponse -> Result a
getParser Bool
expectNull HttpResponse
r = (Value -> Parser a) -> Value -> Result a
forall a b. (a -> Parser b) -> a -> Result b
parse (Bool -> Value -> Parser a
forall a. FromJSON a => Bool -> Value -> Parser a
fromBodyValue Bool
expectNull) HttpResponse
r.body

fromBodyValue :: forall a. (FromJSON a) => Bool -> Value -> Parser a
fromBodyValue :: forall a. FromJSON a => Bool -> Value -> Parser a
fromBodyValue Bool
expectNull Value
body =
  Value
body Value -> (Value -> Parser a) -> Parser a
forall a b. a -> (a -> b) -> b
& String -> (Object -> Parser a) -> Value -> Parser a
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"body value" \Object
b -> do
    val <- Object
b Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
    when (expectNull && val /= Null) $
      fail $
        unpack $
          "Null value expected but got:\n" <> jsonToText val
    parseJSON $ val

instance (Show a) => Show (HttpSpec a) where
  show :: HttpSpec a -> String
  show :: HttpSpec a -> String
show = HttpSpecShowable -> String
forall a. Show a => a -> String
Prelude.show (HttpSpecShowable -> String)
-> (HttpSpec a -> HttpSpecShowable) -> HttpSpec a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HttpSpec a -> HttpSpecShowable
forall a. HttpSpec a -> HttpSpecShowable
mkShowable

data HttpSpecShowable = Request
  { HttpSpecShowable -> Text
description :: Text,
    HttpSpecShowable -> Text
method :: Text,
    HttpSpecShowable -> UrlPath
path :: UrlPath,
    HttpSpecShowable -> Maybe Text
body :: Maybe Text
  }
  deriving (Int -> HttpSpecShowable -> ShowS
[HttpSpecShowable] -> ShowS
HttpSpecShowable -> String
(Int -> HttpSpecShowable -> ShowS)
-> (HttpSpecShowable -> String)
-> ([HttpSpecShowable] -> ShowS)
-> Show HttpSpecShowable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HttpSpecShowable -> ShowS
showsPrec :: Int -> HttpSpecShowable -> ShowS
$cshow :: HttpSpecShowable -> String
show :: HttpSpecShowable -> String
$cshowList :: [HttpSpecShowable] -> ShowS
showList :: [HttpSpecShowable] -> ShowS
Show)

mkShowable :: HttpSpec a -> HttpSpecShowable
mkShowable :: forall a. HttpSpec a -> HttpSpecShowable
mkShowable = \case
  Get Text
d UrlPath
p HttpResponse -> Result a
_ -> Text -> Text -> UrlPath -> Maybe Text -> HttpSpecShowable
Request Text
d Text
"GET" UrlPath
p Maybe Text
forall a. Maybe a
Nothing
  Post Text
d UrlPath
p Value
b HttpResponse -> Result a
_ -> Text -> Text -> UrlPath -> Maybe Text -> HttpSpecShowable
Request Text
d Text
"POST" UrlPath
p (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Value -> Text
jsonToText Value
b)
  PostEmpty Text
d UrlPath
p HttpResponse -> Result a
_ -> Text -> Text -> UrlPath -> Maybe Text -> HttpSpecShowable
Request Text
d Text
"POST" UrlPath
p Maybe Text
forall a. Maybe a
Nothing
  Delete Text
d UrlPath
p HttpResponse -> Result a
_ -> Text -> Text -> UrlPath -> Maybe Text -> HttpSpecShowable
Request Text
d Text
"DELETE" UrlPath
p Maybe Text
forall a. Maybe a
Nothing

-- ######################################################################
-- ########################### WebDriver API ############################
-- ######################################################################

-- https://www.w3.org/TR/2025/WD-webdriver2-20251028/
-- 61 endpoints
-- Method 	URI Template 	Command

-- ** Root Methods

-- |
--  Return a spec to create a new session given 'FullCapabilities' object.
--
-- 'newSession'' can be used if 'FullCapabilities' doesn't meet your requirements.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#new-session)
--
--  @POST 	\/session 	New Session@
newSession :: FullCapabilities -> HttpSpec SessionResponse
newSession :: FullCapabilities -> HttpSpec SessionResponse
newSession = FullCapabilities -> HttpSpec SessionResponse
forall a. ToJSON a => a -> HttpSpec SessionResponse
newSession'

-- |
--
--  Return a spec to create a new session given an object of any type that implements `ToJSON`.
--
-- The 'FullCapabilities' type and associated types should work for the vast majority use cases, but if the required capabilities are not covered by the types provided, 'newSession''.
-- can be used with a custom type instead. 'newSession'' works with any type that implements 'ToJSON', (including an Aeson 'Value').
--
-- Obviously, any type used must produce a JSON object compatible with [capabilities as defined W3C spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#capabilities).
--
--  [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#new-session)
--
--  @POST 	\/session 	New Session@
newSession' :: (ToJSON a) => a -> HttpSpec SessionResponse
newSession' :: forall a. ToJSON a => a -> HttpSpec SessionResponse
newSession' = Text -> UrlPath -> a -> HttpSpec SessionResponse
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"New Session" UrlPath
newSessionUrl

-- |
--
-- Return a spec to get the status of the driver.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#status)
--
-- @GET 	\/status 	Status@
status :: HttpSpec Status
status :: HttpSpec Status
status = Text -> UrlPath -> HttpSpec Status
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Status" ([Text] -> UrlPath
MkUrlPath [Text
"status"])

-- ############################ Session Methods ##########################################

-- |
--
-- Return a spec to delete a session given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#delete-session)
--
-- @DELETE 	\/session\/{session id} 	Delete Session@
deleteSession :: Session -> HttpSpec ()
deleteSession :: Session -> HttpSpec ()
deleteSession Session
sessionRef = Text -> UrlPath -> HttpSpec ()
delete_ Text
"Delete Session" (Text -> UrlPath
sessionUri Session
sessionRef.id)

-- |
--
-- Return a spec to get the timeouts of a session given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-timeouts)
--
-- @GET 	\/session\/{session id}\/timeouts 	Get Timeouts@
getTimeouts :: Session -> HttpSpec Timeouts
getTimeouts :: Session -> HttpSpec Timeouts
getTimeouts Session
sessionRef = Text -> UrlPath -> HttpSpec Timeouts
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Timeouts" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"timeouts")

-- |
--
-- Return a spec to set the timeouts of a session given a 'Session' and 'Timeouts'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#set-timeouts)
--
-- @POST 	\/session\/{session id}\/timeouts 	Set Timeouts@
setTimeouts :: Session -> Timeouts -> HttpSpec ()
setTimeouts :: Session -> Timeouts -> HttpSpec ()
setTimeouts Session
sessionRef Timeouts
timeouts =
  Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Set Timeouts" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"timeouts") (Timeouts -> Value
forall a. ToJSON a => a -> Value
toJSON Timeouts
timeouts)

-- |
--
-- Return a spec to navigate to a URL given a 'Session' and a 'Text' URL.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#navigate-to)
--
-- @POST 	\/session\/{session id}\/url 	Navigate To@
navigateTo :: Session -> URL -> HttpSpec ()
navigateTo :: Session -> URL -> HttpSpec ()
navigateTo Session
sessionRef URL
url = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Navigate To" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"url")  ([Pair] -> Value
object [Key
"url" Key -> URL -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= URL
url])

-- |
--
-- Return a spec to get the current URL of a session given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-current-url)
--
-- @GET 	\/session\/{session id}\/url 	Get Current URL@
getCurrentUrl :: Session -> HttpSpec URL
getCurrentUrl :: Session -> HttpSpec URL
getCurrentUrl Session
sessionRef = Text -> UrlPath -> HttpSpec URL
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Current URL" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"url")

-- |
--
-- Return a spec to navigate back in the browser history given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#back)
--
-- @POST 	\/session\/{session id}\/back 	Back@
back :: Session -> HttpSpec ()
back :: Session -> HttpSpec ()
back Session
sessionRef = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Back" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"back")

-- |
--
-- Return a spec to navigate forward in the browser history given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#forward)
--
-- @POST 	\/session\/{session id}\/forward 	Forward@
forward :: Session -> HttpSpec ()
forward :: Session -> HttpSpec ()
forward Session
sessionRef = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Forward" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"forward")

-- |
--
-- Return a spec to refresh the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#refresh)
--
-- @POST 	\/session\/{session id}\/refresh 	Refresh@
refresh :: Session -> HttpSpec ()
refresh :: Session -> HttpSpec ()
refresh Session
sessionRef = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Refresh" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"refresh")

-- |
--
-- Return a spec to get the title of the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-title)
--
-- @GET 	\/session\/{session id}\/title 	Get Title@
getTitle :: Session -> HttpSpec Text
getTitle :: Session -> HttpSpec Text
getTitle Session
sessionRef = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Title" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"title")

-- |
--
-- Return a spec to get the current window handle given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-window-handle)
--
-- @GET 	\/session\/{session id}\/window 	Get Window Handle@
getWindowHandle :: Session -> HttpSpec Handle
getWindowHandle :: Session -> HttpSpec Handle
getWindowHandle Session
sessionRef = Text -> UrlPath -> HttpSpec Handle
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Window Handle" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"window")

-- |
--
-- Return a spec to create a new window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#new-window)
--
-- @POST 	\/session\/{session id}\/window\/new 	New Window@
newWindow :: Session -> HttpSpec WindowHandleSpec
newWindow :: Session -> HttpSpec WindowHandleSpec
newWindow Session
sessionRef = Text -> UrlPath -> HttpSpec WindowHandleSpec
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
"New Window" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionRef Text
"window" Text
"new")

-- |
--
-- Return a spec to close the current window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#close-window)
--
-- @DELETE 	\/session\/{session id}\/window 	Close Window@
closeWindow :: Session -> HttpSpec [Handle]
closeWindow :: Session -> HttpSpec [Handle]
closeWindow Session
sessionRef = Text -> UrlPath -> HttpSpec [Handle]
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
delete Text
"Close Window" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"window")

-- |
--
-- Return a spec to switch to a different window given a 'Session' and 'WindowHandle'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#switch-to-window)
--
-- @POST 	\/session\/{session id}\/window 	Switch To Window@
switchToWindow :: Session -> Handle -> HttpSpec ()
switchToWindow :: Session -> Handle -> HttpSpec ()
switchToWindow Session
sessionRef MkHandle {Text
handle :: Text
handle :: Handle -> Text
handle} = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Switch To Window" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"window") ([Pair] -> Value
object [Key
"handle" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
handle])

-- |
--
-- Return a spec to switch to a different frame given a 'Session' and 'FrameReference'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#switch-to-frame)
--
-- @POST 	\/session\/{session id}\/frame 	Switch To Frame@
switchToFrame :: Session -> FrameReference -> HttpSpec ()
switchToFrame :: Session -> FrameReference -> HttpSpec ()
switchToFrame Session
sessionRef FrameReference
frameRef = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Switch To Frame" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"frame") (FrameReference -> Value
forall a. ToJSON a => a -> Value
toJSON FrameReference
frameRef)

-- |
--
-- Return a spec to get the source of the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-page-source)
--
-- @GET 	\/session\/{session id}\/source 	Get Page Source@
getPageSource :: Session -> HttpSpec Text
getPageSource :: Session -> HttpSpec Text
getPageSource Session
sessionId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Page Source" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"source")

-- |
--
-- Return a spec to execute a script in the context of the current page given a 'Session', 'Text' script, and a list of 'Value' arguments.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#execute-script)
--
-- @POST 	\/session\/{session id}\/execute\/sync 	Execute Script@
executeScript :: Session -> Script -> HttpSpec Value
executeScript :: Session -> Script -> HttpSpec Value
executeScript Session
sessionId Script
script = Text -> UrlPath -> Value -> HttpSpec Value
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Execute Script" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"execute" Text
"sync") (Script -> Value
forall a. ToJSON a => a -> Value
toJSON Script
script)

-- |
--
-- Return a spec to execute an asynchronous script in the context of the current page given a 'Session', 'Text' script, and a list of 'Value' arguments.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#execute-async-script)
--
-- @POST 	\/session\/{session id}\/execute\/async 	Execute Async Script@
executeScriptAsync :: Session -> Script -> HttpSpec Value
executeScriptAsync :: Session -> Script -> HttpSpec Value
executeScriptAsync Session
sessionId Script
script = Text -> UrlPath -> Script -> HttpSpec Value
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Execute Async Script" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"execute" Text
"async") Script
script

-- |
--
-- Return a spec to get all cookies of the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-all-cookies)
--
-- @GET 	\/session\/{session id}\/cookie 	Get All Cookies@
getAllCookies :: Session -> HttpSpec [Cookie]
getAllCookies :: Session -> HttpSpec [Cookie]
getAllCookies Session
sessionId = Text -> UrlPath -> HttpSpec [Cookie]
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get All Cookies" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"cookie")

-- |
--
-- Return a spec to get a named cookie of the current page given a 'Session' and cookie name.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-named-cookie)
--
-- @GET 	\/session\/{session id}\/cookie\/{name} 	Get Named Cookie@
getNamedCookie :: Session -> Text -> HttpSpec Cookie
getNamedCookie :: Session -> Text -> HttpSpec Cookie
getNamedCookie Session
sessionId Text
cookieName = Text -> UrlPath -> HttpSpec Cookie
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Named Cookie" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"cookie" Text
cookieName)

-- |
--
-- Return a spec to add a cookie to the current page given a 'Session' and 'Cookie'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#add-cookie)
--
-- @POST 	\/session\/{session id}\/cookie 	Add Cookie@
addCookie :: Session -> Cookie -> HttpSpec ()
addCookie :: Session -> Cookie -> HttpSpec ()
addCookie Session
sessionId Cookie
cookie = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Add Cookie" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"cookie") ([Pair] -> Value
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])

-- |
--
-- Return a spec to delete a named cookie from the current page given a 'Session' and cookie name.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#delete-cookie)
--
-- @DELETE 	\/session\/{session id}\/cookie\/{name} 	Delete Cookie@
deleteCookie :: Session -> Text -> HttpSpec ()
deleteCookie :: Session -> Text -> HttpSpec ()
deleteCookie Session
sessionId Text
cookieName = Text -> UrlPath -> HttpSpec ()
delete_ Text
"Delete Cookie" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"cookie" Text
cookieName)

-- |
--
-- Return a spec to delete all cookies from the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#delete-all-cookies)
--
-- @DELETE 	\/session\/{session id}\/cookie 	Delete All Cookies@
deleteAllCookies :: Session -> HttpSpec ()
deleteAllCookies :: Session -> HttpSpec ()
deleteAllCookies Session
sessionId = Text -> UrlPath -> HttpSpec ()
delete_ Text
"Delete All Cookies" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"cookie")

-- |
--
-- Return a spec to perform actions on the current page given a 'Session' and 'Actions'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#perform-actions)
--
-- @POST 	\/session\/{session id}\/actions 	Perform Actions@
performActions :: Session -> Actions -> HttpSpec ()
performActions :: Session -> Actions -> HttpSpec ()
performActions Session
sessionId Actions
actions = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Perform Actions" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"actions") (Actions -> Value
forall a. ToJSON a => a -> Value
toJSON Actions
actions)

-- |
--
-- Return a spec to release actions on the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#release-actions)
--
-- @DELETE 	\/session\/{session id}\/actions 	Release Actions@
releaseActions :: Session -> HttpSpec ()
releaseActions :: Session -> HttpSpec ()
releaseActions Session
sessionId = Text -> UrlPath -> HttpSpec ()
delete_ Text
"Release Actions" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"actions")

-- |
--
-- Return a spec to dismiss an alert on the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#dismiss-alert)
--
-- @POST 	\/session\/{session id}\/alert\/dismiss 	Dismiss Alert@
dismissAlert :: Session -> HttpSpec ()
dismissAlert :: Session -> HttpSpec ()
dismissAlert Session
sessionId = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Dismiss Alert" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"alert" Text
"dismiss")

-- |
--
-- Return a spec to accept an alert on the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#accept-alert)
--
-- @POST 	\/session\/{session id}\/alert\/accept 	Accept Alert@
acceptAlert :: Session -> HttpSpec ()
acceptAlert :: Session -> HttpSpec ()
acceptAlert Session
sessionId = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Accept Alert" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"alert" Text
"accept")

-- |
--
-- Return a spec to get the text of an alert on the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-alert-text)
--
-- @GET 	\/session\/{session id}\/alert\/text 	Get Alert Text@
getAlertText :: Session -> HttpSpec Text
getAlertText :: Session -> HttpSpec Text
getAlertText Session
sessionId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Alert Text" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"alert" Text
"text")

-- |
--
-- Return a spec to send text to an alert on the current page given a 'Session' and 'Text'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#send-alert-text)
--
-- @POST 	\/session\/{session id}\/alert\/text 	Send Alert Text@
sendAlertText :: Session -> Text -> HttpSpec ()
sendAlertText :: Session -> Text -> HttpSpec ()
sendAlertText Session
sessionId Text
text = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Send Alert Text" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"alert" Text
"text") ([Pair] -> Value
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])

-- |
--
-- Return a spec to take a screenshot of the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#take-screenshot)
--
-- @GET 	\/session\/{session id}\/screenshot 	Take Screenshot@
takeScreenshot :: Session -> HttpSpec Text
takeScreenshot :: Session -> HttpSpec Text
takeScreenshot Session
sessionId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Take Screenshot" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"screenshot")

-- |
--
-- Return a spec to print the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#print-page)
--
-- @POST 	\/session\/{session id}\/print 	Print Page@
printPage :: Session -> HttpSpec Text
printPage :: Session -> HttpSpec Text
printPage Session
sessionId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
"Print Page" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"print")

-- ############################ Window Methods ##########################################

-- |
--
-- Return a spec to get all window handles of the current session given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-window-handles)
--
-- @GET 	\/session\/{session id}\/window\/handles 	Get Window Handles@
getWindowHandles :: Session -> HttpSpec [Handle]
getWindowHandles :: Session -> HttpSpec [Handle]
getWindowHandles Session
sessionRef = Text -> UrlPath -> HttpSpec [Handle]
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Window Handles" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionRef Text
"window" Text
"handles")

-- |
--
-- Return a spec to get the window rect of the current window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-window-rect)
--
-- @GET 	\/session\/{session id}\/window\/rect 	Get Window Rect@
getWindowRect :: Session -> HttpSpec WindowRect
getWindowRect :: Session -> HttpSpec WindowRect
getWindowRect Session
sessionRef = Text -> UrlPath -> HttpSpec WindowRect
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Window Rect" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionRef Text
"window" Text
"rect")

-- |
--
-- Return a spec to set the window rect of the current window given a 'Session' and 'WindowRect'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#set-window-rect)
--
-- @POST 	\/session\/{session id}\/window\/rect 	Set Window Rect@
setWindowRect :: Session -> WindowRect -> HttpSpec WindowRect
setWindowRect :: Session -> WindowRect -> HttpSpec WindowRect
setWindowRect Session
sessionRef = Text -> UrlPath -> WindowRect -> HttpSpec WindowRect
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Set Window Rect" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionRef Text
"window" Text
"rect")

-- |
--
-- Return a spec to maximize the current window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#maximize-window)
--
-- @POST 	\/session\/{session id}\/window\/maximize 	Maximize Window@
maximizeWindow :: Session -> HttpSpec WindowRect
maximizeWindow :: Session -> HttpSpec WindowRect
maximizeWindow Session
sessionRef = Text -> UrlPath -> HttpSpec WindowRect
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
"Maximize Window" (Session -> Text -> UrlPath
windowUri1 Session
sessionRef Text
"maximize")

-- |
--
-- Return a spec to minimize the current window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#minimize-window)
--
-- @POST 	\/session\/{session id}\/window\/minimize 	Minimize Window@
minimizeWindow :: Session -> HttpSpec WindowRect
minimizeWindow :: Session -> HttpSpec WindowRect
minimizeWindow Session
sessionRef = Text -> UrlPath -> HttpSpec WindowRect
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
"Minimize Window" (Session -> Text -> UrlPath
windowUri1 Session
sessionRef Text
"minimize")

-- |
--
-- Return a spec to fullscreen the current window given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#fullscreen-window)
--
-- @POST 	\/session\/{session id}\/window\/fullscreen 	Fullscreen Window@
fullscreenWindow :: Session -> HttpSpec WindowRect
fullscreenWindow :: Session -> HttpSpec WindowRect
fullscreenWindow Session
sessionRef = Text -> UrlPath -> HttpSpec WindowRect
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
postEmpty Text
"Fullscreen Window" (Session -> Text -> UrlPath
windowUri1 Session
sessionRef Text
"fullscreen")

-- ############################ Frame Methods ##########################################

-- |
--
-- Return a spec to switch to the parent frame given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#switch-to-parent-frame)
--
-- @POST 	\/session\/{session id}\/frame\/parent 	Switch To Parent Frame@
switchToParentFrame :: Session -> HttpSpec ()
switchToParentFrame :: Session -> HttpSpec ()
switchToParentFrame Session
sessionRef = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Switch To Parent Frame" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionRef Text
"frame" Text
"parent")

-- ############################ Element(s) Methods ##########################################

-- |
--
-- Return a spec to get the active element of the current page given a 'Session'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-active-element)
--
-- @GET 	\/session\/{session id}\/element\/active 	Get Active Element@
getActiveElement :: Session -> HttpSpec ElementId
getActiveElement :: Session -> HttpSpec ElementId
getActiveElement Session
sessionId = Text -> UrlPath -> HttpSpec ElementId
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Active Element" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"element" Text
"active")

-- |
--
-- Return a spec to find an element on the current page given a 'Session' and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-element)
--
-- @POST 	\/session\/{session id}\/element 	Find Element@
findElement :: Session -> Selector -> HttpSpec ElementId
findElement :: Session -> Selector -> HttpSpec ElementId
findElement Session
sessionRef = Text -> UrlPath -> Selector -> HttpSpec ElementId
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Element" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"element")

-- |
--
-- Return a spec to find elements on the current page given a 'Session' and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-elements)
--
-- @POST 	\/session\/{session id}\/elements 	Find Elements@
findElements :: Session -> Selector -> HttpSpec [ElementId]
findElements :: Session -> Selector -> HttpSpec [ElementId]
findElements Session
sessionRef = Text -> UrlPath -> Selector -> HttpSpec [ElementId]
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Elements" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"elements")

-- ############################ Element Instance Methods ##########################################

-- |
--
-- Return a spec to get the shadow root of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-shadow-root)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/shadow 	Get Element Shadow Root@
getElementShadowRoot :: Session -> ElementId -> HttpSpec ShadowRootElementId
getElementShadowRoot :: Session -> ElementId -> HttpSpec ShadowRootElementId
getElementShadowRoot Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec ShadowRootElementId
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Shadow Root" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"shadow")

-- |
--
-- Return a spec to find an element from another element given a 'Session', 'ElementId', and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-element-from-element)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/element 	Find Element From Element@
findElementFromElement :: Session -> ElementId -> Selector -> HttpSpec ElementId
findElementFromElement :: Session -> ElementId -> Selector -> HttpSpec ElementId
findElementFromElement Session
sessionId ElementId
elementId = Text -> UrlPath -> Selector -> HttpSpec ElementId
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Element From Element" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"element")

-- |
--
-- Return a spec to find elements from another element given a 'Session', 'ElementId', and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-elements-from-element)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/elements 	Find Elements From Element@
findElementsFromElement :: Session -> ElementId -> Selector -> HttpSpec [ElementId]
findElementsFromElement :: Session -> ElementId -> Selector -> HttpSpec [ElementId]
findElementsFromElement Session
sessionId ElementId
elementId = Text -> UrlPath -> Selector -> HttpSpec [ElementId]
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Elements From Element" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"elements")

-- |
--
-- Return a spec to check if an element is selected given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#is-element-selected)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/selected 	Is Element Selected@
isElementSelected :: Session -> ElementId -> HttpSpec Bool
isElementSelected :: Session -> ElementId -> HttpSpec Bool
isElementSelected Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Bool
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Is Element Selected" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"selected")

-- |
--
-- Return a spec to get an attribute of an element given a 'Session', 'ElementId', and attribute name.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-attribute)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/attribute\/{name} 	Get Element Attribute@
getElementAttribute :: Session -> ElementId -> Text -> HttpSpec Text
getElementAttribute :: Session -> ElementId -> Text -> HttpSpec Text
getElementAttribute Session
sessionId ElementId
elementId Text
attributeName = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Attribute" (Session -> ElementId -> Text -> Text -> UrlPath
elementUri2 Session
sessionId ElementId
elementId Text
"attribute" Text
attributeName)

-- |
--
-- Return a spec to get a property of an element given a 'Session', 'ElementId', and property name.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-property)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/property\/{name} 	Get Element Property@
getElementProperty :: Session -> ElementId -> Text -> HttpSpec Value
getElementProperty :: Session -> ElementId -> Text -> HttpSpec Value
getElementProperty Session
sessionId ElementId
elementId Text
propertyName = Text -> UrlPath -> HttpSpec Value
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Property" (Session -> ElementId -> Text -> Text -> UrlPath
elementUri2 Session
sessionId ElementId
elementId Text
"property" Text
propertyName)

-- |
--
-- Return a spec to get the CSS value of an element given a 'Session', 'ElementId', and CSS property name.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-css-value)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/css\/{property name} 	Get Element CSS Value@
getElementCssValue :: Session -> ElementId -> Text -> HttpSpec Text
getElementCssValue :: Session -> ElementId -> Text -> HttpSpec Text
getElementCssValue Session
sessionId ElementId
elementId Text
propertyName = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element CSS Value" (Session -> ElementId -> Text -> Text -> UrlPath
elementUri2 Session
sessionId ElementId
elementId Text
"css" Text
propertyName)

-- |
--
-- Return a spec to get the text of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-text)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/text 	Get Element Text@
getElementText :: Session -> ElementId -> HttpSpec Text
getElementText :: Session -> ElementId -> HttpSpec Text
getElementText Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Text" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"text")

-- |
--
-- Return a spec to get the tag name of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-tag-name)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/name 	Get Element Tag Name@
getElementTagName :: Session -> ElementId -> HttpSpec Text
getElementTagName :: Session -> ElementId -> HttpSpec Text
getElementTagName Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Tag Name" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"name")

-- |
--
-- Return a spec to get the rect of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-element-rect)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/rect 	Get Element Rect@
getElementRect :: Session -> ElementId -> HttpSpec WindowRect
getElementRect :: Session -> ElementId -> HttpSpec WindowRect
getElementRect Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec WindowRect
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Element Rect" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"rect")

-- |
--
-- Return a spec to check if an element is enabled given a 'Session' and 'ElementId'.
--SAP will foc
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#is-element-enabled)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/enabled 	Is Element Enabled@
isElementEnabled :: Session -> ElementId -> HttpSpec Bool
isElementEnabled :: Session -> ElementId -> HttpSpec Bool
isElementEnabled Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Bool
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Is Element Enabled" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"enabled")

-- |
--
-- Return a spec to get the computed role of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-computed-role)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/computedrole 	Get Computed Role@
getElementComputedRole :: Session -> ElementId -> HttpSpec Text
getElementComputedRole :: Session -> ElementId -> HttpSpec Text
getElementComputedRole Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Computed Role" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"computedrole")

-- |
--
-- Return a spec to get the computed label of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#get-computed-label)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/computedlabel 	Get Computed Label@
getElementComputedLabel :: Session -> ElementId -> HttpSpec Text
getElementComputedLabel :: Session -> ElementId -> HttpSpec Text
getElementComputedLabel Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Get Computed Label" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"computedlabel")

-- |
--
-- Return a spec to click an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#element-click)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/click 	Element Click@
elementClick :: Session -> ElementId -> HttpSpec ()
elementClick :: Session -> ElementId -> HttpSpec ()
elementClick Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Element Click" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"click")

-- |
--
-- Return a spec to clear an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#element-clear)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/clear 	Element Clear@
elementClear :: Session -> ElementId -> HttpSpec ()
elementClear :: Session -> ElementId -> HttpSpec ()
elementClear Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec ()
postEmpty_ Text
"Element Clear" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"clear")

-- |
--
-- Return a spec to send keys to an element given a 'Session', 'ElementId', and keys to send.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#element-send-keys)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/value 	Element Send Keys@
elementSendKeys :: Session -> ElementId -> Text -> HttpSpec ()
elementSendKeys :: Session -> ElementId -> Text -> HttpSpec ()
elementSendKeys Session
sessionId ElementId
elementId Text
keysToSend = Text -> UrlPath -> Value -> HttpSpec ()
forall c. ToJSON c => Text -> UrlPath -> c -> HttpSpec ()
post_ Text
"Element Send Keys" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"value") ([Pair] -> Value
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
keysToSend])

-- |
--
-- Return a spec to take a screenshot of an element given a 'Session' and 'ElementId'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#take-element-screenshot)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/screenshot 	Take Element Screenshot@
takeElementScreenshot :: Session -> ElementId -> HttpSpec Text
takeElementScreenshot :: Session -> ElementId -> HttpSpec Text
takeElementScreenshot Session
sessionId ElementId
elementId = Text -> UrlPath -> HttpSpec Text
forall a. FromJSON a => Text -> UrlPath -> HttpSpec a
get Text
"Take Element Screenshot" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"screenshot")

-- ############################ Shadow DOM Methods ##########################################

-- |
--
-- Return a spec to find an element from the shadow root given a 'Session', 'ElementId', and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-element-from-shadow-root)
--
-- @POST 	\/session\/{session id}\/shadow\/{shadow id}\/element 	Find Element From Shadow Root@
findElementFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> HttpSpec ElementId
findElementFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> HttpSpec ElementId
findElementFromShadowRoot Session
sessionId ShadowRootElementId
shadowId = Text -> UrlPath -> Selector -> HttpSpec ElementId
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Element From Shadow Root" (Session -> Text -> Text -> Text -> UrlPath
sessionUri3 Session
sessionId Text
"shadow" ShadowRootElementId
shadowId.id Text
"element")

-- |
--
-- Return a spec to find elements from the shadow root given a 'Session', 'ElementId', and 'Selector'.
--
-- [spec](https://www.w3.org/TR/2025/WD-webdriver2-20251028/#find-elements-from-shadow-root)
--
-- @POST 	\/session\/{session id}\/shadow\/{shadow id}\/elements 	Find Elements From Shadow Root@
findElementsFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> HttpSpec [ElementId]
findElementsFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> HttpSpec [ElementId]
findElementsFromShadowRoot Session
sessionId ShadowRootElementId
shadowId = Text -> UrlPath -> Selector -> HttpSpec [ElementId]
forall c r.
(ToJSON c, FromJSON r) =>
Text -> UrlPath -> c -> HttpSpec r
post Text
"Find Elements From Shadow Root" (Session -> Text -> Text -> Text -> UrlPath
sessionUri3 Session
sessionId Text
"shadow" ShadowRootElementId
shadowId.id Text
"elements")

-- ############################ Utils ##########################################

sessionUri :: Text -> UrlPath
sessionUri :: Text -> UrlPath
sessionUri Text
sp = [Text] -> UrlPath
MkUrlPath [Text
session, Text
sp]

sessionUri1 :: Session -> Text -> UrlPath
sessionUri1 :: Session -> Text -> UrlPath
sessionUri1 Session
s Text
sp = [Text] -> UrlPath
MkUrlPath [Text
session, Session
s.id, Text
sp]

sessionUri2 :: Session -> Text -> Text -> UrlPath
sessionUri2 :: Session -> Text -> Text -> UrlPath
sessionUri2 Session
s Text
sp Text
sp2 = [Text] -> UrlPath
MkUrlPath [Text
session, Session
s.id, Text
sp, Text
sp2]

sessionUri3 :: Session -> Text -> Text -> Text -> UrlPath
sessionUri3 :: Session -> Text -> Text -> Text -> UrlPath
sessionUri3 Session
s Text
sp Text
sp2 Text
sp3 = [Text] -> UrlPath
MkUrlPath [Text
session, Session
s.id, Text
sp, Text
sp2, Text
sp3]

sessionUri4 :: Session -> Text -> Text -> Text -> Text -> UrlPath
sessionUri4 :: Session -> Text -> Text -> Text -> Text -> UrlPath
sessionUri4 Session
s Text
sp Text
sp2 Text
sp3 Text
sp4 = [Text] -> UrlPath
MkUrlPath [Text
session, Session
s.id, Text
sp, Text
sp2, Text
sp3, Text
sp4]

window :: Text
window :: Text
window = Text
"window"

windowUri1 :: Session -> Text -> UrlPath
windowUri1 :: Session -> Text -> UrlPath
windowUri1 Session
sr Text
sp = Session -> Text -> Text -> UrlPath
sessionUri2 Session
sr Text
window Text
sp

elementUri1 :: Session -> ElementId -> Text -> UrlPath
elementUri1 :: Session -> ElementId -> Text -> UrlPath
elementUri1 Session
s ElementId
er Text
ep = Session -> Text -> Text -> Text -> UrlPath
sessionUri3 Session
s Text
"element" ElementId
er.id Text
ep

elementUri2 :: Session -> ElementId -> Text -> Text -> UrlPath
elementUri2 :: Session -> ElementId -> Text -> Text -> UrlPath
elementUri2 Session
s ElementId
er Text
ep Text
ep2 = Session -> Text -> Text -> Text -> Text -> UrlPath
sessionUri4 Session
s Text
"element" ElementId
er.id Text
ep Text
ep2

newSessionUrl :: UrlPath
newSessionUrl :: UrlPath
newSessionUrl = [Text] -> UrlPath
MkUrlPath [Text
session]

session :: Text
session :: Text
session = Text
"session"