Skip to content

Commit

Permalink
adde someElement/someParent/someElementWith for issue #73
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Apr 22, 2013
1 parent 0d0eba5 commit 6517682
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
22 changes: 21 additions & 1 deletion basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,34 @@ test (fun _ ->
count ".item" 5
2 === (element "span" |> elementsWithin ".item" |> List.length))

"someElementWithin only searching within element" &&& (fun _ ->
url "http://localhost:4567/elementWithin"
count ".item" 5
true === (element "span" |> someElementWithin ".specialItem").IsSome)

"parent of firstItem and secondItem is list" &&& (fun _ ->
url "http://localhost:4567/parent"
"list" === (element "#firstItem" |> parent).GetAttribute("id"))

"someElement returns None when element not found" &&&& (fun _ ->
"some parent of firstItem and secondItem is list" &&& (fun _ ->
url "http://localhost:4567/parent"
true === (element "#firstItem" |> someParent).IsSome
"list" === (element "#firstItem" |> someParent).Value.GetAttribute("id"))

"someElement returns Some when element found" &&& (fun _ ->
url testpage
true === (someElement "#testfield2").IsSome
"test value 2" === (someElement "#testfield2").Value.GetAttribute("value"))

"someElement returns None when element not found" &&& (fun _ ->
url testpage
None === (someElement "#thisIdDoesNotExist"))

"someElement fails when more than one element found" &&& (fun _ ->
url testpage
failsWith "More than one element was selected when only one was expected for selector: .lastName"
someElement ".lastName" |> ignore)

context "reddit tests"
once (fun _ -> Console.WriteLine "once: reddit tests")
before (fun _ -> Console.WriteLine "before: reddit tests")
Expand Down
8 changes: 4 additions & 4 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ let element cssSelector = find cssSelector elementTimeout browser

let elementWithin cssSelector (elem:IWebElement) = find cssSelector elementTimeout elem

let parent (elem:IWebElement) = elem |> elementWithin ".."
let parent elem = elem |> elementWithin ".."

let elements cssSelector = findMany cssSelector elementTimeout browser

let elementsWithin cssSelector (elem:IWebElement) = findMany cssSelector elementTimeout elem
let elementsWithin cssSelector elem = findMany cssSelector elementTimeout elem

let someElement cssSelector = cssSelector |> elements |> someElementFromList cssSelector

let someElementWithin cssSelector element = element |> elementsWithin cssSelector |> someElementFromList cssSelector
let someElementWithin cssSelector elem = elem |> elementsWithin cssSelector |> someElementFromList cssSelector

let someParent (elem:IWebElement) = elem |> elementsWithin ".." |> someElementFromList "provided element"
let someParent elem = elem |> elementsWithin ".." |> someElementFromList "provided element"

let exists cssSelector = find cssSelector elementTimeout browser

Expand Down
1 change: 1 addition & 0 deletions testpages/views/elementWithin.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<span>
<label class="item">spanned item 4</label>
<label class="item">spanned item 5</label>
<label class="specialItem">spanned item 6</label>
</span>


Expand Down

0 comments on commit 6517682

Please sign in to comment.