webdriver 0.3 → 0.3.0.1
raw patch · 9 files changed
+56/−32 lines, 9 files
Files
- CHANGELOG.md +9/−2
- TODO +2/−0
- src/Test/WebDriver/Capabilities.hs +5/−5
- src/Test/WebDriver/Classes.hs +9/−8
- src/Test/WebDriver/Common/Profile.hs +10/−2
- src/Test/WebDriver/Firefox/Profile.hs +15/−8
- src/Test/WebDriver/Internal.hs +5/−4
- src/Test/WebDriver/Monad.hs +0/−2
- webdriver.cabal +1/−1
CHANGELOG.md view
@@ -1,5 +1,12 @@-#Change Log+#0.3.0.1 +## upcoming release++###bug fixes+*due to a nonconformance in the spec from the Grid server, wire responses were being received that contained no sessionId key, which subsequently resulted in a parse error from our JSON parser. This has been fixed, so that an omitted sessionId defaults to Nothing.+*major bux fixes in the Firefox profile code. Note that loadProfile is unlikely+to work as expected, but prepareTempProfile should.+ ## hs-webdriver 0.3 ### API changes@@ -9,7 +16,7 @@ * FFLogPref is now removed and replaced by the LogPref type, because both Firefox and Opera config use the same logging preference values. * Several new modules have been created, including: Capabilities, Monad, Classes, Exceptions. Many of the definitions have been moved around, but the export lists of the pre-existing modules are the same. -### Bug fixes+### bug fixes * Various issues with the serialization of capabilities meant that Chrome, IE, and Opera weren't able to startup correctly with default capabilities. This is now fixed. ### new features
TODO view
@@ -30,3 +30,5 @@ -- remove temporary directory code from prepareProfile --Use lazy ByteString where possible. patch base64-bytestring to work with lazy bytestrings++-- add support for new experimental IE capabilities
src/Test/WebDriver/Capabilities.hs view
@@ -98,8 +98,8 @@ -- |Default capabilities. This is the same as the 'Default' instance, but with -- less polymorphism. By default, we use 'firefox' of an unspecified 'version' --- with default system-wide proxy settings on whatever 'platform' is available.--- All Maybe Bool capabilities are set to Nothing (no preference).+-- with default system-wide 'proxy' settings on whatever 'platform' is available+-- . All Maybe Bool capabilities are set to Nothing (no preference). defaultCaps :: Capabilities defaultCaps = def @@ -249,11 +249,11 @@ | Opera { -- |Server-side path to the Opera binary operaBinary :: Maybe FilePath --, operaNoRestart :: Maybe Bool - -- |Which Opera product 'were using, e.g. "desktop",- -- "core"+ -- |Which Opera product we're using, e.g. \"desktop\",+ -- \"core\" , operaProduct :: Maybe String -- |Whether the Opera instance should stay open after- -- we close the session. If False, closing the session+ -- we close the session. If false, closing the session -- closes the browser. , operaDetach :: Bool -- |Whether to auto-start the Opera binary. If false,
src/Test/WebDriver/Classes.hs view
@@ -1,9 +1,13 @@ {-# LANGUAGE OverloadedStrings, DeriveDataTypeable, FlexibleContexts, - GeneralizedNewtypeDeriving, StandaloneDeriving #-}+ GeneralizedNewtypeDeriving #-} module Test.WebDriver.Classes- ( WebDriver(..), RequestMethod(..),+ ( -- * WebDriver class+ WebDriver(..), RequestMethod(..),+ -- * SessionState class SessionState(..), modifySession+ -- ** WebDriver sessions , WDSession(..), SessionId(..), defaultSession+ -- **Convenience function for :sessionId URLs , doSessCommand -- * No Session Exception , NoSessionId(..)@@ -55,8 +59,7 @@ -> a -- ^JSON parameters passed in the body -- of the request. Note that, as a special case, -- () will result in an empty request body.- -> wd b -+ -> wd b -- ^The JSON result of the HTTP request. modifySession :: SessionState s => (WDSession -> WDSession) -> s () modifySession f = getSession >>= putSession . f@@ -108,7 +111,7 @@ deriving (Eq, Show, Typeable) --- |This a convenient wrapper around doCommand that automatically prepends+-- |This a convenient wrapper around 'doCommand' that automatically prepends -- the session URL parameter to the wire command URL. For example, passing -- a URL of "/refresh" will expand to "/session/:sessionId/refresh". doSessCommand :: (WebDriver wd, ToJSON a, FromJSON b) => @@ -118,7 +121,7 @@ case mSessId of Nothing -> throwIO . NoSessionId $ msg where - msg = "No session ID found when making request for relative URL "+ msg = "doSessCommand: No session ID found for relative URL " ++ show path Just (SessionId sId) -> doCommand method (T.concat ["/session/", sId, path]) args@@ -178,14 +181,12 @@ instance (Error e, WebDriver wd) => WebDriver (ErrorT e wd) where doCommand rm t a = lift (doCommand rm t a) - --instance SessionState m => SessionState (ContT r m) where -- getSession = lift getSession -- putSession = lift . putSession --instance WebDriver wd => WebDriver (ContT r wd) where -- doCommand rm t a = lift (doCommand rm t a)- instance (Monoid w, SessionState m) => SessionState (SRWS.RWST r w s m) where getSession = lift getSession
src/Test/WebDriver/Common/Profile.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE CPP, TypeSynonymInstances, DeriveDataTypeable, FlexibleInstances, - GeneralizedNewtypeDeriving #-}+ GeneralizedNewtypeDeriving, OverloadedStrings #-} {-# OPTIONS_HADDOCK not-home #-} -- |A type for profile preferences. These preference values are used by both -- Firefox and Opera profiles.@@ -23,6 +23,7 @@ import Data.Typeable import Control.Exception+import Control.Applicative -- |This structure allows you to construct and manipulate profiles in pure code, -- deferring execution of IO operations until the profile is \"prepared\". This @@ -43,7 +44,14 @@ -- |Represents a profile that has been prepared for -- network transmission. The profile cannot be modified in this form. newtype PreparedProfile b = PreparedProfile ByteString- deriving (Eq, Show, ToJSON, FromJSON)+ deriving (Eq, Show)++instance FromJSON (PreparedProfile s) where+ parseJSON (Object o) = PreparedProfile <$> o .: "zip"+ parseJSON other = typeMismatch "PreparedProfile" other+ +instance ToJSON (PreparedProfile s) where+ toJSON s = object ["zip" .= s] -- |A profile preference value. This is the subset of JSON values that excludes -- arrays, objects, and null.
src/Test/WebDriver/Firefox/Profile.hs view
@@ -15,7 +15,6 @@ , prepareTempProfile, prepareLoadedProfile ) where import Test.WebDriver.Common.Profile- import Data.Aeson import Data.Aeson.Parser (jstring, value') import Data.Attoparsec.Char8 as AP@@ -39,7 +38,7 @@ import Control.Monad.Base import Control.Monad.Trans.Control import Control.Applicative-import Control.Exception.Lifted+import Control.Exception.Lifted hiding (try) -- |Phantom type used in the parameters of 'Profile' and 'PreparedProfile'@@ -57,8 +56,12 @@ where extD = path </> "extensions" userPref = path </> "prefs" <.> "js"- getExtensions = HS.fromList . filter (`elem` [".",".."]) - <$> getDirectoryContents extD+ getExtensions = do+ b <- doesDirectoryExist extD+ if b+ then HS.fromList . map (extD </>) . filter (`notElem` [".",".."])+ <$> getDirectoryContents extD+ else return HS.empty getPrefs = HM.fromList <$> (parsePrefs =<< BS.readFile userPref) parsePrefs s = either (throwIO . ProfileParseError)@@ -85,7 +88,7 @@ return prof where extensionD = d </> "extensions"- userPrefs = d </> "prefs" <.> "js"+ userPrefs = d </> "user" <.> "js" installExtension ePath = case splitExtension ePath of@@ -189,13 +192,12 @@ -- firefox prefs.js parser prefsParser :: Parser [(Text, ProfilePref)]-prefsParser = many $ do +prefsParser = many1 $ do padSpaces $ string "user_pref(" k <- prefKey <?> "preference key" padSpaces $ char ',' v <- prefVal <?> "preference value" padSpaces $ string ");"- endOfLine return (k,v) where prefKey = jstring@@ -204,5 +206,10 @@ case fromJSON v of Error str -> fail str Success p -> return p- spaces = AP.takeWhile isSpace+ padSpaces p = spaces >> p <* spaces+ spaces = many (endOfLine <|> void space <|> void comment) + where+ comment = inlineComment <|> lineComment+ lineComment = char '#' *> manyTill anyChar endOfLine+ inlineComment = string "/*" *> manyTill anyChar (string "*/")
src/Test/WebDriver/Internal.hs view
@@ -69,8 +69,9 @@ . show . BS.length $ body ] }--- liftIO . print $ req- liftBase (simpleHTTP req) >>= either (throwIO . HTTPConnError) return+ r <- liftBase (simpleHTTP req) >>= either (throwIO . HTTPConnError) return+ liftBase . print . rspBody $ r+ return r handleHTTPErr :: SessionState s => Response ByteString -> s () handleHTTPErr r@Response{rspBody = body, rspCode = code, rspReason = reason} = @@ -151,9 +152,9 @@ deriving (Eq, Show) instance FromJSON WDResponse where- parseJSON (Object o) = WDResponse <$> o .: "sessionId"+ parseJSON (Object o) = WDResponse <$> o .:? "sessionId" .!= Nothing <*> o .: "status"- <*> o .: "value" .!= Null+ <*> o .:? "value" .!= Null parseJSON v = typeMismatch "WDResponse" v
src/Test/WebDriver/Monad.hs view
@@ -43,9 +43,7 @@ instance WebDriver WD where doCommand method path args = do r <- mkRequest [] method path args- --liftIO . print $ r handleHTTPErr r- --liftIO . print . rspBody $ r handleHTTPResp r -- |Executes a 'WD' computation within the 'IO' monad, using the given
webdriver.cabal view
@@ -1,5 +1,5 @@ Name: webdriver-Version: 0.3+Version: 0.3.0.1 Cabal-Version: >= 1.6 License: BSD3 License-File: LICENSE