From 27cd764306eaab749061f37e3422d3ff2ad0a7b6 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Thu, 12 Jan 2017 18:04:19 -0600 Subject: [PATCH] Finished csharp wrapper? #327 --- csharptests/Program.cs | 43 ++++++++++- src/canopy/canopy.fs | 11 ++- src/canopy/csharp.fs | 170 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 207 insertions(+), 17 deletions(-) diff --git a/csharptests/Program.cs b/csharptests/Program.cs index ce75e402..03d10004 100644 --- a/csharptests/Program.cs +++ b/csharptests/Program.cs @@ -79,10 +79,49 @@ static void Main(string[] args) _.write(lastname, "John"); _.eq("#lastname", "John"); }); - + + _.test("Value 1 listed in #value_list", () => + { + _.url(testpage); + _.starEq("#value_list td", "Value 1"); + }); + + _.test("clicking #button sets #button_clicked to button clicked", () => + { + _.url(testpage); + _.eq("#button_clicked", "button not clicked"); + _.click("#button"); + _.eq("#button_clicked", "button clicked"); + }); + + _.test("clicking #radio1 selects it", () => + { + _.url(testpage); + _.click("#button"); + _.selected("#radio1"); + }); + + _.test("clicking #radio1 selects it", () => + { + _.url(testpage); + _.check("#checkbox"); + _.uncheck("#checkbox"); + _.deselected("#checkbox"); + }); + + _.test("clicking #radio1 selects it", () => + { + _.url("https://api.jquery.com/contextmenu/"); + var iframe = _.element("iframe"); + _.browser.SwitchTo().Frame(iframe); + _.notDisplayed(".contextmenu"); + _.rightClick("div:first"); + _.displayed(".contextmenu"); + }); + _.run(); - System.Console.ReadKey(); + Console.ReadKey(); _.quit(); } } diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index b4a95ab6..9c13fd46 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -222,6 +222,10 @@ let waitFor2 message f = (* documented/actions *) let waitFor = waitFor2 "Condition not met in given amount of time. If you want to increase the time, put compareTimeout <- 10.0 anywhere before a test to increase the timeout" +(* documented/actions *) +let waitForElement cssSelector = + waitFor (fun _ -> someElement cssSelector |> Option.isSome) + //find related let rec private findElements cssSelector (searchContext : ISearchContext) : IWebElement list = if optimizeByDisablingCoverageReport = false then searchedFor <- (cssSelector, browser.Url) :: searchedFor @@ -1035,9 +1039,4 @@ let value = addSelector findByValue "value" let skip message = describe <| sprintf "Skipped: %s" message - raise <| CanopySkipTestException() - - -(* documented/actions *) -let waitForElement cssSelector = - waitFor (fun _ -> someElement cssSelector |> Option.isSome) + raise <| CanopySkipTestException() \ No newline at end of file diff --git a/src/canopy/csharp.fs b/src/canopy/csharp.fs index d6a70d7e..8b659d16 100644 --- a/src/canopy/csharp.fs +++ b/src/canopy/csharp.fs @@ -5,7 +5,7 @@ open canopy type canopy () = - static member browsers = canopy.core.browsers + static member browsers = browsers static member browser = canopy.types.browser @@ -20,6 +20,10 @@ type canopy () = static member lastly (f : System.Action) = lastly (fun _ -> f.Invoke()) + static member onPass (f : System.Action) = onPass (fun _ -> f.Invoke()) + + static member onFail (f : System.Action) = onFail (fun _ -> f.Invoke()) + static member test description (f : System.Action) = description &&& fun _ -> f.Invoke() static member wip description (f : System.Action) = description &&&& fun _ -> f.Invoke() @@ -27,27 +31,175 @@ type canopy () = static member skip description (f : System.Action) = description &&! canopy.runner.skipped static member run () = canopy.runner.run () - + static member runFor browsers = canopy.runner.runFor browsers + //core stuff - static member start b = canopy.core.start b + static member start b = start b + + static member pin direction = pin direction + + static member pinToMonitor direction = pinToMonitor direction + + static member switchTo b = switchTo b + + static member switchToTab number = switchToTab number + + static member closeTab number = closeTab number + + static member tile browsers = tile browsers + + static member positionBrowser left top width height = positionBrowser left top width height + + static member resize size = resize size + + static member rotate () = rotate () + + static member url destination = url destination + + static member currentUrl () = currentUrl () + + static member coverage url = coverage url + + static member addFinder finder = addFinder finder - static member url url = canopy.core.url url + static member title () = title () - static member quit () = canopy.core.quit () + static member reload () = reload () + + static member navigate direction = navigate direction + + static member quit () = quit () + + static member screenshot directory filename = screenshot directory filename + + static member js script = js script + + static member sleep seconds = sleep seconds + + static member puts text = puts text + + static member highlight cssSelector = highlight cssSelector + + static member describe text = describe text + + static member waitFor2 message (f : System.Predicate) = waitFor2 message (fun _ -> f.Invoke()) + + static member waitFor (f : System.Predicate) = waitFor (fun _ -> f.Invoke()) + + static member waitForElement selector = waitForElement selector //element stuff - static member element selector = canopy.core.element selector + static member unreliableElement selector = unreliableElement selector + + static member unreliableElements selector = unreliableElements selector + + static member element selector = element selector + + static member elements selector = elements selector + + static member elementWithin selector element = elementWithin selector element + + static member elementsWithin selector element = elementsWithin selector element + + static member elementWithText selector regex = elementWithText selector regex + + static member elementsWithText selector regex = elementsWithText selector regex - static member read selector = canopy.core.read selector + static member parent element = parent element - static member clear selector = canopy.core.clear selector + static member unreliableElementsWithin selector element = unreliableElementsWithin selector element + + static member someElement selector = + match someElement selector with + | None -> null + | Some element -> element + + static member someElementWithin selector element = + match someElementWithin selector element with + | None -> null + | Some element -> element + + static member someParent element = + match someParent element with + | None -> null + | Some element -> element + + static member nth index selector = nth index selector + + static member first selector = first selector + + static member last index selector = last selector + + static member read selector = read selector + + static member clear selector = clear selector static member write selector value = selector << value + static member click selector = click selector + + static member doubleClick selector = doubleClick selector + + static member ctrlClick selector = ctrlClick selector + + static member rightClick selector = rightClick selector + + static member check selector = check selector + + static member uncheck selector = uncheck selector + + static member hover selector = hover selector + + static member drag selector = drag selector + + static member press key = press key + + static member alert () = alert () + + static member acceptAlert () = acceptAlert () + + static member dismissAlert () = dismissAlert () + + static member fastTextFromCSS selector = fastTextFromCSS selector + //assertions static member eq selector value = selector == value + static member notEq selector value = selector != value + + static member starEq selector value = selector *= value + + static member starNotEq selector value = selector *!= value + + static member starEqRegex selector value = selector *~ value + + static member eqRegex selector value = selector =~ value + + static member notEqRegex selector value = selector !=~ value + + static member contains value1 value2 = contains value1 value2 + + static member notContains value1 value2 = notContains value1 value2 + + static member selected selector = selected value + + static member deselected selector = deselected value + + static member displayed selector = displayed value + + static member notDisplayed selector = notDisplayed value + + static member enabled selector = enabled value + + static member disabled selector = disabled value + + static member fadedIn selector = fadedIn selector + static member equality value1 value2 = value1 === value2 - static member count selector value = count selector value \ No newline at end of file + static member count selector value = count selector value + + static member onn url = onn url + + static member on url = on url \ No newline at end of file