Permalink
Browse files

make write more robust, add stack trace to errors

  • Loading branch information...
1 parent d7969a0 commit 1a3806f24dd249ec19617a96c1dadbcf05c9398e @lefthandedgoat committed Oct 6, 2012
Showing with 15 additions and 9 deletions.
  1. +13 −9 canopy/canopy.fs
  2. +2 −0 canopy/reporters.fs
View
@@ -10,6 +10,7 @@ open levenshtein
open reporters
type Action = { action : string; url : string }
+type CanopyException(message) = inherit Exception(message)
let mutable actions = [];
let mutable (browser : IWebDriver) = null;
@@ -70,6 +71,7 @@ let private wait timeout f =
try
(f ()) = true
with
+ | :? CanopyException as ce -> failwith ce.Message
| _ -> false
)
) |> ignore
@@ -164,15 +166,17 @@ let private writeToSelect cssSelector text =
let ( << ) (cssSelector : string) (text : string) =
logAction "write"
- let element = find cssSelector elementTimeout
- if element.TagName = "select" then
- writeToSelect cssSelector text
- else
- let readonly = element.GetAttribute("readonly")
- if readonly = "true" then
- failwith (String.Format("element {0} is marked as read only, you can not write to read only elements", cssSelector))
- try element.Clear() with ex -> ex |> ignore
- element.SendKeys(text)
+ wait (elementTimeout + 1.0) (fun _ ->
+ let element = find cssSelector elementTimeout
+ if element.TagName = "select" then
+ writeToSelect cssSelector text
+ else
+ let readonly = element.GetAttribute("readonly")
+ if readonly = "true" then
+ raise (CanopyException((String.Format("element {0} is marked as read only, you can not write to read only elements", cssSelector))))
+ try element.Clear() with ex -> ex |> ignore
+ element.SendKeys(text)
+ true)
let private textOf (element : IWebElement) =
if element.TagName = "input" then
View
@@ -26,6 +26,8 @@ type ConsoleReporter() =
Console.WriteLine("Error: ");
Console.ResetColor()
Console.WriteLine(ex.Message);
+ Console.WriteLine("Stack: ");
+ Console.WriteLine(ex.StackTrace);
member this.describe d = Console.WriteLine d

0 comments on commit 1a3806f

Please sign in to comment.