Skip to content

Commit

Permalink
Finished csharp wrapper? #327
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Jan 13, 2017
1 parent 6a1c152 commit 27cd764
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 17 deletions.
43 changes: 41 additions & 2 deletions csharptests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,49 @@ static void Main(string[] args)
_.write(lastname, "John");
_.eq("#lastname", "John");
});


_.test("Value 1 listed in #value_list", () =>

This comment has been minimized.

Copy link
@amirrajan

amirrajan Jan 13, 2017

Collaborator

Consider using indexers:

_.test["Value 1 listed in #value_list"] = () =>
{
    _.url(testpage);
    _.startEq("", "");
}
public Action this[string key]
{
    set { /* */ }
}
{
_.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();
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
170 changes: 161 additions & 9 deletions src/canopy/csharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open canopy

type canopy () =

static member browsers = canopy.core.browsers
static member browsers = browsers

static member browser = canopy.types.browser

Expand All @@ -20,34 +20,186 @@ 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()

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<obj>) = waitFor2 message (fun _ -> f.Invoke())

static member waitFor (f : System.Predicate<obj>) = 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
static member count selector value = count selector value

static member onn url = onn url

static member on url = on url

0 comments on commit 27cd764

Please sign in to comment.