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

Make on (url) checks for equality against full and partial (sans Query string) urls #107

Merged
merged 1 commit into from
Sep 16, 2013
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
23 changes: 23 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ test (fun _ ->
failsWith "More than one element was selected when only one was expected for selector: .lastName"
someElement ".lastName" |> ignore)

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

"Navigating to a url with query string should be on url with and without a query string" &&& fun _ ->
let testpageWithQueryString = testpage + "?param1=weeeee"
let subtestpage = "http://lefthandedgoat.github.io/canopy"
url testpageWithQueryString
on testpageWithQueryString //with query string
on testpage //without query string

"Should not be on partial url" &&& fun _ ->
url testpage
let partialUrl = "http://lefthandedgoat.github.io/canopy"
failsWith ("on check failed, expected expression '" + partialUrl + "' got " + testpage)
on partialUrl

"Should not be on child url" &&& fun _ ->
url testpage
let childUrl = testpage + "notatthspath/"
failsWith ("on check failed, expected expression '" + childUrl + "' got " + testpage)
on childUrl

context "reddit tests"
once (fun _ -> Console.WriteLine "once: reddit tests")
before (fun _ -> Console.WriteLine "before: reddit tests")
Expand Down
9 changes: 6 additions & 3 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,14 @@ let quit browser =

let currentUrl() = browser.Url

let on (u: string) =
let on (u: string) =
let urlSansQueryString u =
let uri = new System.Uri(u)
uri.GetLeftPart(System.UriPartial.Path)
try
wait pageTimeout (fun _ -> (browser.Url.Contains(u)))
wait pageTimeout (fun _ -> if browser.Url = u then true else urlSansQueryString(browser.Url) = u)
with
| ex -> raise (CanopyOnException(sprintf "on check failed, expected %s got %s" u browser.Url));
| ex -> if browser.Url.Contains(u) = false then raise (CanopyOnException(sprintf "on check failed, expected expression '%s' got %s" u browser.Url));

let ( !^ ) (u : string) = browser.Navigate().GoToUrl(u)

Expand Down