From 3af60d9f814eb407b8d3cd069eddab62a2f49dd9 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Thu, 12 Jan 2017 14:56:11 -0600 Subject: [PATCH] CSharp friendly wrapper part 1 #327 --- canopy.sln | 15 ++++++ csharptests/App.config | 6 +++ csharptests/Program.cs | 49 +++++++++++++++++++ csharptests/Properties/AssemblyInfo.cs | 36 ++++++++++++++ csharptests/csharptests.csproj | 66 ++++++++++++++++++++++++++ src/canopy/canopy.fsproj | 1 + src/canopy/csharp.fs | 42 ++++++++++++++++ src/canopy/reporters.fs | 3 +- 8 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 csharptests/App.config create mode 100644 csharptests/Program.cs create mode 100644 csharptests/Properties/AssemblyInfo.cs create mode 100644 csharptests/csharptests.csproj create mode 100644 src/canopy/csharp.fs diff --git a/canopy.sln b/canopy.sln index fa0ad15d..4b6c0b0a 100644 --- a/canopy.sln +++ b/canopy.sln @@ -44,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{3C3590B5 docs\tools\templates\template.cshtml = docs\tools\templates\template.cshtml EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharptests", "csharptests\csharptests.csproj", "{8FD011AE-ACEC-4B55-810B-736DAE312D32}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -84,6 +86,18 @@ Global {9DE5614C-8D7F-4BBD-A6A0-24AABD76796C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {9DE5614C-8D7F-4BBD-A6A0-24AABD76796C}.Release|Mixed Platforms.Build.0 = Release|Any CPU {9DE5614C-8D7F-4BBD-A6A0-24AABD76796C}.Release|x86.ActiveCfg = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|x86.ActiveCfg = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Debug|x86.Build.0 = Debug|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|Any CPU.Build.0 = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|x86.ActiveCfg = Release|Any CPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -92,5 +106,6 @@ Global {D4610DE2-BFD2-491D-AD72-BBBB206E11C7} = {0391DED2-DF91-4A61-959E-EEA250356DA0} {A94D736A-68EB-4D7B-A761-DF6B1EEAE24C} = {12E9007C-8265-43D8-86B0-C9182921A9E5} {3C3590B5-4CC8-49D1-A2CE-4FDFA73ADB53} = {12E9007C-8265-43D8-86B0-C9182921A9E5} + {8FD011AE-ACEC-4B55-810B-736DAE312D32} = {0391DED2-DF91-4A61-959E-EEA250356DA0} EndGlobalSection EndGlobal diff --git a/csharptests/App.config b/csharptests/App.config new file mode 100644 index 00000000..88fa4027 --- /dev/null +++ b/csharptests/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/csharptests/Program.cs b/csharptests/Program.cs new file mode 100644 index 00000000..af4ba3bb --- /dev/null +++ b/csharptests/Program.cs @@ -0,0 +1,49 @@ +using System; +using canopy; +using _ = canopy.csharp.canopy; + +namespace csharptests +{ + class Program + { + static void Main(string[] args) + { + configuration.elementTimeout = 3.0; + configuration.compareTimeout = 3.0; + configuration.pageTimeout = 3.0; + configuration.reporter = new reporters.LiveHtmlReporter(types.BrowserStartMode.Chrome, configuration.chromeDir); + + var testpage = "http://lefthandedgoat.github.io/canopy/testpages/"; + + _.start(types.BrowserStartMode.Chrome); + + _.context("context1"); + _.once(() => Console.WriteLine("once")); + _.before(() => Console.WriteLine("before")); + _.after(() => Console.WriteLine("after")); + _.lastly(() => Console.WriteLine("lastly")); + + _.skip("intentionally skipped shows blue in LiveHtmlReport", () => + { + _.url("http://www.skipped.com"); + }); + + _.test("Apostrophes don't break anything", () => + { + _.url(testpage); + _.count("I've got an apostrophe", 1); + }); + + _.test("#firstName should have John (using == infix operator)", () => + { + _.url(testpage); + _.equals("#firstName", "John"); + }); + + _.run(); + + System.Console.ReadKey(); + _.quit(); + } + } +} diff --git a/csharptests/Properties/AssemblyInfo.cs b/csharptests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e9f24ddb --- /dev/null +++ b/csharptests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharptests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharptests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8fd011ae-acec-4b55-810b-736dae312d32")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/csharptests/csharptests.csproj b/csharptests/csharptests.csproj new file mode 100644 index 00000000..efadd808 --- /dev/null +++ b/csharptests/csharptests.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {8FD011AE-ACEC-4B55-810B-736DAE312D32} + Exe + Properties + csharptests + csharptests + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {63135cf6-70a9-4382-851d-4b679ee0cbf8} + canopy + + + + + \ No newline at end of file diff --git a/src/canopy/canopy.fsproj b/src/canopy/canopy.fsproj index 19c96abb..1e9d3c63 100644 --- a/src/canopy/canopy.fsproj +++ b/src/canopy/canopy.fsproj @@ -62,6 +62,7 @@ + diff --git a/src/canopy/csharp.fs b/src/canopy/csharp.fs new file mode 100644 index 00000000..e1f8e645 --- /dev/null +++ b/src/canopy/csharp.fs @@ -0,0 +1,42 @@ +namespace canopy.csharp + +open canopy.runner +open canopy + +type canopy () = + + static member browsers = canopy.core.browsers + + static member browser = canopy.types.browser + + //runner stuff + static member context description = context description + + static member once (f : System.Action) = once (fun _ -> f.Invoke()) + + static member before (f : System.Action) = before (fun _ -> f.Invoke()) + + static member after (f : System.Action) = after (fun _ -> f.Invoke()) + + static member lastly (f : System.Action) = lastly (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 () + + + //core stuff + static member start b = canopy.core.start b + + static member url url = canopy.core.url url + + static member quit () = canopy.core.quit () + + //assertions + static member equals selector value = selector == value + + static member count selector value = count selector value \ No newline at end of file diff --git a/src/canopy/reporters.fs b/src/canopy/reporters.fs index 6e395ff9..dac8c561 100644 --- a/src/canopy/reporters.fs +++ b/src/canopy/reporters.fs @@ -181,7 +181,7 @@ type TeamCityReporter(?logImagesToConsole: bool) = member this.setEnvironment env = () -type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string, ?pinBrowserRight0: bool) = +type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string, ?pinBrowserRight0: bool) = let pinBrowserRight = defaultArg pinBrowserRight0 true let consoleReporter : IReporter = new ConsoleReporter() :> IReporter @@ -242,6 +242,7 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string, ?pinBrows new() = LiveHtmlReporter(Firefox, String.Empty) new(browser : BrowserStartMode) = LiveHtmlReporter(browser, String.Empty) + new (browser : BrowserStartMode, driverPath : string) = LiveHtmlReporter(browser, driverPath, true) member this.browser with get () = _browser