Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ability to define custom function and wait for it to be true, a…

…lso added ability to get an element/elements so look at properties yourself.
  • Loading branch information...
commit 0bdbd45e8ef2cfa3b786e5c5420633fa15f865d1 1 parent 7b6a6c0
@lefthandedgoat authored
Showing with 37 additions and 1 deletion.
  1. +17 −0 basictests/Program.fs
  2. +16 −1 canopy/canopy.fs
  3. +4 −0 testpages/app.rb
View
17 basictests/Program.fs
@@ -239,6 +239,23 @@ test (fun _ ->
click "#confirmation_test"
alert() == "Not the message")
+wip (fun _ ->
+ describe "define a custom wait for using any function that takes in unit and returns bool"
+ let pageLoaded () =
+ (element "#wait_for").Text = "Done!"
+
+ !^ "http://localhost:4567/waitFor"
+ waitFor pageLoaded
+ "#wait_for" == "Done!")
+
+wip (fun _ ->
+ describe "define a custom wait for using any function that takes in unit and returns bool, example using lists"
+ let fiveNumbersShown () =
+ (elements ".number").Count = 5
+
+ !^ "http://localhost:4567/waitFor"
+ waitFor fiveNumbersShown)
+
run ()
quit ()
View
17 canopy/canopy.fs
@@ -276,4 +276,19 @@ let acceptAlert _ =
browser.SwitchTo().Alert().Accept()
let dismissAlert _ =
- browser.SwitchTo().Alert().Dismiss()
+ browser.SwitchTo().Alert().Dismiss()
+
+let waitFor (f : unit -> bool) =
+ try
+ let wait = new WebDriverWait(browser, TimeSpan.FromSeconds(compareTimeout))
+ wait.Until(fun _ -> (f ())) |> ignore
+ with
+ | :? System.TimeoutException -> Console.WriteLine("Condition not met in given amount of time. If you want to increase the time, put compareTimeout <- 10 anywhere before a test to increase the timeout")
+ failwith (String.Format("waitFor condition failed to become true in {0} seconds", compareTimeout))
+ | ex -> failwith ex.Message
+
+let element cssSelector =
+ find cssSelector elementTimeout
+
+let elements cssSelector =
+ findMany cssSelector elementTimeout
View
4 testpages/app.rb
@@ -28,3 +28,7 @@
get '/alert' do
erb :alert
end
+
+get '/waitFor' do
+ erb :waitFor
+end
Please sign in to comment.
Something went wrong with that request. Please try again.