From b990af43e3705c2bcb94eaec50ddea8b2bf35ae7 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Thu, 22 Jun 2023 16:08:27 -0700 Subject: [PATCH] sandwich-webdriver: more sensible way to fill in capabilities --- .../src/Test/Sandwich/WebDriver.hs | 9 +++++-- .../WebDriver/Internal/Capabilities.hs | 24 +++++++++---------- .../src/Test/Sandwich/Types/ArgParsing.hs | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/sandwich-webdriver/src/Test/Sandwich/WebDriver.hs b/sandwich-webdriver/src/Test/Sandwich/WebDriver.hs index cef0ff77..5ac2100c 100644 --- a/sandwich-webdriver/src/Test/Sandwich/WebDriver.hs +++ b/sandwich-webdriver/src/Test/Sandwich/WebDriver.hs @@ -132,10 +132,15 @@ getSessions = do -- | Merge the options from the 'CommandLineOptions' into some 'WdOptions'. addCommandLineOptionsToWdOptions :: CommandLineOptions a -> WdOptions -> WdOptions addCommandLineOptionsToWdOptions (CommandLineOptions {optWebdriverOptions=(CommandLineWebdriverOptions {..})}) wdOptions@(WdOptions {..}) = wdOptions { - capabilities = case optFirefox of - Nothing -> capabilities + capabilities = case optBrowserToUse of Just UseFirefox -> firefoxCapabilities firefoxBinaryPath Just UseChrome -> chromeCapabilities chromeBinaryPath + Nothing -> case chromeBinaryPath of + Just p -> chromeCapabilities (Just p) + Nothing -> case firefoxBinaryPath of + Just p -> firefoxCapabilities (Just p) + Nothing -> capabilities + , runMode = case optDisplay of Nothing -> runMode Just Headless -> RunHeadless defaultHeadlessConfig diff --git a/sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/Capabilities.hs b/sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/Capabilities.hs index 7a69611a..d95b9eae 100644 --- a/sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/Capabilities.hs +++ b/sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/Capabilities.hs @@ -32,21 +32,19 @@ loggingPrefs = A.object [("browser", "ALL") -- | Default capabilities for regular Chrome. -- Has the "browser" log level to "ALL" so that tests can collect browser logs. chromeCapabilities :: Maybe FilePath -> Capabilities -chromeCapabilities maybeChromePath = - def {browser=Chrome Nothing maybeChromePath args [] mempty - , additionalCaps=[("loggingPrefs", loggingPrefs) - , ("goog:loggingPrefs", loggingPrefs)] - } - where args = ["--verbose"] +chromeCapabilities maybeChromePath = def { + browser = Chrome Nothing maybeChromePath ["--verbose"] [] mempty + , additionalCaps=[("loggingPrefs", loggingPrefs) + , ("goog:loggingPrefs", loggingPrefs)] + } -- | Default capabilities for headless Chrome. headlessChromeCapabilities :: Maybe FilePath -> Capabilities -headlessChromeCapabilities maybeChromePath = - def {browser=Chrome Nothing maybeChromePath args [] mempty - , additionalCaps=[("loggingPrefs", loggingPrefs) - , ("goog:loggingPrefs", loggingPrefs)] - } - where args = ["--verbose", "--headless"] +headlessChromeCapabilities maybeChromePath = def { + browser = Chrome Nothing maybeChromePath ["--verbose", "--headless"] [] mempty + , additionalCaps=[("loggingPrefs", loggingPrefs) + , ("goog:loggingPrefs", loggingPrefs)] + } -- * Firefox @@ -61,7 +59,7 @@ getDefaultFirefoxProfile downloadDir = do -- | Default capabilities for regular Firefox. firefoxCapabilities :: Maybe FilePath -> Capabilities -firefoxCapabilities maybeFirefoxPath = def { browser=ff } +firefoxCapabilities maybeFirefoxPath = def { browser = ff } where ff = Firefox { ffProfile = Nothing , ffLogPref = LogAll diff --git a/sandwich/src/Test/Sandwich/Types/ArgParsing.hs b/sandwich/src/Test/Sandwich/Types/ArgParsing.hs index 73b9b196..a4fcfbbc 100644 --- a/sandwich/src/Test/Sandwich/Types/ArgParsing.hs +++ b/sandwich/src/Test/Sandwich/Types/ArgParsing.hs @@ -139,7 +139,7 @@ data BrowserToUse = UseChrome | UseFirefox deriving Show data CommandLineWebdriverOptions = CommandLineWebdriverOptions { - optFirefox :: Maybe BrowserToUse + optBrowserToUse :: Maybe BrowserToUse , optDisplay :: Maybe DisplayType , optFluxbox :: Bool , optIndividualVideos :: Bool