diff --git a/bower.json b/bower.json index 1c9b486..b2a74f1 100644 --- a/bower.json +++ b/bower.json @@ -17,9 +17,9 @@ ], "license": "Apache-2.0", "dependencies": { - "purescript-aff": "^0.16.0", - "purescript-aff-reattempt": "^0.3.0", - "purescript-base": "^0.2.0", - "purescript-dom": "^0.2.4" + "purescript-aff": "^1.0.0", + "purescript-aff-reattempt": "^1.0.0", + "purescript-base": "^1.0.0", + "purescript-dom": "^1.1.0" } } diff --git a/package.json b/package.json index bcae75c..c2b7453 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,13 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "pulp build" + "build": "pulp build", + "bower": "bower" }, "devDependencies": { - "pulp": "^8.1.0", - "purescript": "^0.7.6", - "rimraf": "^2.5.2" + "pulp": "^9.0.1", + "purescript": "^0.9.1", + "rimraf": "^2.5.3", + "bower": "^1.7.1" } } diff --git a/src/Selenium.purs b/src/Selenium.purs index ec24cdc..faa8ac3 100644 --- a/src/Selenium.purs +++ b/src/Selenium.purs @@ -57,7 +57,7 @@ import Data.Maybe (Maybe()) import Data.Either (either) import Control.Monad.Aff (Aff(), attempt) import Selenium.Types -import Data.Unfoldable (Unfoldable, unfoldr) +import Data.Unfoldable (class Unfoldable, unfoldr) import Data.Foreign (Foreign()) import Data.Maybe (Maybe(..)) import Data.Array (uncons) @@ -116,7 +116,7 @@ loseElement driver locator = do result <- attempt $ findExact driver locator either (const $ pure unit) (const $ throwError $ error failMessage) result where - failMessage = "Found element with locator: " ++ showLocator locator + failMessage = "Found element with locator: " <> showLocator locator -- | Finds elements by locator from `document` findElements :: forall e f. (Unfoldable f) => Driver -> Locator -> Aff (selenium :: SELENIUM|e) (f Element) diff --git a/src/Selenium/ActionSequence.purs b/src/Selenium/ActionSequence.purs index 12fbbfa..29b2263 100644 --- a/src/Selenium/ActionSequence.purs +++ b/src/Selenium/ActionSequence.purs @@ -20,7 +20,7 @@ import Prelude import Selenium.Types import Selenium.MouseButton import Data.List -import Data.Function +import Data.Function.Uncurried import Data.Foldable (foldl) import Control.Monad.Writer (Writer(), execWriter) import Control.Monad.Writer.Class (tell) diff --git a/src/Selenium/Builder.purs b/src/Selenium/Builder.purs index 79a169e..ee93c11 100644 --- a/src/Selenium/Builder.purs +++ b/src/Selenium/Builder.purs @@ -14,7 +14,7 @@ import Selenium.Types import Selenium.Browser import Data.Tuple import Data.List -import Data.Function +import Data.Function.Uncurried import Data.Foldable (foldl) import Control.Monad.Writer (Writer(), execWriter) import Control.Monad.Writer.Class (tell) diff --git a/src/Selenium/Combinators.purs b/src/Selenium/Combinators.purs index db041ee..99d0a23 100644 --- a/src/Selenium/Combinators.purs +++ b/src/Selenium/Combinators.purs @@ -4,7 +4,6 @@ import Prelude import Control.Alt ((<|>)) import Control.Monad.Trans (lift) import Data.Maybe (Maybe(), isJust, maybe) -import Data.Maybe.Unsafe (fromJust) import Data.Either (Either(..), either) import Control.Monad.Error.Class (throwError) import Control.Monad.Eff.Exception (error) @@ -33,7 +32,7 @@ tryFind probablyLocator = waitUntilJust :: forall e o a. Selenium e o (Maybe a) -> Int -> Selenium e o a waitUntilJust check time = do wait (checker $ isJust <$> check) time - fromJust <$> check + check >>= maybe (throwError $ error $ "Maybe was not Just after waiting for isJust") pure -- Tries to evaluate `Selenium` if it returns `false` after 500ms checker :: forall e o. Selenium e o Boolean -> Selenium e o Boolean @@ -81,4 +80,4 @@ await timeout check = do Right _ -> pure unit awaitUrlChanged :: forall e o. String -> Selenium e o Boolean -awaitUrlChanged oldURL = checker $ (oldURL /=) <$> getCurrentUrl +awaitUrlChanged oldURL = checker $ (oldURL /= _) <$> getCurrentUrl diff --git a/src/Selenium/Monad.purs b/src/Selenium/Monad.purs index 63faed2..7990bd5 100644 --- a/src/Selenium/Monad.purs +++ b/src/Selenium/Monad.purs @@ -15,11 +15,11 @@ import Control.Monad.Eff.Console (CONSOLE()) import Control.Monad.Eff.Ref (REF()) import Control.Monad.Reader.Trans import Control.Monad.Reader.Class -import qualified Control.Monad.Aff as A -import qualified Control.Monad.Aff.Reattempt as A -import qualified Selenium as S -import qualified Selenium.ActionSequence as S -import qualified Selenium.XHR as S +import Control.Monad.Aff as A +import Control.Monad.Aff.Reattempt as A +import Selenium as S +import Selenium.ActionSequence as S +import Selenium.XHR as S -- | `Driver` is field of `ReaderT` context -- | Usually selenium tests are run with tons of configs (i.e. xpath locators, -- | timeouts) all those configs can be putted to `Selenium e o a` @@ -236,7 +236,7 @@ clearLog :: forall e o. Selenium e o Unit clearLog = getDriver >>= S.clearLog >>> lift getXHRStats :: forall e o. Selenium e o (List XHRStats) -getXHRStats = getDriver >>= S.getStats >>> map toList >>> lift +getXHRStats = getDriver >>= S.getStats >>> map fromFoldable >>> lift getWindowHandle :: forall e o. Selenium e o WindowHandle diff --git a/src/Selenium/Types.purs b/src/Selenium/Types.purs index 1e118f7..8838c42 100644 --- a/src/Selenium/Types.purs +++ b/src/Selenium/Types.purs @@ -1,7 +1,7 @@ module Selenium.Types where import Prelude -import Data.Foreign.Class (IsForeign) +import Data.Foreign.Class (class IsForeign) import Data.Foreign (readString, ForeignError(..)) import Data.String (toLower) import Data.Either (Either(..)) diff --git a/src/Selenium/XHR.purs b/src/Selenium/XHR.purs index f95e368..df82b0f 100644 --- a/src/Selenium/XHR.purs +++ b/src/Selenium/XHR.purs @@ -10,12 +10,12 @@ import Control.Monad.Error.Class (throwError) import Control.Monad.Eff.Exception (error) import Data.Foreign (readBoolean, isUndefined, readArray) import Data.Foreign.Class (readProp) -import Data.Foreign.NullOrUndefined (runNullOrUndefined) +import Data.Foreign.NullOrUndefined (unNullOrUndefined) -- | Start spy on xhrs. It defines global variable in browser --- | and put information about to it. +-- | and put information about to it. startSpying :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit -startSpying driver = void $ +startSpying driver = void $ executeStr driver """ "use strict" // If we have activated spying @@ -52,13 +52,13 @@ if (window.__SELENIUM__) { var send = XMLHttpRequest.prototype.send; window.XMLHttpRequest.prototype.send = function(data) { - // this request can be deleted (this.clean() i.e.) + // this request can be deleted (this.clean() i.e.) if (Selenium.log[this.__id]) { Selenium.log[this.__id].state = "opened"; } // monkey pathc `onload` (I suppose it's useless to fire xhr // without `onload` handler, but to be sure there is check for - // type of current value + // type of current value var m = this.onload; this.onload = function() { if (Selenium.log[this.__id]) { @@ -70,7 +70,7 @@ if (window.__SELENIUM__) { }; send.apply(this, arguments); }; - // monkey patch `abort` + // monkey patch `abort` var abort = window.XMLHttpRequest.prototype.abort; window.XMLHttpRequest.prototype.abort = function() { if (Selenium.log[this.__id]) { @@ -79,7 +79,7 @@ if (window.__SELENIUM__) { abort.apply(this, arguments); }; this.isActive = true; - // if we define it here we need not to make `send` global + // if we define it here we need not to make `send` global Selenium.unspy = function() { this.active = false; window.XMLHttpRequest.send = send; @@ -106,8 +106,8 @@ if (window.__SELENIUM__) { """ -- | Clean log. Will raise an error if spying hasn't been initiated -clearLog :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit -clearLog driver = do +clearLog :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit +clearLog driver = do success <- executeStr driver """ if (!window.__SELENIUM__) { return false; @@ -123,7 +123,7 @@ clearLog driver = do -- | Get recorded xhr stats. If spying has not been set will raise an error getStats :: forall e. Driver -> Aff (selenium :: SELENIUM|e) (Array XHRStats) -getStats driver = do +getStats driver = do log <- executeStr driver """ if (!window.__SELENIUM__) { return undefined; @@ -142,8 +142,8 @@ getStats driver = do method <- readProp "method" el url <- readProp "url" el async <- readProp "async" el - password <- runNullOrUndefined <$> readProp "password" el - user <- runNullOrUndefined <$> readProp "user" el + password <- unNullOrUndefined <$> readProp "password" el + user <- unNullOrUndefined <$> readProp "user" el pure { state: state , method: method , url: url @@ -151,6 +151,3 @@ getStats driver = do , password: password , user: user } - - -