packages feed

webdriver-angular 0.1.6 → 0.1.7

raw patch · 5 files changed

+98/−52 lines, 5 files

Files

src/Test/WebDriver/Commands/Angular.hs view
@@ -15,8 +15,8 @@     , findNgFrom     , findNgsFrom     , NgRepeater(..)-    , findRepeater     , findRepeaters+    , findRepeater     , findRepeaterFrom     , findRepeatersFrom @@ -26,10 +26,8 @@     , setNgLocation     ) where -import Control.Applicative ((<$>)) import Control.Monad.IO.Class (liftIO, MonadIO) import Control.Exception (throwIO, Exception)-import Data.Maybe (catMaybes) import Data.Typeable (Typeable) import Test.WebDriver.Class import Test.WebDriver.Commands@@ -52,16 +50,20 @@     where         body = maybe (error $ "Unable to find " ++ T.unpack script) id $ M.lookup script cs --- | Variant of execCS that fails properly on Null-execElems :: WebDriver wd => T.Text -> [JSArg] -> wd [Element]+-- | Variant of execCS that parses a list of Elements+execElems :: (WebDriver wd, A.FromJSON a) => T.Text -> [JSArg] -> wd [a] execElems script arg = do-    x <- execCS script arg-    case (x, A.fromJSON x) of-        (A.Null, _) -> return []-        (A.Array _, A.Success [A.Null]) -> return []-        _ -> catMaybes <$> fromJSON' x -- parse as [Maybe Element] and drop the nothings because-                                       -- looking up ByRow returns Nulls in the list.+    mlst <- execCS script arg+    case mlst of+        Nothing -> return []+        -- the return list can have Null or Array [Null, Null, Null, Null] inside it for some reason+        -- only objects can be parsed as elements, so filter out the objects+        Just lst -> mapM fromJSON' $ filter isObject lst +  where+    isObject (A.Object _) = True+    isObject _ = False+ asyncCS :: (WebDriver wd, A.FromJSON a) => T.Text -> [JSArg] -> wd (Maybe a) asyncCS script arg = asyncJS arg body     where@@ -130,21 +132,23 @@ findNg' e (ByModel name) = execElems "findByModel" [JSArg name, e] findNg' e (BySelectedOption name) = execElems "findSelectedOptions" [JSArg name, e] --- | Find an element from the document which matches the Angular repeater.  If zero or more than one--- element are returned, an exception of type 'NgException' is thrown.+-- | A variant on 'findRepeaters' which throws an exception if the return value from 'findRepeaters'+-- does not have length exactly one. findRepeater :: (MonadIO wd, WebDriver wd) => NgRepeater -> wd Element findRepeater r = checkOne r =<< findRepeater' (JSArg A.Null) r --- | Find elements from the document which match the Angular repeater.+-- | Finds elements from the document which match the 'NgRepeater'.+--+-- Note that when using ng-repeat-start and ng-repeat-end and looking up using 'ByRows', all+-- elements are returned in one big list, not grouped by each instance of ng-repeat-start. findRepeaters :: WebDriver wd => NgRepeater -> wd [Element] findRepeaters = findRepeater' $ JSArg A.Null --- | Find an element from the given element which matches the Angular repeater.  If zero or more than--- one are returned, an exception of type 'NgException' is thrown.+-- | A variant of 'findRepater' which allows searching only the given element. findRepeaterFrom :: (MonadIO wd, WebDriver wd) => Element -> NgRepeater -> wd Element findRepeaterFrom e r = checkOne r =<< findRepeater' (JSArg e) r --- | Find elements from the given element which match the Angular repeater.+-- | A variant of 'findRepaters' which allows searching only the given element. findRepeatersFrom :: WebDriver wd => Element -> NgRepeater -> wd [Element] findRepeatersFrom e = findRepeater' $ JSArg e @@ -176,4 +180,3 @@     case x of         A.Null -> return ()         _ -> liftIO $ throwIO $ NgException $ "Error setting location: " ++ show x-
test/NgSpec.hs view
@@ -5,7 +5,7 @@ import Test.WebDriver.Commands.Angular  ngSpec :: Spec-ngSpec = session "Angular webdriver commands" $ using Firefox $ do+ngSpec = session "Angular webdriver commands" $ using Chrome $ do     it "opens the page" $ runWD $ do         openPage "http://localhost:3456/index.html"         waitForAngular "body" `shouldReturn` True@@ -58,44 +58,78 @@         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"+    describe "ng-repeat" $ do -        findRepeaters (ByRows "cat in cats") `shouldReturn` []-        findRepeater (ByRows "cat in cats") `shouldThrow` NgException "Selector ByRows \"cat in cats\" returned []"+        it "finds all repeater rows" $ runWD $ do+            [r1, r2, r3] <- findRepeaters $ ByRows "dog in dogs1"+            mapM_ (`shouldBeTag`"li") [r1, r2, r3]+            r1 `shouldHaveText` "Spot mutt"+            r2 `shouldHaveText` "Spike poodle"+            r3 `shouldHaveText` "Jupiter bulldog" -    it "finds a single repeater row" $ runWD $ do-        r2 <- findRepeater $ ByRow "dog in dogs" 1-        r2 `shouldBeTag` "li"-        r2 `shouldHaveText` "Spike poodle"+            findRepeaters (ByRows "cat in cats") `shouldReturn` []+            findRepeater (ByRows "cat in cats") `shouldThrow` NgException "Selector ByRows \"cat in cats\" returned []" -        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 single repeater row" $ runWD $ do+            r2 <- findRepeater $ ByRow "dog in dogs1" 1+            r2 `shouldBeTag` "li"+            r2 `shouldHaveText` "Spike poodle" -    it "finds a repeater column" $ runWD $ do-        [c1, c2, c3] <- findRepeaters $ ByColumn "dog in dogs" "{{dog.name}}"-        mapM_ (`shouldBeTag`"span") [c1, c2, c3]+            findRepeaters (ByRow "cat in cats" 1) `shouldReturn` []+            findRepeater (ByRow "cat in cats" 1) `shouldThrow` NgException "Selector ByRow \"cat in cats\" 1 returned []" -        c1 `shouldHaveText` "Spot"-        c2 `shouldHaveText` "Spike"-        c3 `shouldHaveText` "Jupiter"+        it "finds a repeater column" $ runWD $ do+            [c1, c2, c3] <- findRepeaters $ ByColumn "dog in dogs1" "{{dog.name}}"+            mapM_ (`shouldBeTag`"span") [c1, c2, c3] -        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 []"+            c1 `shouldHaveText` "Spot"+            c2 `shouldHaveText` "Spike"+            c3 `shouldHaveText` "Jupiter" -    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 (ByColumn "cat in cats" "{{cat.name}}") `shouldReturn` []+            findRepeater (ByColumn "cat in cats" "{{cat.name}}") `shouldThrow`+                NgException "Selector ByColumn \"cat in cats\" \"{{cat.name}}\" returned []" -        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 "finds a repeater by row and column" $ runWD $ do+            c2 <- findRepeater $ ByRowAndCol "dog in dogs1" 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 []"++    describe "ng-repeat-start and ng-repeat-end" $ do++        it "finds all repeater rows" $ runWD $ do+            [r1, r1', r2, r2', r3, r3'] <- findRepeaters $ ByRows "dog in dogs2"+            mapM_ (`shouldBeTag`"li") [r1, r2, r3, r1', r2', r3']+            r1  `shouldHaveText` "Spot"+            r1' `shouldHaveText` "mutt"+            r2  `shouldHaveText` "Spike"+            r2' `shouldHaveText` "poodle"+            r3  `shouldHaveText` "Jupiter"+            r3' `shouldHaveText` "bulldog"++        it "finds a single repeater row" $ runWD $ do+            r2 <- findRepeaters $ ByRow "dog in dogs2" 1+            length r2 `shouldBe` 2+            mapM_ (`shouldBeTag` "li") r2+            head r2 `shouldHaveText` "Spike"+            (r2 !! 1) `shouldHaveText` "poodle"++        it "finds a repeater column" $ runWD $ do+            [c1, c2, c3] <- findRepeaters $ ByColumn "dog in dogs2" "{{dog.name}}"+            mapM_ (`shouldBeTag`"span") [c1, c2, c3]++            c1 `shouldHaveText` "Spot"+            c2 `shouldHaveText` "Spike"+            c3 `shouldHaveText` "Jupiter"++        it "finds a repeater by row and column" $ runWD $ do+            c2 <- findRepeater $ ByRowAndCol "dog in dogs2" 1 "{{dog.breed}}"+            c2 `shouldBeTag` "span"+            c2 `shouldHaveText` "poodle"      it "evaluates an angular expression" $ runWD $ do         e <- findNg $ ByBinding "{{a}}"
test/www/index.html view
@@ -24,10 +24,18 @@                     <option value="Bar">Bar</option>             </select>             <ul>-                <li ng-repeat="dog in dogs">+                <li ng-repeat="dog in dogs1">                     <span>{{dog.name}}</span>                     <span>{{dog.breed}}</span>                 </li>+            </ul>+	    <ul>+		<li ng-repeat-start="dog in dogs2">+		    <span>{{dog.name}}</span>+		 </li>+		 <li ng-repeat-end>+                    <span>{{dog.breed}}+                 </li>             </ul>             <div id="one">                 <span id="span-one">{{cost}}</span>
test/www/ng.js view
@@ -1,8 +1,9 @@ angular.module("test", []) .controller("TestCtrl", function($scope) {     $scope.a = "A";-    $scope.dogs = [{name:"Spot", breed:"mutt"},+    $scope.dogs1 = [{name:"Spot", breed:"mutt"},                    {name:"Spike", breed:"poodle"},                    {name:"Jupiter", breed:"bulldog"}];+    $scope.dogs2 = angular.copy($scope.dogs1);     $scope.cost = 12.6; });
webdriver-angular.cabal view
@@ -1,5 +1,5 @@ name:              webdriver-angular-version:           0.1.6+version:           0.1.7 cabal-version:     >= 1.8 build-type:        Simple synopsis:          Webdriver actions to assist with testing a webpage which uses Angular.Js