Skip to content

Commit

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

"parent of firstItem and secondItem is list" &&&& (fun _ ->
"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 _ ->
url testpage
None === (someElement "#thisIdDoesNotExist"))

context "reddit tests"
once (fun _ -> Console.WriteLine "once: reddit tests")
before (fun _ -> Console.WriteLine "before: reddit tests")
Expand Down
12 changes: 12 additions & 0 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ let private findMany cssSelector timeout (searchContext : ISearchContext) =
findByFunction cssSelector timeout findElements searchContext

//get elements
let private someElementFromList cssSelector elementsList =
match elementsList with
| [x] -> Some(x)
| [] -> None
| _ -> failwith ("More than one element was selected when only one was expected for selector: " + cssSelector)

let element cssSelector = find cssSelector elementTimeout browser

let elementWithin cssSelector (elem:IWebElement) = find cssSelector elementTimeout elem
Expand All @@ -214,6 +220,12 @@ let elements cssSelector = findMany cssSelector elementTimeout browser

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

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

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

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

let exists cssSelector = find cssSelector elementTimeout browser

let nth index cssSelector = List.nth (elements cssSelector) index
Expand Down

0 comments on commit 0d0eba5

Please sign in to comment.