{-# LANGUAGE CPP #-}

{-

    -- | Type definitions for commands for all [WebDriver HTTP endpoints](HTMLSpecURL).
    --
    -- See the demos in the [demos](https://github.com/pyrethrum/webdriver/blob/main/webdriver-precore/test/README.md) for how this module can be used to develop a WebDriver client.
    --


-}

module WebDriverPreCore.HTTP.API
  ( -- * Root Methods
    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
  ( KeyValue ((.=)),
    Value (..),
  )
import Data.Text (Text)
import WebDriverPreCore.HTTP.Protocol
  ( Actions (..),
    Cookie (..),
    Status (..),
    ElementId (..),
    FrameReference (..),
    FullCapabilities,
    Script,
    Selector (..),
    Session (..),
    SessionResponse (..),
    Timeouts,
    URL,
    Handle (..),
    WindowHandleSpec (..),
    WindowRect (..), 
    ShadowRootElementId(..),
    Command(..),
    mkPost,
    mkPost'
  )
import Utils (UrlPath (..))
import Prelude hiding (id, lookup)
import Data.Aeson.KeyMap (fromList)

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

-- ** 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](HTMLSpecURL#new-session)
--
--  @POST 	\/session 	New Session@
newSession :: FullCapabilities -> Command SessionResponse
newSession :: FullCapabilities -> Command SessionResponse
newSession = Text -> UrlPath -> FullCapabilities -> Command SessionResponse
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"New Session" UrlPath
newSessionUrl

-- |
--
-- Return a spec to get the status of the driver.
--
-- [spec](HTMLSpecURL#status)
--
-- @GET 	\/status 	Status@
status :: Command Status
status :: Command Status
status = Text -> UrlPath -> Command Status
forall {k} (r :: k). Text -> UrlPath -> Command r
Get Text
"Status" (UrlPath -> Command Status) -> UrlPath -> Command Status
forall a b. (a -> b) -> a -> b
$ [Text] -> UrlPath
MkUrlPath [Text
"status"]

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

-- |
--
-- Return a spec to delete a session given a 'Session'.
--
-- [spec](HTMLSpecURL#delete-session)
--
-- @DELETE 	\/session\/{session id} 	Delete Session@
deleteSession :: Session -> Command ()
deleteSession :: Session -> Command ()
deleteSession Session
sessionRef = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
Delete Text
"Delete Session" (UrlPath -> Command ()) -> UrlPath -> Command ()
forall a b. (a -> b) -> a -> b
$ Text -> UrlPath
sessionUri Session
sessionRef.id

-- |
--
-- Return a spec to get the timeouts of a session given a 'Session'.
--
-- [spec](HTMLSpecURL#get-timeouts)
--
-- @GET 	\/session\/{session id}\/timeouts 	Get Timeouts@
getTimeouts :: Session -> Command Timeouts
getTimeouts :: Session -> Command Timeouts
getTimeouts Session
sessionRef = Text -> UrlPath -> Command Timeouts
forall {k} (r :: k). Text -> UrlPath -> Command r
Get Text
"Get Timeouts" (UrlPath -> Command Timeouts) -> UrlPath -> Command Timeouts
forall a b. (a -> b) -> a -> b
$ Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"timeouts"

-- |
--
-- Return a spec to set the timeouts of a session given a 'Session' and 'Timeouts'.
--
-- [spec](HTMLSpecURL#set-timeouts)
--
-- @POST 	\/session\/{session id}\/timeouts 	Set Timeouts@
setTimeouts :: Session -> Timeouts -> Command ()
setTimeouts :: Session -> Timeouts -> Command ()
setTimeouts Session
sessionRef =
  Text -> UrlPath -> Timeouts -> Command ()
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Set Timeouts" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"timeouts")

-- |
--
-- Return a spec to navigate to a URL given a 'Session' and a 'Text' URL.
--
-- [spec](HTMLSpecURL#navigate-to)
--
-- @POST 	\/session\/{session id}\/url 	Navigate To@
navigateTo :: Session -> URL -> Command ()
navigateTo :: Session -> URL -> Command ()
navigateTo Session
sessionRef = Text -> UrlPath -> (URL -> Object) -> URL -> Command ()
forall {k} a (r :: k).
Text -> UrlPath -> (a -> Object) -> a -> Command r
mkPost' Text
"Navigate To" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"url") (\URL
url -> [(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
fromList [Key
"url" Key -> URL -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
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](HTMLSpecURL#get-current-url)
--
-- @GET 	\/session\/{session id}\/url 	Get Current URL@
getCurrentUrl :: Session -> Command URL
getCurrentUrl :: Session -> Command URL
getCurrentUrl Session
sessionRef = Text -> UrlPath -> Command URL
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#back)
--
-- @POST 	\/session\/{session id}\/back 	Back@
back :: Session -> Command ()
back :: Session -> Command ()
back Session
sessionRef = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#forward)
--
-- @POST 	\/session\/{session id}\/forward 	Forward@
forward :: Session -> Command ()
forward :: Session -> Command ()
forward Session
sessionRef = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
PostEmpty Text
"Forward" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"forward")

-- |
--
-- Return a spec to refresh the current page given a 'Session'.
--
-- [spec](HTMLSpecURL#refresh)
--
-- @POST 	\/session\/{session id}\/refresh 	Refresh@
refresh :: Session -> Command ()
refresh :: Session -> Command ()
refresh Session
sessionRef = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-title)
--
-- @GET 	\/session\/{session id}\/title 	Get Title@
getTitle :: Session -> Command Text
getTitle :: Session -> Command Text
getTitle Session
sessionRef = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-window-handle)
--
-- @GET 	\/session\/{session id}\/window 	Get Window Handle@
getWindowHandle :: Session -> Command Handle
getWindowHandle :: Session -> Command Handle
getWindowHandle Session
sessionRef = Text -> UrlPath -> Command Handle
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#new-window)
--
-- @POST 	\/session\/{session id}\/window\/new 	New Window@
newWindow :: Session -> Command WindowHandleSpec
newWindow :: Session -> Command WindowHandleSpec
newWindow Session
sessionRef = Text -> UrlPath -> Command WindowHandleSpec
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#close-window)
--
-- @DELETE 	\/session\/{session id}\/window 	Close Window@
closeWindow :: Session -> Command [Handle]
closeWindow :: Session -> Command [Handle]
closeWindow Session
sessionRef = Text -> UrlPath -> Command [Handle]
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#switch-to-window)
--
-- @POST 	\/session\/{session id}\/window 	Switch To Window@
switchToWindow :: Session -> Handle -> Command ()
switchToWindow :: Session -> Handle -> Command ()
switchToWindow Session
sessionRef = Text -> UrlPath -> Handle -> Command ()
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Switch To Window" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"window")

-- |
--
-- Return a spec to switch to a different frame given a 'Session' and 'FrameReference'.
--
-- [spec](HTMLSpecURL#switch-to-frame)
--
-- @POST 	\/session\/{session id}\/frame 	Switch To Frame@
switchToFrame :: Session -> FrameReference -> Command ()
switchToFrame :: Session -> FrameReference -> Command ()
switchToFrame Session
sessionRef = Text -> UrlPath -> FrameReference -> Command ()
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Switch To Frame" (Session -> Text -> UrlPath
sessionUri1 Session
sessionRef Text
"frame")

-- |
--
-- Return a spec to get the source of the current page given a 'Session'.
--
-- [spec](HTMLSpecURL#get-page-source)
--
-- @GET 	\/session\/{session id}\/source 	Get Page Source@
getPageSource :: Session -> Command Text
getPageSource :: Session -> Command Text
getPageSource Session
sessionId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#execute-script)
--
-- @POST 	\/session\/{session id}\/execute\/sync 	Execute Script@
executeScript :: Session -> Script -> Command Value
executeScript :: Session -> Script -> Command Value
executeScript Session
sessionId = Text -> UrlPath -> Script -> Command Value
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Execute Script" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"execute" Text
"sync")

-- |
--
-- 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](HTMLSpecURL#execute-async-script)
--
-- @POST 	\/session\/{session id}\/execute\/async 	Execute Async Script@
executeScriptAsync :: Session -> Script -> Command Value
executeScriptAsync :: Session -> Script -> Command Value
executeScriptAsync Session
sessionId = Text -> UrlPath -> Script -> Command Value
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Execute Async Script" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"execute" Text
"async")

-- |
--
-- Return a spec to get all cookies of the current page given a 'Session'.
--
-- [spec](HTMLSpecURL#get-all-cookies)
--
-- @GET 	\/session\/{session id}\/cookie 	Get All Cookies@
getAllCookies :: Session -> Command [Cookie]
getAllCookies :: Session -> Command [Cookie]
getAllCookies Session
sessionId = Text -> UrlPath -> Command [Cookie]
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-named-cookie)
--
-- @GET 	\/session\/{session id}\/cookie\/{name} 	Get Named Cookie@
getNamedCookie :: Session -> Text -> Command Cookie
getNamedCookie :: Session -> Text -> Command Cookie
getNamedCookie Session
sessionId Text
cookieName = Text -> UrlPath -> Command Cookie
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#add-cookie)
--
-- @POST 	\/session\/{session id}\/cookie 	Add Cookie@
addCookie :: Session -> Cookie -> Command ()
addCookie :: Session -> Cookie -> Command ()
addCookie Session
sessionId Cookie
cookie = Text -> UrlPath -> Object -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Object -> Command r
Post Text
"Add Cookie" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"cookie") ([(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
fromList [Key
"cookie" Key -> Cookie -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
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](HTMLSpecURL#delete-cookie)
--
-- @DELETE 	\/session\/{session id}\/cookie\/{name} 	Delete Cookie@
deleteCookie :: Session -> Text -> Command ()
deleteCookie :: Session -> Text -> Command ()
deleteCookie Session
sessionId Text
cookieName = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#delete-all-cookies)
--
-- @DELETE 	\/session\/{session id}\/cookie 	Delete All Cookies@
deleteAllCookies :: Session -> Command ()
deleteAllCookies :: Session -> Command ()
deleteAllCookies Session
sessionId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#perform-actions)
--
-- @POST 	\/session\/{session id}\/actions 	Perform Actions@
performActions :: Session -> Actions -> Command ()
performActions :: Session -> Actions -> Command ()
performActions Session
sessionId = Text -> UrlPath -> Actions -> Command ()
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Perform Actions" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"actions")

-- |
--
-- Return a spec to release actions on the current page given a 'Session'.
--
-- [spec](HTMLSpecURL#release-actions)
--
-- @DELETE 	\/session\/{session id}\/actions 	Release Actions@
releaseActions :: Session -> Command ()
releaseActions :: Session -> Command ()
releaseActions Session
sessionId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#dismiss-alert)
--
-- @POST 	\/session\/{session id}\/alert\/dismiss 	Dismiss Alert@
dismissAlert :: Session -> Command ()
dismissAlert :: Session -> Command ()
dismissAlert Session
sessionId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#accept-alert)
--
-- @POST 	\/session\/{session id}\/alert\/accept 	Accept Alert@
acceptAlert :: Session -> Command ()
acceptAlert :: Session -> Command ()
acceptAlert Session
sessionId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-alert-text)
--
-- @GET 	\/session\/{session id}\/alert\/text 	Get Alert Text@
getAlertText :: Session -> Command Text
getAlertText :: Session -> Command Text
getAlertText Session
sessionId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#send-alert-text)
--
-- @POST 	\/session\/{session id}\/alert\/text 	Send Alert Text@
sendAlertText :: Session -> Text -> Command ()
sendAlertText :: Session -> Text -> Command ()
sendAlertText Session
sessionId Text
text = Text -> UrlPath -> Object -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Object -> Command r
Post Text
"Send Alert Text" (Session -> Text -> Text -> UrlPath
sessionUri2 Session
sessionId Text
"alert" Text
"text") ([(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
fromList [Key
"text" Key -> Text -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
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](HTMLSpecURL#take-screenshot)
--
-- @GET 	\/session\/{session id}\/screenshot 	Take Screenshot@
takeScreenshot :: Session -> Command Text
takeScreenshot :: Session -> Command Text
takeScreenshot Session
sessionId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
Get Text
"Take Screenshot" (Session -> Text -> UrlPath
sessionUri1 Session
sessionId Text
"screenshot")

-- |
--
-- Return a spec to print the current page given a 'Session'.
--
-- [spec](HTMLSpecURL#print-page)
--
-- @POST 	\/session\/{session id}\/print 	Print Page@
printPage :: Session -> Command Text
printPage :: Session -> Command Text
printPage Session
sessionId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-window-handles)
--
-- @GET 	\/session\/{session id}\/window\/handles 	Get Window Handles@
getWindowHandles :: Session -> Command [Handle]
getWindowHandles :: Session -> Command [Handle]
getWindowHandles Session
sessionRef = Text -> UrlPath -> Command [Handle]
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-window-rect)
--
-- @GET 	\/session\/{session id}\/window\/rect 	Get Window Rect@
getWindowRect :: Session -> Command WindowRect
getWindowRect :: Session -> Command WindowRect
getWindowRect Session
sessionRef = Text -> UrlPath -> Command WindowRect
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#set-window-rect)
--
-- @POST 	\/session\/{session id}\/window\/rect 	Set Window Rect@
setWindowRect :: Session -> WindowRect -> Command WindowRect
setWindowRect :: Session -> WindowRect -> Command WindowRect
setWindowRect Session
sessionRef = Text -> UrlPath -> WindowRect -> Command WindowRect
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#maximize-window)
--
-- @POST 	\/session\/{session id}\/window\/maximize 	Maximize Window@
maximizeWindow :: Session -> Command WindowRect
maximizeWindow :: Session -> Command WindowRect
maximizeWindow Session
sessionRef = Text -> UrlPath -> Command WindowRect
forall {k} (r :: k). Text -> UrlPath -> Command r
PostEmpty Text
"Maximize Window" (Session -> Text -> UrlPath
windowUri1 Session
sessionRef Text
"maximize")

-- |
--
-- Return a spec to minimize the current window given a 'Session'.
--
-- [spec](HTMLSpecURL#minimize-window)
--
-- @POST 	\/session\/{session id}\/window\/minimize 	Minimize Window@
minimizeWindow :: Session -> Command WindowRect
minimizeWindow :: Session -> Command WindowRect
minimizeWindow Session
sessionRef = Text -> UrlPath -> Command WindowRect
forall {k} (r :: k). Text -> UrlPath -> Command r
PostEmpty Text
"Minimize Window" (Session -> Text -> UrlPath
windowUri1 Session
sessionRef Text
"minimize")

-- |
--
-- Return a spec to fullscreen the current window given a 'Session'.
--
-- [spec](HTMLSpecURL#fullscreen-window)
--
-- @POST 	\/session\/{session id}\/window\/fullscreen 	Fullscreen Window@
fullScreenWindow :: Session -> Command WindowRect
fullScreenWindow :: Session -> Command WindowRect
fullScreenWindow Session
sessionRef = Text -> UrlPath -> Command WindowRect
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#switch-to-parent-frame)
--
-- @POST 	\/session\/{session id}\/frame\/parent 	Switch To Parent Frame@
switchToParentFrame :: Session -> Command ()
switchToParentFrame :: Session -> Command ()
switchToParentFrame Session
sessionRef = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-active-element)
--
-- @GET 	\/session\/{session id}\/element\/active 	Get Active Element@
getActiveElement :: Session -> Command ElementId
getActiveElement :: Session -> Command ElementId
getActiveElement Session
sessionId = Text -> UrlPath -> Command ElementId
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#find-element)
--
-- @POST 	\/session\/{session id}\/element 	Find Element@
findElement :: Session -> Selector -> Command ElementId
findElement :: Session -> Selector -> Command ElementId
findElement Session
sessionRef = Text -> UrlPath -> Selector -> Command ElementId
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#find-elements)
--
-- @POST 	\/session\/{session id}\/elements 	Find Elements@
findElements :: Session -> Selector -> Command [ElementId]
findElements :: Session -> Selector -> Command [ElementId]
findElements Session
sessionRef = Text -> UrlPath -> Selector -> Command [ElementId]
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#get-element-shadow-root)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/shadow 	Get Element Shadow Root@
getElementShadowRoot :: Session -> ElementId -> Command ShadowRootElementId
getElementShadowRoot :: Session -> ElementId -> Command ShadowRootElementId
getElementShadowRoot Session
sessionId ElementId
elementId = Text -> UrlPath -> Command ShadowRootElementId
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#find-element-from-element)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/element 	Find Element From Element@
findElementFromElement :: Session -> ElementId -> Selector -> Command ElementId
findElementFromElement :: Session -> ElementId -> Selector -> Command ElementId
findElementFromElement Session
sessionId ElementId
elementId = Text -> UrlPath -> Selector -> Command ElementId
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#find-elements-from-element)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/elements 	Find Elements From Element@
findElementsFromElement :: Session -> ElementId -> Selector -> Command [ElementId]
findElementsFromElement :: Session -> ElementId -> Selector -> Command [ElementId]
findElementsFromElement Session
sessionId ElementId
elementId = Text -> UrlPath -> Selector -> Command [ElementId]
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#is-element-selected)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/selected 	Is Element Selected@
isElementSelected :: Session -> ElementId -> Command Bool
isElementSelected :: Session -> ElementId -> Command Bool
isElementSelected Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Bool
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-attribute)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/attribute\/{name} 	Get Element Attribute@
getElementAttribute :: Session -> ElementId -> Text -> Command Text
getElementAttribute :: Session -> ElementId -> Text -> Command Text
getElementAttribute Session
sessionId ElementId
elementId Text
attributeName = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-property)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/property\/{name} 	Get Element Property@
getElementProperty :: Session -> ElementId -> Text -> Command Value
getElementProperty :: Session -> ElementId -> Text -> Command Value
getElementProperty Session
sessionId ElementId
elementId Text
propertyName = Text -> UrlPath -> Command Value
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-css-value)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/css\/{property name} 	Get Element CSS Value@
getElementCssValue :: Session -> ElementId -> Text -> Command Text
getElementCssValue :: Session -> ElementId -> Text -> Command Text
getElementCssValue Session
sessionId ElementId
elementId Text
propertyName = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-text)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/text 	Get Element Text@
getElementText :: Session -> ElementId -> Command Text
getElementText :: Session -> ElementId -> Command Text
getElementText Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-tag-name)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/name 	Get Element Tag Name@
getElementTagName :: Session -> ElementId -> Command Text
getElementTagName :: Session -> ElementId -> Command Text
getElementTagName Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-element-rect)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/rect 	Get Element Rect@
getElementRect :: Session -> ElementId -> Command WindowRect
getElementRect :: Session -> ElementId -> Command WindowRect
getElementRect Session
sessionId ElementId
elementId = Text -> UrlPath -> Command WindowRect
forall {k} (r :: k). Text -> UrlPath -> Command r
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'.
--
-- [spec](HTMLSpecURL#is-element-enabled)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/enabled 	Is Element Enabled@
isElementEnabled :: Session -> ElementId -> Command Bool
isElementEnabled :: Session -> ElementId -> Command Bool
isElementEnabled Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Bool
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-computed-role)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/computedrole 	Get Computed Role@
getElementComputedRole :: Session -> ElementId -> Command Text
getElementComputedRole :: Session -> ElementId -> Command Text
getElementComputedRole Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#get-computed-label)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/computedlabel 	Get Computed Label@
getElementComputedLabel :: Session -> ElementId -> Command Text
getElementComputedLabel :: Session -> ElementId -> Command Text
getElementComputedLabel Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#element-click)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/click 	Element Click@
elementClick :: Session -> ElementId -> Command ()
elementClick :: Session -> ElementId -> Command ()
elementClick Session
sessionId ElementId
elementId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#element-clear)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/clear 	Element Clear@
elementClear :: Session -> ElementId -> Command ()
elementClear :: Session -> ElementId -> Command ()
elementClear Session
sessionId ElementId
elementId = Text -> UrlPath -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#element-send-keys)
--
-- @POST 	\/session\/{session id}\/element\/{element id}\/value 	Element Send Keys@
elementSendKeys :: Session -> ElementId -> Text -> Command ()
elementSendKeys :: Session -> ElementId -> Text -> Command ()
elementSendKeys Session
sessionId ElementId
elementId Text
keysToSend = Text -> UrlPath -> Object -> Command ()
forall {k} (r :: k). Text -> UrlPath -> Object -> Command r
Post Text
"Element Send Keys" (Session -> ElementId -> Text -> UrlPath
elementUri1 Session
sessionId ElementId
elementId Text
"value") ([(Key, Value)] -> Object
forall v. [(Key, v)] -> KeyMap v
fromList [Key
"text" Key -> Text -> (Key, Value)
forall v. ToJSON v => Key -> v -> (Key, Value)
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](HTMLSpecURL#take-element-screenshot)
--
-- @GET 	\/session\/{session id}\/element\/{element id}\/screenshot 	Take Element Screenshot@
takeElementScreenshot :: Session -> ElementId -> Command Text
takeElementScreenshot :: Session -> ElementId -> Command Text
takeElementScreenshot Session
sessionId ElementId
elementId = Text -> UrlPath -> Command Text
forall {k} (r :: k). Text -> UrlPath -> Command r
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](HTMLSpecURL#find-element-from-shadow-root)
--
-- @POST 	\/session\/{session id}\/shadow\/{shadow id}\/element 	Find Element From Shadow Root@
findElementFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> Command ElementId
findElementFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> Command ElementId
findElementFromShadowRoot Session
sessionId ShadowRootElementId
shadowId  = Text -> UrlPath -> Selector -> Command ElementId
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost 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](HTMLSpecURL#find-elements-from-shadow-root)
--
-- @POST 	\/session\/{session id}\/shadow\/{shadow id}\/elements 	Find Elements From Shadow Root@
findElementsFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> Command [ElementId]
findElementsFromShadowRoot :: Session -> ShadowRootElementId -> Selector -> Command [ElementId]
findElementsFromShadowRoot Session
sessionId ShadowRootElementId
shadowId = Text -> UrlPath -> Selector -> Command [ElementId]
forall {k} a (r :: k).
ToJSON a =>
Text -> UrlPath -> a -> Command r
mkPost Text
"Find Elements From Shadow Root" (Session -> Text -> Text -> Text -> UrlPath
sessionUri3 Session
sessionId Text
"shadow" ShadowRootElementId
shadowId.id Text
"elements") 

-- ############################ Helper Functions ##########################################

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

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

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]

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

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