Skip to content

Commit

Permalink
Add 'on exact path' assertion aka 'onn'
Browse files Browse the repository at this point in the history
including docs & test
  • Loading branch information
Blair55 committed Nov 9, 2016
1 parent 3b19870 commit 6781b10
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/content/assertions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ Assert that one of many element `regex` matches a value.
(**
on
--
Assert that the browser is currently on a url (uses `String.Contains`).
Assert that the browser is currently on a url. Falls back to using `String.Contains` after page timeout.
*)
url "https://duckduckgo.com/?q=canopy+f%23"
on "https://duckduckgo.com/?q"

(**
onn
--
Same as `on` but does not fall back to using `String.Contains`.
*)
url "https://duckduckgo.com/about"
onn "https://duckduckgo.com/about"

(**
selected
--------
Expand Down
8 changes: 6 additions & 2 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -909,15 +909,19 @@ let quit browser =
let currentUrl() = browser.Url

(* documented/assertions *)
let on (u: string) =
let onn (u: string) =
let urlPath (u : string) =
let url = match u with
| x when x.StartsWith("http") -> u //leave absolute urls alone
| _ -> "http://host/" + u.Trim('/') //ensure valid uri
let uriBuilder = new System.UriBuilder(url)
uriBuilder.Path.TrimEnd('/') //get the path part removing trailing slashes
wait pageTimeout (fun _ -> if browser.Url = u then true else urlPath(browser.Url) = urlPath(u))

(* documented/assertions *)
let on (u: string) =
try
wait pageTimeout (fun _ -> if browser.Url = u then true else urlPath(browser.Url) = urlPath(u))
onn u
with
| ex -> if browser.Url.Contains(u) = false then raise (CanopyOnException(sprintf "on check failed, expected expression '%s' got %s" u browser.Url))

Expand Down
4 changes: 4 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ test (fun _ ->
url testpage
on testpage

"Navigating to a url should be on exact url" &&& fun _ ->
url testpage
onn testpage

"Navigating to a url with query string should be on url with and without a query string" &&& fun _ ->
let testpageWithQueryString = testpage + "?param1=weeeee"
url testpageWithQueryString
Expand Down

0 comments on commit 6781b10

Please sign in to comment.