webdriver-angular 0.1.2 → 0.1.3
raw patch · 6 files changed
+128/−191 lines, 6 filesdep ~hspec-webdriverdep ~webdriver
Dependency ranges changed: hspec-webdriver, webdriver
Files
- src/Test/WebDriver/Commands/Angular.hs +2/−9
- test/ManagerSpecs.hs +0/−55
- test/NgSpec.hs +119/−0
- test/NgSpecs.hs +0/−118
- test/main.hs +3/−6
- webdriver-angular.cabal +4/−3
src/Test/WebDriver/Commands/Angular.hs view
@@ -29,7 +29,6 @@ import Control.Monad.IO.Class (liftIO, MonadIO) import Control.Exception (throwIO, Exception) import Data.Maybe (catMaybes)-import Data.Monoid ((<>)) import Data.Typeable (Typeable) import Test.WebDriver.Classes import Test.WebDriver.Commands@@ -62,12 +61,10 @@ _ -> catMaybes <$> fromJSON' x -- parse as [Maybe Element] and drop the nothings because -- looking up ByRow returns Nulls in the list. -{- asyncCS :: (WebDriver wd, A.FromJSON a) => T.Text -> [JSArg] -> wd (Maybe a) asyncCS script arg = asyncJS arg body where body = maybe (error $ "Unable to find " ++ T.unpack script) id $ M.lookup script cs--} -- | Wait until Angular has finished rendering before continuing. @False@ indicates the timeout -- was hit (see 'setScriptTimeout') and we stopped waiting and @True@ means that angular has@@ -76,14 +73,10 @@ => T.Text -- ^ CSS selector to element which has ng-app -> wd Bool waitForAngular sel = do- --a <- asyncCS "waitForAngular" [JSArg sel] :: WebDriver wd => wd (Maybe - - let body = maybe (error $ "Unable to find waitForAngular") id $ M.lookup "waitForAngular" cs- body' = "var oldDone = arguments[1]; arguments[1] = function(e) { oldDone(e || true); };" <> body- a <- asyncJS [JSArg sel] body'+ a <- asyncCS "waitForAngular" [JSArg sel] case a of Nothing -> return False- Just (A.Bool True) -> return True+ Just A.Null -> return True Just _ -> liftIO $ throwIO $ NgException $ "Error waiting for angular: " ++ show a -- | Exceptions of this type will be thrown when an element is unable to be located.
− test/ManagerSpecs.hs
@@ -1,55 +0,0 @@-{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}-module ManagerSpecs where--import Control.Concurrent (threadDelay)-import Test.Hspec.WebDriver-import Test.WebDriver.Commands.Angular--mSpecs :: Spec-mSpecs = describe "session manager tests" $ do- parallel $ it "runs in parallel" $ using [Firefox, Chrome] $ do- openPage "http://localhost:3456/index.html"- waitForAngular "body" `shouldReturn` True-- i <- findNg $ ByModel "xxx"- i `shouldBeTag` "input"- sendKeys "John" i-- liftIO $ threadDelay $ 25 * 10^(6::Int)-- sendKeys " Mark" i- xHead <- findNg $ ByBinding "{{xxx}}"- xHead `shouldBeTag` "h1"- xHead `shouldHaveText` "X John Mark"-- parallel $ do- describe "Firefox 1" $- it "waits for a while" $ using Firefox $ do- openPage "http://localhost:3456/index.html"- waitForAngular "body" `shouldReturn` True- - i <- findNg $ ByModel "xxx"- sendKeys "Firefox 1" i- - liftIO $ threadDelay $ 2 * 10^(6::Int)-- describe "Firefox 2" $- it "waits for a while" $ using Firefox $ do- openPage "http://localhost:3456/index.html"- waitForAngular "body" `shouldReturn` True- - i <- findNg $ ByModel "xxx"- sendKeys "Firefox 2" i- - liftIO $ threadDelay $ 2 * 10^(6::Int)-- describe "Firefox 3" $- it "waits for a while" $ using Firefox $ do- openPage "http://localhost:3456/index.html"- waitForAngular "body" `shouldReturn` True- - i <- findNg $ ByModel "xxx"- sendKeys "Firefox 3" i- - liftIO $ threadDelay $ 2 * 10^(6::Int)-
+ test/NgSpec.hs view
@@ -0,0 +1,119 @@+{-# LANGUAGE OverloadedStrings #-}+module NgSpec where++import Test.Hspec.WebDriver+import Test.WebDriver.Commands.Angular++ngSpec :: Spec+ngSpec = session "Angular webdriver commands" $ using Firefox $ do+ it "opens the page" $ runWD $ do+ openPage "http://localhost:3456/index.html"+ waitForAngular "body" `shouldReturn` True++ it "finds elements by binding" $ runWD $ do+ binding <- findNg $ ByBinding "{{a}}"+ binding `shouldBeTag` "h1"+ binding `shouldHaveText` "Hello A!"++ it "does not find missing model elements" $ runWD $ do+ findNgs (ByModel "qqq") `shouldReturn` []+ findNg (ByModel "qqq") `shouldThrow` NgException "Selector ByModel \"qqq\" returned []"++ it "finds input elements" $ runWD $ do+ i <- findNg $ ByModel "xxx"+ i `shouldBeTag` "input"+ sendKeys "John" i++ xHead <- findNg $ ByBinding "{{xxx}}"+ xHead `shouldBeTag` "h1"+ xHead `shouldHaveText` "X John"++ it "finds textarea elements" $ runWD $ do+ t <- findNg $ ByModel "yyy"+ t `shouldBeTag` "textarea"+ sendKeys "Mark" t++ yHead <- findNg $ ByBinding "{{yyy}}"+ yHead `shouldBeTag` "h2"+ yHead `shouldHaveText` "Y Mark"++ it "finds select elements" $ runWD $ do+ s <- findNg $ ByModel "zzz"+ s `shouldBeTag` "select"+ opt <- findElemFrom s $ ByCSS "option[value=\"Bar\"]"+ click opt++ zHead <- findNg $ ByBinding "{{zzz}}"+ zHead `shouldBeTag` "h3"+ zHead `shouldHaveText` "Z Bar"++ it "finds selected option inside select opt" $ runWD $ do+ opt <- findNg $ BySelectedOption "zzz"+ opt `shouldBeTag` "option"+ opt `shouldHaveText` "Bar"++ it "finds model elements of different types" $ runWD $ do+ [i, t, s] <- findNgs $ ByModel "name"+ i `shouldBeTag` "input"+ t `shouldBeTag` "textarea"+ s `shouldBeTag` "select"++ it "finds all repeater rows" $ runWD $ do+ [r1, r2, r3] <- findRepeaters $ ByRows "dog in dogs"+ mapM_ (`shouldBeTag`"li") [r1, r2, r3]+ r1 `shouldHaveText` "Spot mutt"+ r2 `shouldHaveText` "Spike poodle"+ r3 `shouldHaveText` "Jupiter bulldog"++ findRepeaters (ByRows "cat in cats") `shouldReturn` []+ findRepeater (ByRows "cat in cats") `shouldThrow` NgException "Selector ByRows \"cat in cats\" returned []"++ it "finds a single repeater row" $ runWD $ do+ r2 <- findRepeater $ ByRow "dog in dogs" 1+ r2 `shouldBeTag` "li"+ r2 `shouldHaveText` "Spike poodle"++ findRepeaters (ByRow "cat in cats" 1) `shouldReturn` []+ findRepeater (ByRow "cat in cats" 1) `shouldThrow` NgException "Selector ByRow \"cat in cats\" 1 returned []"++ it "finds a repeater column" $ runWD $ do+ [c1, c2, c3] <- findRepeaters $ ByColumn "dog in dogs" "{{dog.name}}"+ mapM_ (`shouldBeTag`"span") [c1, c2, c3]++ c1 `shouldHaveText` "Spot"+ c2 `shouldHaveText` "Spike"+ c3 `shouldHaveText` "Jupiter"++ findRepeaters (ByColumn "cat in cats" "{{cat.name}}") `shouldReturn` []+ findRepeater (ByColumn "cat in cats" "{{cat.name}}") `shouldThrow`+ NgException "Selector ByColumn \"cat in cats\" \"{{cat.name}}\" returned []"++ it "finds a repeater by row and column" $ runWD $ do+ c2 <- findRepeater $ ByRowAndCol "dog in dogs" 1 "{{dog.breed}}"+ c2 `shouldBeTag` "span"+ c2 `shouldHaveText` "poodle"++ findRepeaters (ByRowAndCol "cat in cats" 12 "{{cat.name}}") `shouldReturn` []+ findRepeater (ByRowAndCol "cat in cats" 22 "{{cat.name}}") `shouldThrow`+ NgException "Selector ByRowAndCol \"cat in cats\" 22 \"{{cat.name}}\" returned []"++ it "evaluates an angular expression" $ runWD $ do+ e <- findNg $ ByBinding "{{a}}"+ ngEvaluate e "cost | number:2" `shouldReturn` ("12.60" :: String)++ it "loads the location url" $ runWD $ do+ getLocationAbsUrl "body" `shouldReturn` "http://localhost:3456/index.html"++ it "loads {{cost}} from document" $ runWD $ do+ [s1, s2] <- findNgs $ ByBinding "{{cost}}"+ s1 `shouldBeTag` "span"+ s2 `shouldBeTag` "span"+ s1 `shouldHaveAttr` ("id", "span-one")+ s2 `shouldHaveAttr` ("id", "span-two")++ it "loads {{cost}} only from one element" $ runWD $ do+ d <- findElem $ ById "one"+ d `shouldBeTag` "div"+ s1 <- findNgFrom d $ ByBinding "{{cost}}"+ s1 `shouldBeTag` "span"+ s1 `shouldHaveAttr` ("id", "span-one")
− test/NgSpecs.hs
@@ -1,118 +0,0 @@-{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}-module NgSpecs where--import Test.Hspec.WebDriver-import Test.WebDriver.Commands.Angular--ngSpecs :: Spec-ngSpecs = describe "Angular webdriver commands" $ do- it "finds elements by binding" $ using Firefox $ do- openPage "http://localhost:3456/index.html"- waitForAngular "body" `shouldReturn` True-- binding <- findNg $ ByBinding "{{a}}"- binding `shouldBeTag` "h1"- binding `shouldHaveText` "Hello A!"-- it "does not find missing model elements" $ using Firefox $ do- findNgs (ByModel "qqq") `shouldReturn` []- findNg (ByModel "qqq") `shouldThrow` NgException "Selector ByModel \"qqq\" returned []"-- it "finds input elements" $ using Firefox $ do- i <- findNg $ ByModel "xxx"- i `shouldBeTag` "input"- sendKeys "John" i-- xHead <- findNg $ ByBinding "{{xxx}}"- xHead `shouldBeTag` "h1"- xHead `shouldHaveText` "X John"-- it "finds textarea elements" $ using Firefox $ do- t <- findNg $ ByModel "yyy"- t `shouldBeTag` "textarea"- sendKeys "Mark" t-- yHead <- findNg $ ByBinding "{{yyy}}"- yHead `shouldBeTag` "h2"- yHead `shouldHaveText` "Y Mark"-- it "finds select elements" $ using Firefox $ do- s <- findNg $ ByModel "zzz"- s `shouldBeTag` "select"- opt <- findElemFrom s $ ByCSS "option[value=\"Bar\"]"- click opt-- zHead <- findNg $ ByBinding "{{zzz}}"- zHead `shouldBeTag` "h3"- zHead `shouldHaveText` "Z Bar"-- it "finds selected option inside select opt" $ using Firefox $ do- opt <- findNg $ BySelectedOption "zzz"- opt `shouldBeTag` "option"- opt `shouldHaveText` "Bar"-- it "finds model elements of different types" $ using Firefox $ do- [i, t, s] <- findNgs $ ByModel "name"- i `shouldBeTag` "input"- t `shouldBeTag` "textarea"- s `shouldBeTag` "select"-- it "finds all repeater rows" $ using Firefox $ do- [r1, r2, r3] <- findRepeaters $ ByRows "dog in dogs"- mapM_ (`shouldBeTag`"li") [r1, r2, r3]- r1 `shouldHaveText` "Spot mutt"- r2 `shouldHaveText` "Spike poodle"- r3 `shouldHaveText` "Jupiter bulldog"-- findRepeaters (ByRows "cat in cats") `shouldReturn` []- findRepeater (ByRows "cat in cats") `shouldThrow` NgException "Selector ByRows \"cat in cats\" returned []"-- it "finds a single repeater row" $ using Firefox $ do- r2 <- findRepeater $ ByRow "dog in dogs" 1- r2 `shouldBeTag` "li"- r2 `shouldHaveText` "Spike poodle"-- findRepeaters (ByRow "cat in cats" 1) `shouldReturn` []- findRepeater (ByRow "cat in cats" 1) `shouldThrow` NgException "Selector ByRow \"cat in cats\" 1 returned []"-- it "finds a repeater column" $ using Firefox $ do- [c1, c2, c3] <- findRepeaters $ ByColumn "dog in dogs" "{{dog.name}}"- mapM_ (`shouldBeTag`"span") [c1, c2, c3]-- c1 `shouldHaveText` "Spot"- c2 `shouldHaveText` "Spike"- c3 `shouldHaveText` "Jupiter"-- findRepeaters (ByColumn "cat in cats" "{{cat.name}}") `shouldReturn` []- findRepeater (ByColumn "cat in cats" "{{cat.name}}") `shouldThrow`- NgException "Selector ByColumn \"cat in cats\" \"{{cat.name}}\" returned []"-- it "finds a repeater by row and column" $ using Firefox $ do- c2 <- findRepeater $ ByRowAndCol "dog in dogs" 1 "{{dog.breed}}"- c2 `shouldBeTag` "span"- c2 `shouldHaveText` "poodle"-- findRepeaters (ByRowAndCol "cat in cats" 12 "{{cat.name}}") `shouldReturn` []- findRepeater (ByRowAndCol "cat in cats" 22 "{{cat.name}}") `shouldThrow`- NgException "Selector ByRowAndCol \"cat in cats\" 22 \"{{cat.name}}\" returned []"-- it "evaluates an angular expression" $ using Firefox $ do- e <- findNg $ ByBinding "{{a}}"- ngEvaluate e "cost | number:2" `shouldReturn` ("12.60" :: String)-- it "loads the location url" $ using Firefox $ do- getLocationAbsUrl "body" `shouldReturn` "http://localhost:3456/index.html"-- it "loads {{cost}} from document" $ using Firefox $ do- [s1, s2] <- findNgs $ ByBinding "{{cost}}"- s1 `shouldBeTag` "span"- s2 `shouldBeTag` "span"- s1 `shouldHaveAttr` ("id", "span-one")- s2 `shouldHaveAttr` ("id", "span-two")-- it "loads {{cost}} only from one element" $ using Firefox $ do- d <- findElem $ ById "one"- d `shouldBeTag` "div"- s1 <- findNgFrom d $ ByBinding "{{cost}}"- s1 `shouldBeTag` "span"- s1 `shouldHaveAttr` ("id", "span-one")
test/main.hs view
@@ -6,16 +6,13 @@ import Network.Wai.Application.Static import Network.Wai.Handler.Warp (run) import Test.Hspec (hspec)-import Test.Hspec.WebDriver (createSessionManager) -import NgSpecs-import ManagerSpecs+import NgSpec startServer :: IO ThreadId startServer = forkIO $ run 3456 $ staticApp $ defaultFileServerSettings "test/www" main :: IO ()-main = bracket startServer killThread $ \_ -> do- createSessionManager 2- hspec $ ngSpecs >> mSpecs+main = bracket startServer killThread $ \_ ->+ hspec $ ngSpec
webdriver-angular.cabal view
@@ -1,5 +1,5 @@ name: webdriver-angular-version: 0.1.2+version: 0.1.3 cabal-version: >= 1.8 build-type: Simple synopsis: Webdriver actions to assist with testing a webpage which uses Angular.Js@@ -40,7 +40,8 @@ build-depends: base >= 4 && < 5 - , webdriver >= 0.5 && < 0.6+ -- 0.5.3.1 contains a needed bugfix+ , webdriver >= 0.5.3.1 && < 0.6 , aeson >= 0.6 , language-javascript >= 0.5 && < 0.6 , template-haskell >= 0.6@@ -56,7 +57,7 @@ build-depends: base >= 4 && < 5 , hspec >= 1.8- , hspec-webdriver+ , hspec-webdriver >= 0.2 && < 0.3 , transformers , wai-app-static >= 2.0 , warp >= 2.0