Skip to content

Commit

Permalink
sandwich-webdriver: more sensible way to fill in capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Jun 22, 2023
1 parent aa9fa2f commit b990af4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
9 changes: 7 additions & 2 deletions sandwich-webdriver/src/Test/Sandwich/WebDriver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sandwich/src/Test/Sandwich/Types/ArgParsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b990af4

Please sign in to comment.