module Test.WebDriver.Config(
WDConfig(..), defaultConfig
, modifyCaps, useBrowser, useVersion, usePlatform, useProxy
, SessionHistoryConfig, noHistory, unlimitedHistory, onlyMostRecentHistory
, WebDriverConfig(..)
) where
import Test.WebDriver.Capabilities
import Test.WebDriver.Session
import Data.Default.Class (Default(..))
import Data.String (fromString)
import Control.Monad.Base
import Network.HTTP.Client (Manager, newManager, defaultManagerSettings)
import Network.HTTP.Types (RequestHeaders)
data WDConfig = WDConfig {
WDConfig -> String
wdHost :: String
, WDConfig -> Int
wdPort :: Int
, WDConfig -> Capabilities
wdCapabilities :: Capabilities
, WDConfig -> String
wdBasePath :: String
, :: RequestHeaders
, :: RequestHeaders
, WDConfig -> SessionHistoryConfig
wdHistoryConfig :: SessionHistoryConfig
, WDConfig -> Maybe Manager
wdHTTPManager :: Maybe Manager
, WDConfig -> Int
wdHTTPRetryCount :: Int
}
instance GetCapabilities WDConfig where
getCaps :: WDConfig -> Capabilities
getCaps = WDConfig -> Capabilities
wdCapabilities
instance SetCapabilities WDConfig where
setCaps :: Capabilities -> WDConfig -> WDConfig
setCaps Capabilities
caps WDConfig
conf = WDConfig
conf { wdCapabilities :: Capabilities
wdCapabilities = Capabilities
caps }
instance Default WDConfig where
def :: WDConfig
def = WDConfig {
wdHost :: String
wdHost = String
"127.0.0.1"
, wdPort :: Int
wdPort = Int
4444
, wdRequestHeaders :: RequestHeaders
wdRequestHeaders = []
, wdAuthHeaders :: RequestHeaders
wdAuthHeaders = []
, wdCapabilities :: Capabilities
wdCapabilities = forall a. Default a => a
def
, wdHistoryConfig :: SessionHistoryConfig
wdHistoryConfig = SessionHistoryConfig
unlimitedHistory
, wdBasePath :: String
wdBasePath = String
"/wd/hub"
, wdHTTPManager :: Maybe Manager
wdHTTPManager = forall a. Maybe a
Nothing
, wdHTTPRetryCount :: Int
wdHTTPRetryCount = Int
0
}
defaultConfig :: WDConfig
defaultConfig :: WDConfig
defaultConfig = forall a. Default a => a
def
class WebDriverConfig c where
mkCaps :: MonadBase IO m => c -> m Capabilities
mkSession :: MonadBase IO m => c -> m WDSession
instance WebDriverConfig WDConfig where
mkCaps :: forall (m :: * -> *). MonadBase IO m => WDConfig -> m Capabilities
mkCaps = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. GetCapabilities t => t -> Capabilities
getCaps
mkSession :: forall (m :: * -> *). MonadBase IO m => WDConfig -> m WDSession
mkSession WDConfig{Int
String
RequestHeaders
Maybe Manager
Capabilities
SessionHistoryConfig
wdHTTPRetryCount :: Int
wdHTTPManager :: Maybe Manager
wdHistoryConfig :: SessionHistoryConfig
wdAuthHeaders :: RequestHeaders
wdRequestHeaders :: RequestHeaders
wdBasePath :: String
wdCapabilities :: Capabilities
wdPort :: Int
wdHost :: String
wdHTTPRetryCount :: WDConfig -> Int
wdHTTPManager :: WDConfig -> Maybe Manager
wdHistoryConfig :: WDConfig -> SessionHistoryConfig
wdAuthHeaders :: WDConfig -> RequestHeaders
wdRequestHeaders :: WDConfig -> RequestHeaders
wdBasePath :: WDConfig -> String
wdCapabilities :: WDConfig -> Capabilities
wdPort :: WDConfig -> Int
wdHost :: WDConfig -> String
..} = do
Manager
manager <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe m Manager
createManager forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Manager
wdHTTPManager
forall (m :: * -> *) a. Monad m => a -> m a
return WDSession { wdSessHost :: ByteString
wdSessHost = forall a. IsString a => String -> a
fromString forall a b. (a -> b) -> a -> b
$ String
wdHost
, wdSessPort :: Int
wdSessPort = Int
wdPort
, wdSessRequestHeaders :: RequestHeaders
wdSessRequestHeaders = RequestHeaders
wdRequestHeaders
, wdSessAuthHeaders :: RequestHeaders
wdSessAuthHeaders = RequestHeaders
wdAuthHeaders
, wdSessBasePath :: ByteString
wdSessBasePath = forall a. IsString a => String -> a
fromString forall a b. (a -> b) -> a -> b
$ String
wdBasePath
, wdSessId :: Maybe SessionId
wdSessId = forall a. Maybe a
Nothing
, wdSessHist :: [SessionHistory]
wdSessHist = []
, wdSessHistUpdate :: SessionHistoryConfig
wdSessHistUpdate = SessionHistoryConfig
wdHistoryConfig
, wdSessHTTPManager :: Manager
wdSessHTTPManager = Manager
manager
, wdSessHTTPRetryCount :: Int
wdSessHTTPRetryCount = Int
wdHTTPRetryCount }
where
createManager :: m Manager
createManager = forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase forall a b. (a -> b) -> a -> b
$ ManagerSettings -> IO Manager
newManager ManagerSettings
defaultManagerSettings