Skip to content

Commit

Permalink
Made LiveHtmlReporter browser type configurable #126
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Jan 23, 2014
1 parent 368d43c commit d6d751b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 88 deletions.
2 changes: 2 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open canopy
open runner
open configuration
open reporters
open types

start chrome
let mainBrowser = browser
Expand All @@ -13,6 +14,7 @@ compareTimeout <- 3.0
pageTimeout <- 3.0
runFailedContextsFirst <- true
reporter <- new LiveHtmlReporter() :> IReporter
//reporter <- new LiveHtmlReporter(Chrome, configuration.chromeDir) :> IReporter

failFast := true

Expand Down
45 changes: 1 addition & 44 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,13 @@ open System
open configuration
open levenshtein
open reporters

type CanopyException(message) = inherit Exception(message)
type CanopyReadOnlyException(message) = inherit CanopyException(message)
type CanopyOptionNotFoundException(message) = inherit CanopyException(message)
type CanopySelectionFailedExeception(message) = inherit CanopyException(message)
type CanopyDeselectionFailedException(message) = inherit CanopyException(message)
type CanopyWaitForException(message) = inherit CanopyException(message)
type CanopyElementNotFoundException(message) = inherit CanopyException(message)
type CanopyMoreThanOneElementFoundException(message) = inherit CanopyException(message)
type CanopyEqualityFailedException(message) = inherit CanopyException(message)
type CanopyNotEqualsFailedException(message) = inherit CanopyException(message)
type CanopyValueNotInListException(message) = inherit CanopyException(message)
type CanopyValueInListException(message) = inherit CanopyException(message)
type CanopyContainsFailedException(message) = inherit CanopyException(message)
type CanopyCountException(message) = inherit CanopyException(message)
type CanopyDisplayedFailedException(message) = inherit CanopyException(message)
type CanopyNotDisplayedFailedException(message) = inherit CanopyException(message)
type CanopyEnabledFailedException(message) = inherit CanopyException(message)
type CanopyDisabledFailedException(message) = inherit CanopyException(message)
type CanopyNotStringOrElementException(message) = inherit CanopyException(message)
type CanopyOnException(message) = inherit CanopyException(message)
type CanopyCheckFailedException(message) = inherit CanopyException(message)
type CanopyUncheckFailedException(message) = inherit CanopyException(message)
open types

let mutable (browser : IWebDriver) = null
let mutable (failureMessage : string) = null
let mutable wipTest = false
let mutable searchedFor : (string * string) list = []

//directions
type direction =
| Left
| Right
| FullScreen

//browser
type BrowserStartMode =
| Firefox
| FirefoxWithProfile of Firefox.FirefoxProfile
| FirefoxWithUserAgent of string
| IE
| IEWithOptions of IE.InternetExplorerOptions
| IEWithOptionsAndTimeSpan of IE.InternetExplorerOptions * TimeSpan
| Chrome
| ChromeWithOptions of Chrome.ChromeOptions
| ChromeWithOptionsAndTimeSpan of Chrome.ChromeOptions * TimeSpan
| ChromeWithUserAgent of string
| PhantomJS
| PhantomJSProxyNone

let firefox = Firefox
let ie = IE
let chrome = Chrome
Expand Down
1 change: 1 addition & 0 deletions canopy/canopy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="..\AssemblyInfo.fs">
<Link>AssemblyInfo.fs</Link>
</Compile>
<Compile Include="types.fs" />
<Compile Include="reporters.fs" />
<Compile Include="configuration.fs" />
<Compile Include="levenshtein.fs" />
Expand Down
23 changes: 20 additions & 3 deletions canopy/reporters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open OpenQA.Selenium
open types

type IReporter =
abstract member testStart : string -> unit
Expand Down Expand Up @@ -139,10 +140,24 @@ type TeamCityReporter() =

member this.skip () = ()

type LiveHtmlReporter() =
type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) =
let consoleReporter : IReporter = new ConsoleReporter() :> IReporter

let _browser = new OpenQA.Selenium.Firefox.FirefoxDriver() :> IWebDriver

let _browser =
//copy pasta!
match browser with
| IE -> new OpenQA.Selenium.IE.InternetExplorerDriver(driverPath) :> IWebDriver
| IEWithOptions options ->new OpenQA.Selenium.IE.InternetExplorerDriver(driverPath, options) :> IWebDriver
| IEWithOptionsAndTimeSpan(options, timeSpan) -> new OpenQA.Selenium.IE.InternetExplorerDriver(driverPath, options, timeSpan) :> IWebDriver
| Chrome -> new OpenQA.Selenium.Chrome.ChromeDriver(driverPath) :> IWebDriver
| ChromeWithOptions options -> new OpenQA.Selenium.Chrome.ChromeDriver(driverPath, options) :> IWebDriver
| ChromeWithOptionsAndTimeSpan(options, timeSpan) -> new OpenQA.Selenium.Chrome.ChromeDriver(driverPath, options, timeSpan) :> IWebDriver
| Firefox -> new OpenQA.Selenium.Firefox.FirefoxDriver() :> IWebDriver
| FirefoxWithProfile profile -> new OpenQA.Selenium.Firefox.FirefoxDriver(profile) :> IWebDriver
| ChromeWithUserAgent userAgent -> raise(System.Exception("Sorry ChromeWithUserAgent can't be used for LiveHtmlReporter"))
| FirefoxWithUserAgent userAgent -> raise(System.Exception("Sorry FirefoxWithUserAgent can't be used for LiveHtmlReporter"))
| PhantomJS | PhantomJSProxyNone -> raise(System.Exception("Sorry PhantomJS can't be used for LiveHtmlReporter"))

