From 6781b10a6127373a6b125fb217d70d46858b4260 Mon Sep 17 00:00:00 2001 From: Blair55 Date: Wed, 9 Nov 2016 22:52:54 +0000 Subject: [PATCH] Add 'on exact path' assertion aka 'onn' including docs & test --- docs/content/assertions.fsx | 10 +++++++++- src/canopy/canopy.fs | 8 ++++++-- tests/basictests/Program.fs | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/content/assertions.fsx b/docs/content/assertions.fsx index 5b6f6743..149d78d4 100644 --- a/docs/content/assertions.fsx +++ b/docs/content/assertions.fsx @@ -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 -------- diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index 72eb89b3..fe789920 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -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)) diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index 28073815..e84b2a79 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -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