Skip to content

Commit

Permalink
displayed and notDisplayed now accept selectors and elements #93
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Sep 12, 2013
1 parent 519406f commit eb132af
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("canopy")>]
[<assembly: AssemblyTitleAttribute("canopy")>]
[<assembly: AssemblyDescriptionAttribute("A simple framework in f# on top of selenium for writing UI automation and tests. Change Log at https://github.com/lefthandedgoat/canopy/wiki/Change-Log")>]
[<assembly: AssemblyVersionAttribute("0.8.4")>]
[<assembly: AssemblyVersionAttribute("0.8.6")>]

()
2 changes: 1 addition & 1 deletion Build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Fake.AssemblyInfoFile

// Assembly / NuGet package properties
let projectName = "canopy"
let version = "0.8.4"
let version = "0.8.6"
let projectDescription = "A simple framework in f# on top of selenium for writing UI automation and tests. Change Log at https://github.com/lefthandedgoat/canopy/wiki/Change-Log"
let authors = ["Chris Holt"]

Expand Down
12 changes: 10 additions & 2 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ context "other tests"
!^ "http://lefthandedgoat.github.io/canopy/testpages/displayed"
displayed "#displayed")

"displayed test via element" &&& (fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/displayed"
element "#displayed" |> displayed)

"displayed test2" &&& (fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/displayed"
waitFor (fun _ -> (element "#displayed").Displayed))
Expand All @@ -390,6 +394,10 @@ context "other tests"
!^ "http://lefthandedgoat.github.io/canopy/testpages/notDisplayed"
notDisplayed "#notDisplayed")

"notDisplayed test via element" &&& (fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/notDisplayed"
element "#notDisplayed" |> notDisplayed)

"notDisplayed test for element that is not on the screen" &&& (fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/notDisplayed"
notDisplayed "#nalsjdfalfalsdjfalsjfaljsflsjf")
Expand Down Expand Up @@ -450,10 +458,10 @@ context "multiple elements test"

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

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

"error with multiple elements" &&&& fun _ ->
"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"
Expand Down
44 changes: 25 additions & 19 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -473,41 +473,47 @@ let is expected actual =

let (===) expected actual = is expected actual

let private shown cssSelector =
let elem = element cssSelector
let private shown (elem : IWebElement) =
let opacity = elem.GetCssValue("opacity")
let display = elem.GetCssValue("display")
display <> "none" && opacity = "1"
let displayed cssSelector =
let displayed item =
try
wait compareTimeout (fun _ -> shown cssSelector)
wait compareTimeout (fun _ ->
match box item with
| :? IWebElement as element -> shown element
| :? string as cssSelector -> element cssSelector |> shown
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't click %O because it is not a string or webelement" item)))
with
| :? WebDriverTimeoutException -> raise (CanopyDisplayedFailedException(sprintf "display checked for %s failed." cssSelector))
| :? WebDriverTimeoutException -> raise (CanopyDisplayedFailedException(sprintf "display checked for %O failed." item))

let notDisplayed cssSelector =
let notDisplayed item =
try
wait compareTimeout (fun _ -> (elements cssSelector |> List.isEmpty) || not(shown cssSelector))
()
wait compareTimeout (fun _ ->
match box item with
| :? IWebElement as element -> not(shown element)
| :? string as cssSelector -> (elements cssSelector |> List.isEmpty) || not(element cssSelector |> shown)
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't click %O because it is not a string or webelement" item)))
with
| :? WebDriverTimeoutException -> raise (CanopyNotDisplayedFailedException(sprintf "notDisplay checked for %s failed." cssSelector));
| :? WebDriverTimeoutException -> raise (CanopyNotDisplayedFailedException(sprintf "notDisplay checked for %O failed." item));

let fadedIn cssSelector = (fun _ -> shown cssSelector)
let fadedIn cssSelector = fun _ -> element cssSelector |> shown

//clicking/checking
let click item =
match box item with
| :? IWebElement as element -> element.Click()
| :? string as cssSelector ->
| :? string as cssSelector ->
wait elementTimeout (fun _ ->
let atleastOneItemClicked = ref false
elements cssSelector
|> List.iter (fun elem ->
try
elem.Click()
atleastOneItemClicked := true
with | ex -> ())
!atleastOneItemClicked)
let atleastOneItemClicked = ref false
elements cssSelector
|> List.iter (fun elem ->
try
elem.Click()
atleastOneItemClicked := true
with | ex -> ())
!atleastOneItemClicked)
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't click %O because it is not a string or webelement" item))
let doubleClick item =
Expand Down

0 comments on commit eb132af

Please sign in to comment.