Skip to content

Commit

Permalink
added ability to hide command prompt window (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Maksymets authored and lefthandedgoat committed Mar 11, 2017
1 parent 4247079 commit 1f75bc3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 23 deletions.
8 changes: 8 additions & 0 deletions docs/content/configuration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ edgeDir
*)
edgeDir <- "C:\\"

(**
hideCommandPromptWindow
-----------
* Hide drivers command prompt window
* Defaults to false
*)
hideCommandPromptWindow <- true

(**
elementTimeout
-------------------
Expand Down
92 changes: 69 additions & 23 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -775,15 +775,48 @@ let pinToMonitor n =
else
raise(CanopyException(sprintf "Monitor %d is not detected" n))

let private chromeWithUserAgent userAgent =
let options = Chrome.ChromeOptions()
options.AddArgument("--user-agent=" + userAgent)
new Chrome.ChromeDriver(chromeDir, options) :> IWebDriver
let private firefoxDriverService =
let service = Firefox.FirefoxDriverService.CreateDefaultService()
service.HideCommandPromptWindow <- hideCommandPromptWindow
service

let private firefoxWithUserAgent (userAgent : string) =
let profile = FirefoxProfile()
profile.SetPreference("general.useragent.override", userAgent)
new FirefoxDriver(profile) :> IWebDriver
let options = Firefox.FirefoxOptions();
options.Profile <- profile
new FirefoxDriver(firefoxDriverService, options, TimeSpan.FromSeconds(elementTimeout)) :> IWebDriver

let private chromeDriverService =
let service = Chrome.ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow <- hideCommandPromptWindow;
service

let private chromeWithUserAgent userAgent =
let options = Chrome.ChromeOptions()
options.BinaryLocation <- chromeDir
options.AddArgument("--user-agent=" + userAgent)
new Chrome.ChromeDriver(chromeDriverService, options) :> IWebDriver

let private phantomJsDriverService =
let service = PhantomJS.PhantomJSDriverService.CreateDefaultService(phantomJSDir)
service.HideCommandPromptWindow <- hideCommandPromptWindow
service

let private ieDriverService =
let service = IE.InternetExplorerDriverService.CreateDefaultService(ieDir)
service.HideCommandPromptWindow <- hideCommandPromptWindow
service

let private edgeDriverService =
let service = Edge.EdgeDriverService.CreateDefaultService(edgeDir)
service.HideCommandPromptWindow <- hideCommandPromptWindow
service

let private safariDriverService =
let service = Safari.SafariDriverService.CreateDefaultService()
service.HideCommandPromptWindow <- hideCommandPromptWindow
service

(* documented/actions *)
let start b =
Expand All @@ -797,46 +830,59 @@ let start b =

browser <-
match b with
| IE -> new IE.InternetExplorerDriver(ieDir) :> IWebDriver
| IEWithOptions options -> new IE.InternetExplorerDriver(ieDir, options) :> IWebDriver
| IEWithOptionsAndTimeSpan(options, timeSpan) -> new IE.InternetExplorerDriver(ieDir, options, timeSpan) :> IWebDriver
| EdgeBETA -> new Edge.EdgeDriver(edgeDir) :> IWebDriver
| IE -> new IE.InternetExplorerDriver(ieDriverService) :> IWebDriver
| IEWithOptions options -> new IE.InternetExplorerDriver(ieDriverService, options) :> IWebDriver
| IEWithOptionsAndTimeSpan(options, timeSpan) -> new IE.InternetExplorerDriver(ieDriverService, options, timeSpan) :> IWebDriver
| EdgeBETA -> new Edge.EdgeDriver(edgeDriverService) :> IWebDriver
| Chrome ->
let options = Chrome.ChromeOptions()
options.BinaryLocation <- chromeDir
options.AddArguments("--disable-extensions")
options.AddArgument("test-type") //https://code.google.com/p/chromedriver/issues/detail?id=799
new Chrome.ChromeDriver(chromeDir, options) :> IWebDriver
| ChromeWithOptions options -> new Chrome.ChromeDriver(chromeDir, options) :> IWebDriver
| ChromeWithUserAgent userAgent -> chromeWithUserAgent userAgent
| ChromeWithOptionsAndTimeSpan(options, timeSpan) -> new Chrome.ChromeDriver(chromeDir, options, timeSpan) :> IWebDriver
new Chrome.ChromeDriver(chromeDriverService, options) :> IWebDriver
| ChromeWithOptions options ->
options.BinaryLocation <- chromeDir
new Chrome.ChromeDriver(chromeDriverService, options) :> IWebDriver
| ChromeWithUserAgent userAgent ->
chromeWithUserAgent userAgent
| ChromeWithOptionsAndTimeSpan(options, timeSpan) ->
options.BinaryLocation <- chromeDir
new Chrome.ChromeDriver(chromeDriverService, options, timeSpan) :> IWebDriver
| Chromium ->
let options = Chrome.ChromeOptions()
options.AddArguments("--disable-extensions")
options.AddArgument("test-type") //https://code.google.com/p/chromedriver/issues/detail?id=799
new Chrome.ChromeDriver(chromiumDir, options) :> IWebDriver
| ChromiumWithOptions options -> new Chrome.ChromeDriver(chromiumDir, options) :> IWebDriver
| Firefox -> new FirefoxDriver() :> IWebDriver
| FirefoxWithProfile profile -> new FirefoxDriver(profile) :> IWebDriver
options.BinaryLocation <- chromiumDir
new Chrome.ChromeDriver(chromeDriverService, options) :> IWebDriver
| ChromiumWithOptions options ->
options.BinaryLocation <- chromiumDir
new Chrome.ChromeDriver(chromeDriverService, options) :> IWebDriver
| Firefox ->new FirefoxDriver(firefoxDriverService) :> IWebDriver
| FirefoxWithProfile profile ->
let options = new Firefox.FirefoxOptions();
options.Profile <- profile
new FirefoxDriver(firefoxDriverService, options, TimeSpan.FromSeconds(elementTimeout)) :> IWebDriver
| FirefoxWithPath path ->
let options = new Firefox.FirefoxOptions()
options.BrowserExecutableLocation <- path
new FirefoxDriver(options) :> IWebDriver
new FirefoxDriver(firefoxDriverService, options, TimeSpan.FromSeconds(elementTimeout)) :> IWebDriver
| FirefoxWithUserAgent userAgent -> firefoxWithUserAgent userAgent
| FirefoxWithPathAndTimeSpan(path, timespan) ->
let options = new Firefox.FirefoxOptions()
options.BrowserExecutableLocation <- path
new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), options, timespan) :> IWebDriver
new FirefoxDriver(firefoxDriverService, options, timespan) :> IWebDriver
| FirefoxWithProfileAndTimeSpan(profile, timespan) ->
let options = new Firefox.FirefoxOptions()
options.Profile <- profile
new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), options, timespan) :> IWebDriver
| Safari ->new Safari.SafariDriver() :> IWebDriver
new FirefoxDriver(firefoxDriverService, options, timespan) :> IWebDriver
| Safari ->
new Safari.SafariDriver(safariDriverService) :> IWebDriver
| PhantomJS ->
autoPinBrowserRightOnLaunch <- false
new PhantomJS.PhantomJSDriver(phantomJSDir) :> IWebDriver
new PhantomJS.PhantomJSDriver(phantomJsDriverService) :> IWebDriver
| PhantomJSProxyNone ->
autoPinBrowserRightOnLaunch <- false
let service = PhantomJS.PhantomJSDriverService.CreateDefaultService(canopy.configuration.phantomJSDir)
let service = phantomJsDriverService
service.ProxyType <- "none"
new PhantomJS.PhantomJSDriver(service) :> IWebDriver
| Remote(url, capabilities) -> new Remote.RemoteWebDriver(new Uri(url), capabilities) :> IWebDriver
Expand Down
2 changes: 2 additions & 0 deletions src/canopy/configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ let mutable phantomJSDir = folderByOSType
let mutable safariDir = folderByOSType
(* documented/configuration *)
let mutable edgeDir = @"C:\Program Files (x86)\Microsoft Web Driver\"
(* documented/configuration *)
let mutable hideCommandPromptWindow = false

(* documented/configuration *)
let mutable elementTimeout = 10.0
Expand Down

0 comments on commit 1f75bc3

Please sign in to comment.