hspec-webdriver 0.2.2 → 0.2.3
raw patch · 3 files changed
+39/−11 lines, 3 filesdep +data-default
Dependencies added: data-default
Files
- Test/Hspec/WebDriver.hs +17/−6
- Test/Hspec/WebDriver/Internal.hs +20/−4
- hspec-webdriver.cabal +2/−1
Test/Hspec/WebDriver.hs view
@@ -40,6 +40,7 @@ , runWD , WDExample , Using(..)+ , inspectSession -- * Expectations , shouldBe@@ -71,6 +72,7 @@ import Control.Exception.Lifted (try, Exception, onException, throwIO, catch) import Control.Monad (when) import Control.Monad.IO.Class (liftIO)+import Data.Default (def) import Data.IORef import Data.Typeable (Typeable) import Data.Word (Word16)@@ -149,12 +151,10 @@ -> String -- ^ message -> ([cap], Spec) -> Spec-sessionOn host port bp = hSessionWd W.WDSession { W.wdHost = host- , W.wdPort = port- , W.wdBasePath = bp- , W.wdSessId = Nothing- , W.lastHTTPRequest = Nothing- }+sessionOn host port bp = hSessionWd def { W.wdHost = host+ , W.wdPort = port+ , W.wdBasePath = bp+ } -- | A typeclass of things which can be converted to a list of capabilities. It's primary purpose -- is to allow the word @using@ to be used with 'session' so that the session description reads like@@ -178,6 +178,17 @@ instance Using [BrowserDefaults] where type UsingList [BrowserDefaults] = [BrowserDefaults] using d s = (d, s)++-- | Abort the session without closing the session.+--+-- Normally, 'session' will automatically close the session either when the tests complete without+-- error or when any of the tests within the session throws an error. When developing the test+-- suite, this can be annoying since closing the session causes the browser window to close.+-- Therefore, while developing the test suite, you can insert a call to 'inspectSession'. This will+-- immedietly halt the session (all later tests will fail) but will not close the session so that+-- the browser window stays open.+inspectSession :: WD ()+inspectSession = throwIO I.AbortSessionEx -- | 'H.shouldBe' lifted into the 'WD' monad. shouldBe :: (Show a, Eq a) => a -> a -> WD ()
Test/Hspec/WebDriver/Internal.hs view
@@ -5,6 +5,7 @@ , runState , with , SessionExample(..)+ , AbortSessionEx(..) ) where import Control.Applicative@@ -12,6 +13,7 @@ import Control.Monad.Trans.State (state, evalState, execState, execStateT, StateT) import Data.Traversable (traverse) import Data.Typeable (Typeable, cast)+import Data.IORef import System.IO.Unsafe (unsafePerformIO) import Test.Hspec #if MIN_VERSION_hspec(1,10,0)@@ -46,6 +48,11 @@ where go item = state $ \cnt -> (item, cnt+1) +data AbortSessionEx = AbortSessionEx+ deriving Typeable+instance E.Exception AbortSessionEx+instance Show AbortSessionEx where+ show AbortSessionEx = "Session Aborted" data SessionTest a = SessionTest (IO () -> IO ()) (a -> IO a) deriving Typeable@@ -102,11 +109,20 @@ -- A session test, where in addition the open function succeeded. (Right a, Just (SessionTest act f)) -> do+ aborted <- newIORef False act $ do- a' <- f a - `E.onException` close ma -- use old state on error- close $ Right a' -- use new state- return Success+ mstate <- E.try $ f a+ case mstate of+ -- pass new state to next test+ Right st -> close (Right st)+ Left serr@(E.SomeException actErr) -> do+ case cast actErr of+ -- pass abort to next test+ Just AbortSessionEx -> close (Left serr) >> writeIORef aborted True+ -- pass original state and rethrow the error+ Nothing -> close ma >> E.throwIO serr+ abrt <- readIORef aborted+ return $ if abrt then (Fail "Session Aborted") else Success -- A session test where the state ma is an error (which is the error -- thrown by open). Pass the error ma to the next test and throw the
hspec-webdriver.cabal view
@@ -1,5 +1,5 @@ name: hspec-webdriver-version: 0.2.2+version: 0.2.3 cabal-version: >= 1.8 build-type: Simple synopsis: Write end2end web application tests using webdriver and hspec@@ -32,6 +32,7 @@ , HUnit >= 1.2 && < 1.3 , hashable >= 1.2 , hspec >= 1.8+ , data-default >= 0.5 , lifted-base >= 0.2 , stm >= 2.4 , text >= 0.11