From 5851c9ee268dabc61efafcd781071249348c6757 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Mon, 31 Mar 2014 21:20:52 -0500 Subject: [PATCH] Add support for firefox aurora for #141 --- canopy/canopy.fs | 46 ++++++++++++++++++++------------------------- canopy/reporters.fs | 4 +++- canopy/types.fs | 1 + 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/canopy/canopy.fs b/canopy/canopy.fs index e561581a..35fcefb1 100644 --- a/canopy/canopy.fs +++ b/canopy/canopy.fs @@ -23,6 +23,7 @@ let mutable wipTest = false let mutable searchedFor : (string * string) list = [] let firefox = Firefox +let aurora = FirefoxWithPath(@"C:\Program Files (x86)\Aurora\firefox.exe") let ie = IE let chrome = Chrome let phantomJS = PhantomJS @@ -54,7 +55,7 @@ let private takeScreenshot directory filename = saveScreenshot directory filename pic pic with - | :? OpenQA.Selenium.UnhandledAlertException as ex-> + | :? UnhandledAlertException as ex-> let pic = takeScreenShotIfAlertUp() saveScreenshot directory filename pic let alert = browser.SwitchTo().Alert() @@ -604,12 +605,12 @@ let pin direction = let private chromeWithUserAgent userAgent = let options = Chrome.ChromeOptions() options.AddArgument("--user-agent=" + userAgent) - new OpenQA.Selenium.Chrome.ChromeDriver(chromeDir, options) :> OpenQA.Selenium.IWebDriver + new Chrome.ChromeDriver(chromeDir, options) :> IWebDriver let private firefoxWithUserAgent (userAgent : string) = let profile = FirefoxProfile() profile.SetPreference("general.useragent.override", userAgent) - new OpenQA.Selenium.Firefox.FirefoxDriver(profile) :> OpenQA.Selenium.IWebDriver + new FirefoxDriver(profile) :> IWebDriver let start b = //for chrome you need to download chromedriver.exe from http://code.google.com/p/chromedriver/wiki/GettingStarted @@ -621,45 +622,38 @@ let start b = browser <- match b with - | IE -> - new OpenQA.Selenium.IE.InternetExplorerDriver(ieDir) :> IWebDriver - | IEWithOptions options -> - new OpenQA.Selenium.IE.InternetExplorerDriver(ieDir, options) :> IWebDriver - | IEWithOptionsAndTimeSpan(options, timeSpan) -> - new OpenQA.Selenium.IE.InternetExplorerDriver(ieDir, options, timeSpan) :> IWebDriver - | Chrome -> - new OpenQA.Selenium.Chrome.ChromeDriver(chromeDir) :> IWebDriver - | ChromeWithOptions options -> - new OpenQA.Selenium.Chrome.ChromeDriver(chromeDir, options) :> IWebDriver + | IE -> new IE.InternetExplorerDriver(ieDir) :> IWebDriver + | IEWithOptions options -> new IE.InternetExplorerDriver(ieDir, options) :> IWebDriver + | IEWithOptionsAndTimeSpan(options, timeSpan) -> new IE.InternetExplorerDriver(ieDir, options, timeSpan) :> IWebDriver + | Chrome -> new Chrome.ChromeDriver(chromeDir) :> IWebDriver + | ChromeWithOptions options -> new Chrome.ChromeDriver(chromeDir, options) :> IWebDriver | ChromeWithUserAgent userAgent -> chromeWithUserAgent userAgent - | ChromeWithOptionsAndTimeSpan(options, timeSpan) -> - new OpenQA.Selenium.Chrome.ChromeDriver(chromeDir, options, timeSpan) :> IWebDriver - | Firefox -> - new OpenQA.Selenium.Firefox.FirefoxDriver() :> IWebDriver - | FirefoxWithProfile profile -> - new OpenQA.Selenium.Firefox.FirefoxDriver(profile) :> IWebDriver + | ChromeWithOptionsAndTimeSpan(options, timeSpan) -> new Chrome.ChromeDriver(chromeDir, options, timeSpan) :> IWebDriver + | Firefox -> new FirefoxDriver() :> IWebDriver + | FirefoxWithProfile profile -> new FirefoxDriver(profile) :> IWebDriver + | FirefoxWithPath path -> new FirefoxDriver(Firefox.FirefoxBinary(path), Firefox.FirefoxProfile()) :> IWebDriver | FirefoxWithUserAgent userAgent -> firefoxWithUserAgent userAgent | PhantomJS -> autoPinBrowserRightOnLaunch <- false - new OpenQA.Selenium.PhantomJS.PhantomJSDriver(phantomJSDir) :> IWebDriver + new PhantomJS.PhantomJSDriver(phantomJSDir) :> IWebDriver | PhantomJSProxyNone -> autoPinBrowserRightOnLaunch <- false - let service = OpenQA.Selenium.PhantomJS.PhantomJSDriverService.CreateDefaultService(canopy.configuration.phantomJSDir) + let service = PhantomJS.PhantomJSDriverService.CreateDefaultService(canopy.configuration.phantomJSDir) service.ProxyType <- "none" - new OpenQA.Selenium.PhantomJS.PhantomJSDriver(service) :> IWebDriver + new PhantomJS.PhantomJSDriver(service) :> IWebDriver if autoPinBrowserRightOnLaunch = true then pin Right browsers <- browsers @ [browser] let switchTo b = browser <- b -let tile (browsers : OpenQA.Selenium.IWebDriver list) = +let tile (browsers : IWebDriver list) = let h = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height let w = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width let count = browsers.Length let maxWidth = w / count - let rec setSize (browsers : OpenQA.Selenium.IWebDriver list) c = + let rec setSize (browsers : IWebDriver list) c = match browsers with | [] -> () | b :: tail -> @@ -670,7 +664,7 @@ let tile (browsers : OpenQA.Selenium.IWebDriver list) = setSize browsers 0 let innerSize() = - let jsBrowser = browser :?> OpenQA.Selenium.IJavaScriptExecutor + let jsBrowser = browser :?> IJavaScriptExecutor let innerWidth = System.Int32.Parse(jsBrowser.ExecuteScript("return window.innerWidth").ToString()) let innerHeight = System.Int32.Parse(jsBrowser.ExecuteScript("return window.innerHeight").ToString()) innerWidth, innerHeight @@ -689,7 +683,7 @@ let rotate() = let quit browser = reporter.quit() match box browser with - | :? OpenQA.Selenium.IWebDriver as b -> b.Quit() + | :? IWebDriver as b -> b.Quit() | _ -> browsers |> List.iter (fun b -> b.Quit()) let currentUrl() = browser.Url diff --git a/canopy/reporters.fs b/canopy/reporters.fs index b99fac4e..c9466fec 100644 --- a/canopy/reporters.fs +++ b/canopy/reporters.fs @@ -154,6 +154,7 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) = | 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 + | FirefoxWithPath path -> new OpenQA.Selenium.Firefox.FirefoxDriver(Firefox.FirefoxBinary(path), Firefox.FirefoxProfile()) :> 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")) @@ -171,7 +172,8 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string) = let mutable canQuit = false let mutable contexts : string list = [] - new() = LiveHtmlReporter(Firefox, @"c:\") + new() = LiveHtmlReporter(Firefox, String.Empty) + new(browser : BrowserStartMode) = LiveHtmlReporter(browser, String.Empty) member this.browser with get () = _browser diff --git a/canopy/types.fs b/canopy/types.fs index 19185f5f..9bd471f6 100644 --- a/canopy/types.fs +++ b/canopy/types.fs @@ -36,6 +36,7 @@ type direction = type BrowserStartMode = | Firefox | FirefoxWithProfile of Firefox.FirefoxProfile + | FirefoxWithPath of string | FirefoxWithUserAgent of string | IE | IEWithOptions of IE.InternetExplorerOptions