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

Add bindings for file detectors #12

Merged
merged 1 commit into from
Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Selenium.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ findChildren :: forall e f. (Unfoldable f) => Element -> Locator -> Aff (seleniu

Same as `findElements` but starts searching from custom element

#### `setFileDetector`

``` purescript
setFileDetector :: forall e. Driver -> FileDetector -> Eff (selenium :: SELENIUM | e) Unit
```

#### `navigateBack`

``` purescript
Expand Down
9 changes: 9 additions & 0 deletions docs/Selenium/Remote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Module Selenium.Remote

#### `fileDetector`

``` purescript
fileDetector :: forall e. Eff (selenium :: SELENIUM | e) FileDetector
```


6 changes: 6 additions & 0 deletions docs/Selenium/Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ data ScrollBehaviour :: *
data Capabilities :: *
```

#### `FileDetector`

``` purescript
data FileDetector :: *
```

#### `Location`

``` purescript
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var exampleForeigns = [
gulp.task("make", function() {
return purescript.psc({
src: sources,
ffi: foreigns
ffi: foreigns
});
});

Expand All @@ -45,6 +45,7 @@ gulp.task("docs", function() {
"Selenium.Builder": "docs/Selenium/Builder.md",
"Selenium.Key": "docs/Selenium/Key.md",
"Selenium.MouseButton": "docs/Selenium/MouseButton.md",
"Selenium.Remote": "docs/Selenium/Remote.md",
"Selenium.ScrollBehaviuor": "docs/Selenium/ScrollBehaviuor.md",
"Selenium.Types": "docs/Selenium/Types.md"
}
Expand Down
8 changes: 8 additions & 0 deletions src/Selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ exports.get = function(driver) {
};
};

exports.setFileDetector = function(driver) {
return function(detector) {
return function () {
driver.setFileDetector(detector);
};
};
};

exports.wait = function(check) {
return function(timeout) {
return function(driver) {
Expand Down
37 changes: 18 additions & 19 deletions src/Selenium.purs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Selenium
, isEnabled
, getInnerHtml
, clearEl
, setFileDetector
) where

import Prelude
Expand All @@ -44,8 +45,8 @@ import DOM (DOM())

-- | Go to url
foreign import get :: forall e. Driver -> String -> Aff (selenium :: SELENIUM|e) Unit
-- | Wait until first argument returns 'true'. If it returns false an error will be raised
foreign import wait :: forall e. Aff (selenium :: SELENIUM|e) Boolean ->
-- | Wait until first argument returns 'true'. If it returns false an error will be raised
foreign import wait :: forall e. Aff (selenium :: SELENIUM|e) Boolean ->
Int -> Driver ->
Aff (selenium :: SELENIUM|e) Unit
-- | Finalizer
Expand All @@ -58,10 +59,10 @@ foreign import byCss :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
foreign import byId :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
foreign import byName :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
foreign import byXPath :: forall e. String -> Aff (selenium :: SELENIUM|e) Locator
-- | Build locator from asynchronous function returning element.
-- | Build locator from asynchronous function returning element.
-- | I.e. this locator will find first visible element with `.common-element` class
-- | ```purescript
-- | affLocator \el -> do
-- | ```purescript
-- | affLocator \el -> do
-- | commonElements <- byCss ".common-element" >>= findElements el
-- | flagedElements <- traverse (\el -> Tuple el <$> isVisible el) commonElements
-- | maybe err pure $ foldl foldFn Nothing flagedElements
Expand All @@ -73,32 +74,33 @@ foreign import byXPath :: forall e. String -> Aff (selenium :: SELENIUM|e) Locat
foreign import affLocator :: forall e. (Element -> Aff (selenium :: SELENIUM|e) Element) -> Aff (selenium :: SELENIUM|e) Locator


foreign import _findElement :: forall e a. Maybe a -> (a -> Maybe a) ->
foreign import _findElement :: forall e a. Maybe a -> (a -> Maybe a) ->
Driver -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
foreign import _findChild :: forall e a. Maybe a -> (a -> Maybe a) ->
foreign import _findChild :: forall e a. Maybe a -> (a -> Maybe a) ->
Element -> Locator -> Aff (selenium :: SELENIUM|e) (Maybe Element)
foreign import _findElements :: forall e. Driver -> Locator -> Aff (selenium :: SELENIUM|e) (Array Element)
foreign import _findChildren :: forall e. Element -> Locator -> Aff (selenium :: SELENIUM|e) (Array Element)

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

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

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

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

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

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






7 changes: 7 additions & 0 deletions src/Selenium/Remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// module Selenium.Remote

var remote = require('selenium-webdriver/remote');

exports.fileDetector = function () {
return new remote.FileDetector();
};
6 changes: 6 additions & 0 deletions src/Selenium/Remote.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Selenium.Remote where

import Control.Monad.Eff (Eff())
import Selenium.Types

foreign import fileDetector :: forall e. Eff (selenium :: SELENIUM | e) FileDetector
3 changes: 2 additions & 1 deletion src/Selenium/Types.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Selenium.Types where
module Selenium.Types where

foreign import data Builder :: *
foreign import data SELENIUM :: !
Expand All @@ -18,6 +18,7 @@ foreign import data ProxyConfig :: *
foreign import data SafariOptions :: *
foreign import data ScrollBehaviour :: *
foreign import data Capabilities :: *
foreign import data FileDetector :: *


type Location =
Expand Down