Skip to content

Commit

Permalink
Fix for #136 add waitFor with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Mar 30, 2014
1 parent 169950e commit 754dc27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ context "other tests"
waitFor pageLoaded
"#wait_for" == "Done!"

"define a custom wait for using any function that takes in unit and returns bool" &&& fun _ ->
failsWith "waiting for page to load
waitFor condition failed to become true in 3.0 seconds"
let pageLoaded () =
(element "#wait_for").Text = "Done!!!"

!^ "http://lefthandedgoat.github.io/canopy/testpages/waitFor"
waitFor2 "waiting for page to load" pageLoaded

"another example of another wait for, waiting on opacity to be 100% before clicking" &&& fun _ ->
compareTimeout <- 10.0
!^ "http://lefthandedgoat.github.io/canopy/testpages/noClickTilVisible"
Expand Down
9 changes: 5 additions & 4 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ let suggestOtherSelectors cssSelector =
let describe text =
puts text

let waitFor (f : unit -> bool) =
let waitFor2 message (f : unit -> bool) =
try
wait compareTimeout f
with
| :? WebDriverTimeoutException ->
puts "Condition not met in given amount of time. If you want to increase the time, put compareTimeout <- 10.0 anywhere before a test to increase the timeout"
raise (CanopyWaitForException(sprintf "waitFor condition failed to become true in %.1f seconds" compareTimeout))
| :? WebDriverTimeoutException ->
raise (CanopyWaitForException(sprintf "%s%swaitFor condition failed to become true in %.1f seconds" message System.Environment.NewLine compareTimeout))

let waitFor = waitFor2 "Condition not met in given amount of time. If you want to increase the time, put compareTimeout <- 10.0 anywhere before a test to increase the timeout"

//find related
let rec private findElements cssSelector (searchContext : ISearchContext) : IWebElement list =
searchedFor <- (cssSelector, browser.Url) :: searchedFor
Expand Down

0 comments on commit 754dc27

Please sign in to comment.