Skip to content
This repository was archived by the owner on Jan 17, 2020. It is now read-only.

Commit fdd54be

Browse files
committed
Added repeatedlyTryTo function
1 parent 3e6381f commit fdd54be

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
],
1818
"license": "Apache-2.0",
1919
"dependencies": {
20-
"purescript-base": "^0.2.0",
2120
"purescript-aff": "^0.11.3",
21+
"purescript-aff-reattempt": "^0.1.0",
22+
"purescript-base": "^0.2.0",
2223
"purescript-dom": "^0.2.4"
2324
}
2425
}

docs/Selenium/Monad.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ putting `Driver` to `ReaderT`
77
#### `Selenium`
88

99
``` purescript
10-
type Selenium e o a = ReaderT { driver :: Driver | o } (Aff (console :: CONSOLE, selenium :: SELENIUM, dom :: DOM | e)) a
10+
type Selenium e o a = ReaderT { driver :: Driver, defaultTimeout :: Int | o } (Aff (console :: CONSOLE, selenium :: SELENIUM, dom :: DOM, ref :: REF | e)) a
1111
```
1212

1313
`Driver` is field of `ReaderT` context
@@ -94,6 +94,22 @@ get :: forall e o. String -> Selenium e o Unit
9494
wait :: forall e o. Selenium e o Boolean -> Int -> Selenium e o Unit
9595
```
9696

97+
#### `tryRepeatedlyTo'`
98+
99+
``` purescript
100+
tryRepeatedlyTo' :: forall a e o. Int -> Selenium e o a -> Selenium e o a
101+
```
102+
103+
Tries the provided Selenium computation repeatedly until the provided timeout expires
104+
105+
#### `tryRepeatedlyTo`
106+
107+
``` purescript
108+
tryRepeatedlyTo :: forall a e o. Selenium e o a -> Selenium e o a
109+
```
110+
111+
Tries the provided Selenium computation repeatedly until `Selenium`'s defaultTimeout expires
112+
97113
#### `byCss`
98114

99115
``` purescript
@@ -283,7 +299,7 @@ Run sequence of actions
283299
#### `actions`
284300

285301
``` purescript
286-
actions :: forall e o. ({ driver :: Driver | o } -> Sequence Unit) -> Selenium e o Unit
302+
actions :: forall e o. ({ driver :: Driver, defaultTimeout :: Int | o } -> Sequence Unit) -> Selenium e o Unit
287303
```
288304

289305
Same as `sequence` but takes function of `ReaderT` as an argument

src/Selenium.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ foreign import get :: forall e. Driver -> String -> Aff (selenium :: SELENIUM|e)
6363
foreign import wait :: forall e. Aff (selenium :: SELENIUM|e) Boolean ->
6464
Int -> Driver ->
6565
Aff (selenium :: SELENIUM|e) Unit
66+
6667
-- | Finalizer
6768
foreign import quit :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit
6869

src/Selenium/Monad.purs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import Data.List
1414
import DOM
1515
import Selenium.Types
1616
import Control.Monad.Eff.Console (CONSOLE())
17+
import Control.Monad.Eff.Ref (REF())
1718
import Control.Monad.Trans
1819
import Control.Monad.Reader.Trans
1920
import Control.Monad.Reader.Class
2021
import qualified Control.Monad.Aff as A
22+
import qualified Control.Monad.Aff.Reattempt as A
2123
import qualified Selenium as S
2224
import qualified Selenium.ActionSequence as S
2325
import qualified Selenium.XHR as S
@@ -26,8 +28,8 @@ import qualified Selenium.XHR as S
2628
-- | timeouts) all those configs can be putted to `Selenium e o a`
2729
type Selenium e o a =
2830
ReaderT
29-
{driver :: Driver |o}
30-
(A.Aff (console :: CONSOLE, selenium :: SELENIUM, dom :: DOM |e)) a
31+
{driver :: Driver, defaultTimeout :: Int |o}
32+
(A.Aff (console :: CONSOLE, selenium :: SELENIUM, dom :: DOM, ref :: REF |e)) a
3133

3234
-- | get driver from context
3335
getDriver :: forall e o. Selenium e o Driver
@@ -77,6 +79,15 @@ wait :: forall e o. Selenium e o Boolean -> Int -> Selenium e o Unit
7779
wait check time = ReaderT \r ->
7880
S.wait (runReaderT check r) time r.driver
7981

82+
-- | Tries the provided Selenium computation repeatedly until the provided timeout expires
83+
tryRepeatedlyTo' :: forall a e o. Int -> Selenium e o a -> Selenium e o a
84+
tryRepeatedlyTo' time selenium = ReaderT \r ->
85+
A.reattempt time (runReaderT selenium r)
86+
87+
-- | Tries the provided Selenium computation repeatedly until `Selenium`'s defaultTimeout expires
88+
tryRepeatedlyTo :: forall a e o. Selenium e o a -> Selenium e o a
89+
tryRepeatedlyTo selenium = ask >>= \r -> tryRepeatedlyTo' r.defaultTimeout selenium
90+
8091
byCss :: forall e o. String -> Selenium e o Locator
8192
byCss = lift <<< S.byCss
8293

@@ -182,7 +193,7 @@ sequence seq = do
182193
getDriver >>= lift <<< flip S.sequence seq
183194

184195
-- | Same as `sequence` but takes function of `ReaderT` as an argument
185-
actions :: forall e o. ({driver :: Driver |o} -> S.Sequence Unit) -> Selenium e o Unit
196+
actions :: forall e o. ({driver :: Driver, defaultTimeout :: Int |o} -> S.Sequence Unit) -> Selenium e o Unit
186197
actions seqFn = do
187198
ctx <- ask
188199
sequence $ seqFn ctx

0 commit comments

Comments
 (0)