From 4115fa489773dac9378acd601400fb21b9471757 Mon Sep 17 00:00:00 2001 From: Kevin Miller Date: Mon, 16 Sep 2013 09:50:02 -0500 Subject: [PATCH] on now checks for equality against full and partial path url Discussed on this gist: https://gist.github.com/KevM/6554377#comment-906673 Note: this is a breaking change with the existing on as it does a compare and was passing for sub partial urls. --- basictests/Program.fs | 23 +++++++++++++++++++++++ canopy/canopy.fs | 9 ++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/basictests/Program.fs b/basictests/Program.fs index 3665da3e..1f6fd2ab 100644 --- a/basictests/Program.fs +++ b/basictests/Program.fs @@ -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") diff --git a/canopy/canopy.fs b/canopy/canopy.fs index dd639365..7be02a7c 100644 --- a/canopy/canopy.fs +++ b/canopy/canopy.fs @@ -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)