Skip to content

Commit

Permalink
Add support for firefox aurora for #141
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Apr 1, 2014
1 parent 754dc27 commit 5851c9e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
46 changes: 20 additions & 26 deletions canopy/canopy.fs
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion canopy/reporters.fs
Expand Up @@ -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"))
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions canopy/types.fs
Expand Up @@ -36,6 +36,7 @@ type direction =
type BrowserStartMode =
| Firefox
| FirefoxWithProfile of Firefox.FirefoxProfile
| FirefoxWithPath of string
| FirefoxWithUserAgent of string
| IE
| IEWithOptions of IE.InternetExplorerOptions
Expand Down

0 comments on commit 5851c9e

Please sign in to comment.