Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'on exact path' assertion aka 'onn' #304

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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