Skip to content

Commit

Permalink
Fix for #105 Inconsisten behaviour between element and someElementWithin
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Sep 7, 2013
1 parent 01e1935 commit 519406f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
14 changes: 14 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,19 @@ if not (browser :? OpenQA.Selenium.PhantomJS.PhantomJSDriver) then
click "#confirmation_test"
alert() == "Not the message")

context "multiple elements test"

before (fun _ -> !^ "http://lefthandedgoat.github.io/canopy/testpages/")

"no error with multiple elements" &&&& fun _ ->
read (element "input") === "test value 1"

"error with multiple elements" &&&& fun _ ->
throwIfMoreThanOneElement <- true
failsWith "More than one element was selected when only one was expected for selector: input"
read (element "input") === "test value 1"


context "tiling windows"
"start multiple browsers and tile them" &&& (fun _ ->
start chrome
Expand All @@ -461,6 +474,7 @@ context "tiling windows"
)

context "todo tests"

"write a test that tests the whole internet!" &&& todo

run ()
Expand Down
23 changes: 17 additions & 6 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,31 @@ let private findMany cssSelector timeout (searchContext : ISearchContext) =
findByFunction cssSelector timeout findElements searchContext

//get elements

let private elementFromList cssSelector elementsList =
match elementsList with
| [] -> null
| x :: [] -> x
| x :: y :: _ ->
if throwIfMoreThanOneElement then raise (CanopyMoreThanOneElementFoundException(sprintf "More than one element was selected when only one was expected for selector: %s" cssSelector))
else x

let private someElementFromList cssSelector elementsList =
match elementsList with
| [x] -> Some(x)
| [] -> None
| _ -> raise (CanopyMoreThanOneElementFoundException(sprintf "More than one element was selected when only one was expected for selector: %s" cssSelector))
| [] -> None
| x :: [] -> Some(x)
| x :: y :: _ ->
if throwIfMoreThanOneElement then raise (CanopyMoreThanOneElementFoundException(sprintf "More than one element was selected when only one was expected for selector: %s" cssSelector))
else Some(x)

let elements cssSelector = findMany cssSelector elementTimeout browser

let element cssSelector = find cssSelector elementTimeout browser
let element cssSelector = cssSelector |> elements |> elementFromList cssSelector

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

let parent elem = elem |> elementWithin ".."

let elements cssSelector = findMany cssSelector elementTimeout browser

let elementsWithin cssSelector elem = findMany cssSelector elementTimeout elem

let someElement cssSelector = cssSelector |> elements |> someElementFromList cssSelector
Expand Down
3 changes: 2 additions & 1 deletion canopy/configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ let mutable wipSleep = 1.0
let mutable runFailedContextsFirst = false
let mutable reporter : IReporter = new ConsoleReporter() :> IReporter
let mutable disableSuggestOtherSelectors = false
let mutable autoPinBrowserRightOnLaunch = true
let mutable autoPinBrowserRightOnLaunch = true
let mutable throwIfMoreThanOneElement = false

0 comments on commit 519406f

Please sign in to comment.