webdriver 0.6.2.1 → 0.6.3
raw patch · 8 files changed
+48/−16 lines, 8 filesdep ~aesondep ~base
Dependency ranges changed: aeson, base
Files
- CHANGELOG.md +4/−0
- src/Test/WebDriver/Capabilities.hs +1/−1
- src/Test/WebDriver/Commands.hs +1/−1
- src/Test/WebDriver/Config.hs +5/−1
- src/Test/WebDriver/Internal.hs +17/−8
- src/Test/WebDriver/JSON.hs +14/−2
- src/Test/WebDriver/Session.hs +3/−0
- webdriver.cabal +3/−3
CHANGELOG.md view
@@ -1,4 +1,8 @@ #Change Log+##0.6.3+* Support aeson 0.10+* Added support for multiple HTTP attempts per command request, using the new WDConfig field wdHTTPRetryCount+ ##0.6.2.1 * Supports vector 0.11, aeson 0.9, attoparsec 0.13
src/Test/WebDriver/Capabilities.hs view
@@ -233,7 +233,7 @@ req :: FromJSON a => Text -> Parser a req = (o .:) -- required field opt :: FromJSON a => Text -> a -> Parser a- opt k d = o .:? k .!= d -- optional field+ opt k d = o .:?? k .!= d -- optional field b :: Text -> Parser (Maybe Bool) b k = opt k Nothing -- Maybe Bool field
src/Test/WebDriver/Commands.hs view
@@ -347,7 +347,7 @@ req :: FromJSON a => Text -> Parser a req = (o .:) opt :: FromJSON a => Text -> a -> Parser a- opt k d = o .:? k .!= d+ opt k d = o .:?? k .!= d parseJSON v = typeMismatch "Cookie" v -- |Retrieve all cookies visible to the current page.
src/Test/WebDriver/Config.hs view
@@ -34,6 +34,8 @@ , wdBasePath :: String -- |Use the given http-client 'Manager' instead of the default , wdHTTPManager :: Maybe Manager+ -- |Number of times to retry a HTTP request if it times out (default 0)+ , wdHTTPRetryCount :: Int } @@ -46,6 +48,7 @@ , wdKeepSessHist = False , wdBasePath = "/wd/hub" , wdHTTPManager = Nothing+ , wdHTTPRetryCount = 0 } {- |A default session config connects to localhost on port 4444, and hasn't been@@ -64,7 +67,8 @@ , wdSessId = Nothing , wdSessHist = [] , wdSessHistUpdate = histUpdate- , wdSessHTTPManager = manager }+ , wdSessHTTPManager = manager+ , wdSessHTTPRetryCount = wdHTTPRetryCount } where createManager = liftBase $ newManager defaultManagerSettings histUpdate
src/Test/WebDriver/Internal.hs view
@@ -19,7 +19,7 @@ import Test.WebDriver.JSON import Test.WebDriver.Session -import Network.HTTP.Client (httpLbs, Request(..), RequestBody(..), Response(..))+import Network.HTTP.Client (httpLbs, Request(..), RequestBody(..), Response(..), HttpException(ResponseTimeout)) import Network.HTTP.Types.Header import Network.HTTP.Types.Status (Status(..)) import Data.Aeson@@ -32,12 +32,12 @@ import Data.ByteString.Lazy.Char8 as LBS (length, unpack, null, fromStrict) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Base64.Lazy as B64-+import System.IO (hPutStrLn, stderr) import Control.Monad.Base import Control.Exception.Lifted (throwIO) import Control.Applicative-import Control.Exception (SomeException, toException)+import Control.Exception (SomeException, toException, catch) import Control.Exception (Exception) import Data.Typeable (Typeable)@@ -68,10 +68,19 @@ sendHTTPRequest :: (WDSessionState s) => Request -> s (Response ByteString) sendHTTPRequest req = do s@WDSession{..} <- getSession- res <- liftBase $ httpLbs req wdSessHTTPManager+ res <- liftBase $ retryOnTimeout wdSessHTTPRetryCount $ httpLbs req wdSessHTTPManager putSession s {wdSessHist = wdSessHistUpdate (req, res) wdSessHist} return res- ++retryOnTimeout :: Int -> IO a -> IO a+retryOnTimeout retryCount go = go `catch` handleTimeout+ where+ handleTimeout ResponseTimeout+ | retryCount > 0 = do+ hPutStrLn stderr "HTTP request timed out - retrying"+ retryOnTimeout (retryCount - 1) go++ handleTimeout e = throwIO e -- |Parses a 'WDResponse' object from a given HTTP response. getJSONResult :: (WDSessionState s, FromJSON a) => Response ByteString -> s (Either SomeException a)@@ -185,9 +194,9 @@ deriving (Eq, Show) instance FromJSON WDResponse where- parseJSON (Object o) = WDResponse <$> o .:? "sessionId" .!= Nothing+ parseJSON (Object o) = WDResponse <$> o .:?? "sessionId" .!= Nothing <*> o .: "status"- <*> o .:? "value" .!= Null+ <*> o .:?? "value" .!= Null parseJSON v = typeMismatch "WDResponse" v @@ -332,7 +341,7 @@ where req :: FromJSON a => Text -> Parser a req = (o .:) --required key opt :: FromJSON a => Text -> a -> Parser a- opt k d = o .:? k .!= d --optional key+ opt k d = o .:?? k .!= d --optional key parseJSON v = typeMismatch "FailedCommandInfo" v instance FromJSON StackFrame where
src/Test/WebDriver/JSON.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings, FlexibleContexts, DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings, FlexibleContexts, DeriveDataTypeable, CPP #-} -- |A collection of convenience functions for using and parsing JSON values -- within 'WD'. All monadic parse errors are converted to asynchronous -- 'BadJSON' exceptions.@@ -7,7 +7,7 @@ -- be useful for implementing non-standard commands. module Test.WebDriver.JSON ( -- * Access a JSON object key- (!:)+ (!:), (.:??) -- * Conversion from JSON within WD -- |Apostrophes are used to disambiguate these functions -- from their "Data.Aeson" counterparts.@@ -90,6 +90,18 @@ -- |This operator is a wrapper over Aeson's '.:' operator. (!:) :: (MonadBaseControl IO wd, FromJSON a) => Object -> Text -> wd a o !: k = aesonResultToWD $ parse (.: k) o+++-- |Emulates the behavior of '.:?' in Aeson versions \< 0.10, allowing the field to be either missing or 'Null' if the result type is a 'Maybe'.+-- In newer Aeson versions (\>= 0.10), this is equivalent to:+--+-- > fmap join (o .:? k)+(.:??) :: FromJSON a => Object -> Text -> Parser (Maybe a)+#if MIN_VERSION_aeson(0,10,0)+o .:?? k = fmap join (o .:? k)+#else+(.:??) = (.:?)+#endif -- |Parse a JSON 'Object' as a pair. The first two string arguments specify the
src/Test/WebDriver/Session.hs view
@@ -60,6 +60,9 @@ -> [(Request, Response LBS.ByteString)] -- |HTTP 'Manager' used for connection pooling by the http-client library. , wdSessHTTPManager :: Manager++ -- |Number of times to retry a HTTP request if it times out+ , wdSessHTTPRetryCount :: Int } -- |The last HTTP request issued by this session, if any.
webdriver.cabal view
@@ -1,10 +1,10 @@ Name: webdriver-Version: 0.6.2.1+Version: 0.6.3 Cabal-Version: >= 1.8 License: BSD3 License-File: LICENSE Author: Adam Curtis-Maintainer: acurtis@spsu.edu+Maintainer: kallisti.dev@gmail.com Homepage: https://github.com/kallisti-dev/hs-webdriver Category: Web, Browser, Testing Synopsis: a Haskell client for the Selenium WebDriver protocol@@ -34,7 +34,7 @@ hs-source-dirs: src ghc-options: -Wall build-depends: base == 4.*- , aeson >= 0.6.2.0 && < 0.10+ , aeson >= 0.6.2.0 && < 0.11 , http-client >= 0.3 && < 0.5 , http-types >= 0.8 && < 0.9 , text >= 0.11.3 && < 1.3