let pin () =
let h = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
let w = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
Expand All @@ -156,6 +171,8 @@ type LiveHtmlReporter() =
let mutable canQuit = false
let mutable contexts : string list = []

new() = LiveHtmlReporter(Firefox, @"c:\")

member this.browser
with get () = _browser

Expand Down
42 changes: 1 addition & 41 deletions canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,13 @@ open System
open configuration
open canopy
open reporters
open types

let rec private last = function
| hd :: [] -> hd
| hd :: tl -> last tl
| _ -> failwith "Empty list."

type Test (description: string, func : (unit -> unit), number : int) =
member x.Description = description
member x.Func = func
member x.Number = number

type suite () = class
let mutable context : string = null
let mutable once = fun () -> ()
let mutable before = fun () -> ()
let mutable after = fun () -> ()
let mutable lastly = fun () -> ()
let mutable tests : Test list = []
let mutable wips : Test list = []
let mutable manys : Test list = []

member x.Context
with get() = context
and set(value) = context <- value
member x.Once
with get() = once
and set(value) = once <- value
member x.Before
with get() = before
and set(value) = before <- value
member x.After
with get() = after
and set(value) = after <- value
member x.Lastly
with get() = lastly
and set(value) = lastly <- value
member x.Tests
with get() = tests
and set(value) = tests <- value
member x.Wips
with get() = wips
and set(value) = wips <- value
member x.Manys
with get() = manys
and set(value) = manys <- value
end

let mutable suites = [new suite()]
let mutable todo = fun () -> ()
let mutable skipped = fun () -> ()
Expand Down
89 changes: 89 additions & 0 deletions canopy/types.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module canopy.types

open System
open OpenQA.Selenium

type CanopyException(message) = inherit Exception(message)
type CanopyReadOnlyException(message) = inherit CanopyException(message)
type CanopyOptionNotFoundException(message) = inherit CanopyException(message)
type CanopySelectionFailedExeception(message) = inherit CanopyException(message)
type CanopyDeselectionFailedException(message) = inherit CanopyException(message)
type CanopyWaitForException(message) = inherit CanopyException(message)
type CanopyElementNotFoundException(message) = inherit CanopyException(message)
type CanopyMoreThanOneElementFoundException(message) = inherit CanopyException(message)
type CanopyEqualityFailedException(message) = inherit CanopyException(message)
type CanopyNotEqualsFailedException(message) = inherit CanopyException(message)
type CanopyValueNotInListException(message) = inherit CanopyException(message)
type CanopyValueInListException(message) = inherit CanopyException(message)
type CanopyContainsFailedException(message) = inherit CanopyException(message)
type CanopyCountException(message) = inherit CanopyException(message)
type CanopyDisplayedFailedException(message) = inherit CanopyException(message)
type CanopyNotDisplayedFailedException(message) = inherit CanopyException(message)
type CanopyEnabledFailedException(message) = inherit CanopyException(message)
type CanopyDisabledFailedException(message) = inherit CanopyException(message)
type CanopyNotStringOrElementException(message) = inherit CanopyException(message)
type CanopyOnException(message) = inherit CanopyException(message)
type CanopyCheckFailedException(message) = inherit CanopyException(message)
type CanopyUncheckFailedException(message) = inherit CanopyException(message)

//directions
type direction =
| Left
| Right
| FullScreen

//browser
type BrowserStartMode =
| Firefox
| FirefoxWithProfile of Firefox.FirefoxProfile
| FirefoxWithUserAgent of string
| IE
| IEWithOptions of IE.InternetExplorerOptions
| IEWithOptionsAndTimeSpan of IE.InternetExplorerOptions * TimeSpan
| Chrome
| ChromeWithOptions of Chrome.ChromeOptions
| ChromeWithOptionsAndTimeSpan of Chrome.ChromeOptions * TimeSpan
| ChromeWithUserAgent of string
| PhantomJS
| PhantomJSProxyNone

type Test (description: string, func : (unit -> unit), number : int) =
member x.Description = description
member x.Func = func
member x.Number = number

type suite () = class
let mutable context : string = null
let mutable once = fun () -> ()
let mutable before = fun () -> ()
let mutable after = fun () -> ()
let mutable lastly = fun () -> ()
let mutable tests : Test list = []
let mutable wips : Test list = []
let mutable manys : Test list = []

member x.Context
with get() = context
and set(value) = context <- value
member x.Once
with get() = once
and set(value) = once <- value
member x.Before
with get() = before
and set(value) = before <- value
member x.After
with get() = after
and set(value) = after <- value
member x.Lastly
with get() = lastly
and set(value) = lastly <- value
member x.Tests
with get() = tests
and set(value) = tests <- value
member x.Wips
with get() = wips
and set(value) = wips <- value
member x.Manys
with get() = manys
and set(value) = manys <- value
end

0 comments on commit d6d751b

Please sign in to comment.