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

Commit ddb4e28

Browse files
committed
Add bindings for file detectors
1 parent d582cbc commit ddb4e28

File tree

9 files changed

+64
-21
lines changed

9 files changed

+64
-21
lines changed

docs/Selenium.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ findChildren :: forall e f. (Unfoldable f) => Element -> Locator -> Aff (seleniu
106106

107107
Same as `findElements` but starts searching from custom element
108108

109+
#### `setFileDetector`
110+
111+
``` purescript
112+
setFileDetector :: forall e. Driver -> FileDetector -> Eff (selenium :: SELENIUM | e) Unit
113+
```
114+
109115
#### `navigateBack`
110116

111117
``` purescript

docs/Selenium/Remote.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Module Selenium.Remote
2+
3+
#### `fileDetector`
4+
5+
``` purescript
6+
fileDetector :: forall e. Eff (selenium :: SELENIUM | e) FileDetector
7+
```
8+
9+

docs/Selenium/Types.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ data ScrollBehaviour :: *
108108
data Capabilities :: *
109109
```
110110

111+
#### `FileDetector`
112+
113+
``` purescript
114+
data FileDetector :: *
115+
```
116+
111117
#### `Location`
112118

113119
``` purescript

gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var exampleForeigns = [
2323
gulp.task("make", function() {
2424
return purescript.psc({
2525
src: sources,
26-
ffi: foreigns
26+
ffi: foreigns
2727
});
2828
});
2929

@@ -45,6 +45,7 @@ gulp.task("docs", function() {
4545
"Selenium.Builder": "docs/Selenium/Builder.md",
4646
"Selenium.Key": "docs/Selenium/Key.md",
4747
"Selenium.MouseButton": "docs/Selenium/MouseButton.md",
48+
"Selenium.Remote": "docs/Selenium/Remote.md",
4849
"Selenium.ScrollBehaviuor": "docs/Selenium/ScrollBehaviuor.md",
4950
"Selenium.Types": "docs/Selenium/Types.md"
5051
}

src/Selenium.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ exports.get = function(driver) {
1111
};
1212
};
1313

14+
exports.setFileDetector = function(driver) {
15+
return function(detector) {
16+
return function () {
17+
driver.setFileDetector(detector);
18+
};
19+
};
20+
};
21+
1422
exports.wait = function(check) {
1523
return function(timeout) {
1624
return function(driver) {

src/Selenium.purs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Selenium
2727
, isEnabled
2828
, getInnerHtml
2929
, clearEl
30+
, setFileDetector
3031
) where
3132

3233
import Prelude
@@ -44,8 +45,8 @@ import DOM (DOM())
4445

4546
-- | Go to url
4647
foreign import get :: forall e. Driver -> String -> Aff (selenium :: SELENIUM|e) Unit
47-
-- | Wait until first argument returns 'true'. If it returns false an error will be raised
48-
foreign import wait :: forall e. Aff (selenium :: SELENIUM|e) Boolean ->
48+
-- | Wait until first argument returns 'true'. If it returns false an error will be raised
49+
foreign import wait :: forall e. Aff (selenium :: SELENIUM|e) Boolean ->
4950
Int -> Driver ->
5051
Aff (selenium :: SELENIUM|e) Unit
5152
-- | Finalizer
@@ -58,10 +59,10 @@ foreign import byCss :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
5859
foreign import byId :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
5960
foreign import byName :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
6061
foreign import byXPath :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
61-
-- | Build locator from asynchronous function returning element.
62+
-- | Build locator from asynchronous function returning element.
6263
-- | I.e. this locator will find first visible element with `.common-element` class
63-
-- | ```purescript
64-
-- | affLocator \el -> do
64+
-- | ```purescript
65+
-- | affLocator \el -> do
6566
-- | commonElements <- byCss ".common-element" >>= findElements el
6667
-- | flagedElements <- traverse (\el -> Tuple el <$> isVisible el) commonElements
6768
-- | maybe err pure $ foldl foldFn Nothing flagedElements
@@ -73,32 +74,33 @@ foreign import byXPath :: forall e. String -> Aff (selenium :: SELENIUM|e) Locat
7374
foreign import affLocator :: forall e. (Element -> Aff (selenium :: SELENIUM|e) Element) -> Aff (selenium :: SELENIUM|e) Locator
7475

7576

76-
foreign import _findElement :: forall e a. Maybe a -> (a -> Maybe a) ->
77+
foreign import _findElement :: forall e a. Maybe a -> (a -> Maybe a) ->
7778
Driver -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
78-
foreign import _findChild :: forall e a. Maybe a -> (a -> Maybe a) ->
79+
foreign import _findChild :: forall e a. Maybe a -> (a -> Maybe a) ->
7980
Element -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
8081
foreign import _findElements :: forall e. Driver -> Locator -> Aff (selenium :: SELENIUM|e) (Array Element)
8182
foreign import _findChildren :: forall e. Element -> Locator -> Aff (selenium :: SELENIUM|e) (Array Element)
8283

8384
-- | Tries to find an element starting from `document` will return `Nothing` if there
8485
-- | is no element can be found by locator
8586
findElement :: forall e. Driver -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
86-
findElement = _findElement Nothing Just
87+
findElement = _findElement Nothing Just
8788

8889
-- | Finds elements by locator from `document`
89-
findElements :: forall e f. (Unfoldable f) => Driver -> Locator -> Aff (selenium :: SELENIUM|e) (f Element)
90-
findElements driver locator =
90+
findElements :: forall e f. (Unfoldable f) => Driver -> Locator -> Aff (selenium :: SELENIUM|e) (f Element)
91+
findElements driver locator =
9192
unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs) <$> (_findElements driver locator)
9293

93-
-- | Same as `findElement` but starts searching from custom element
94+
-- | Same as `findElement` but starts searching from custom element
9495
findChild :: forall e. Element -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
9596
findChild = _findChild Nothing Just
9697

9798
-- | Same as `findElements` but starts searching from custom element
98-
findChildren :: forall e f. (Unfoldable f) => Element -> Locator -> Aff (selenium ::SELENIUM|e) (f Element)
99-
findChildren el locator =
99+
findChildren :: forall e f. (Unfoldable f) => Element -> Locator -> Aff (selenium ::SELENIUM|e) (f Element)
100+
findChildren el locator =
100101
unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs) <$> (_findChildren el locator)
101102

103+
foreign import setFileDetector :: forall e. Driver -> FileDetector -> Eff (selenium :: SELENIUM|e) Unit
102104

103105
foreign import navigateBack :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit
104106
foreign import navigateForward :: forall e. Driver -> Aff (selenium :: SELENIUM|e) Unit
@@ -116,14 +118,11 @@ foreign import getAttribute :: forall e. Element -> String -> Aff (selenium :: S
116118
foreign import isDisplayed :: forall e. Element -> Aff (selenium :: SELENIUM|e) Boolean
117119
foreign import isEnabled :: forall e. Element -> Aff (selenium :: SELENIUM|e) Boolean
118120
foreign import getInnerHtml :: forall e. Element -> Aff (selenium :: SELENIUM|e) String
119-
-- | Clear `value` of element, if it has no value will do nothing.
120-
-- | If `value` is weakly referenced by `virtual-dom` (`purescript-halogen`)
121-
-- | will not work -- to clear such inputs one should use direct signal from
121+
-- | Clear `value` of element, if it has no value will do nothing.
122+
-- | If `value` is weakly referenced by `virtual-dom` (`purescript-halogen`)
123+
-- | will not work -- to clear such inputs one should use direct signal from
122124
-- | `Selenium.ActionSequence`
123125
foreign import clearEl :: forall e. Element -> Aff (selenium :: SELENIUM|e) Unit
124126

125-
126-
127-
128127

129128

src/Selenium/Remote.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// module Selenium.Remote
2+
3+
var remote = require('selenium-webdriver/remote');
4+
5+
exports.fileDetector = function () {
6+
return new remote.FileDetector();
7+
};

src/Selenium/Remote.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Selenium.Remote where
2+
3+
import Control.Monad.Eff (Eff())
4+
import Selenium.Types
5+
6+
foreign import fileDetector :: forall e. Eff (selenium :: SELENIUM | e) FileDetector

src/Selenium/Types.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Selenium.Types where
1+
module Selenium.Types where
22

33
foreign import data Builder :: *
44
foreign import data SELENIUM :: !
@@ -18,6 +18,7 @@ foreign import data ProxyConfig :: *
1818
foreign import data SafariOptions :: *
1919
foreign import data ScrollBehaviour :: *
2020
foreign import data Capabilities :: *
21+
foreign import data FileDetector :: *
2122

2223

2324
type Location =

0 commit comments

Comments
 (0)