module Test.WebDriver.Config(
WDConfig(..), defaultConfig, mkSession
) where
import Test.WebDriver.Session
import Test.WebDriver.Capabilities
import Data.Default (Default, def)
import Data.String (fromString)
import Network.HTTP.Client (Manager, newManager, defaultManagerSettings)
import Network.HTTP.Types (RequestHeaders)
import Control.Monad.Base (MonadBase, liftBase)
data WDConfig = WDConfig {
wdHost :: String
, wdPort :: Int
, wdRequestHeaders :: RequestHeaders
, wdCapabilities :: Capabilities
, wdKeepSessHist :: Bool
, wdBasePath :: String
, wdHTTPManager :: Maybe Manager
}
instance Default WDConfig where
def = WDConfig {
wdHost = "127.0.0.1"
, wdPort = 4444
, wdRequestHeaders = []
, wdCapabilities = def
, wdKeepSessHist = False
, wdBasePath = "/wd/hub"
, wdHTTPManager = Nothing
}
defaultConfig :: WDConfig
defaultConfig = def
mkSession :: MonadBase IO m => WDConfig -> m WDSession
mkSession WDConfig{..} = do
manager <- maybe createManager return wdHTTPManager
return WDSession { wdSessHost = fromString $ wdHost
, wdSessPort = wdPort
, wdSessBasePath = fromString $ wdBasePath
, wdSessId = Nothing
, wdSessHist = []
, wdSessHistUpdate = histUpdate
, wdSessHTTPManager = manager }
where
createManager = liftBase $ newManager defaultManagerSettings
histUpdate
| wdKeepSessHist = (:)
| otherwise = \x _ -> [x]