packages feed

sandwich-webdriver 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+33/−12 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Test.Sandwich.WebDriver.Internal.StartWebDriver: configureHeadlessCapabilities :: RunMode -> Capabilities -> Capabilities
+ Test.Sandwich.WebDriver.Internal.StartWebDriver: configureHeadlessCapabilities :: Constraints m => WdOptions -> RunMode -> Capabilities -> m Capabilities
- Test.Sandwich.WebDriver.Internal.StartWebDriver: startWebDriver' :: (MonadIO m, MonadLogger m, MonadBaseControl IO m) => WdOptions -> Text -> FilePath -> [Char] -> [Char] -> [String] -> Maybe XvfbSession -> Maybe [(String, String)] -> m WebDriver
+ Test.Sandwich.WebDriver.Internal.StartWebDriver: startWebDriver' :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadMask m) => WdOptions -> Text -> FilePath -> [Char] -> [Char] -> [String] -> Maybe XvfbSession -> Maybe [(String, String)] -> m WebDriver

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog for sandwich-webdriver +# Unreleased++# 0.2.1.0++* Pass `--headless=new` instead of `--headless` for Chrome >= 110, to address https://www.selenium.dev/blog/2023/headless-is-going-away/.+ # 0.2.0.0  * Fix the obtainChromeDriver function now that the zip files contain multiple files. This added a MonadMask constraint to the function so it's a major version bump.
sandwich-webdriver.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           sandwich-webdriver-version:        0.2.0.0+version:        0.2.1.0 synopsis:       Sandwich integration with Selenium WebDriver description:    Please see the <https://codedownio.github.io/sandwich/docs/extensions/sandwich-webdriver documentation>. category:       Testing
src/Test/Sandwich/WebDriver/Internal/StartWebDriver.hs view
@@ -15,7 +15,6 @@  module Test.Sandwich.WebDriver.Internal.StartWebDriver where - import Control.Concurrent import Control.Exception import Control.Monad@@ -42,6 +41,7 @@ import System.Process import Test.Sandwich import Test.Sandwich.WebDriver.Internal.Binaries+import Test.Sandwich.WebDriver.Internal.Binaries.Util (detectChromeVersion) import Test.Sandwich.WebDriver.Internal.Ports import Test.Sandwich.WebDriver.Internal.Types import Test.Sandwich.WebDriver.Internal.Util@@ -152,16 +152,17 @@   -- Retry every 60ms, for up to 60s before admitting defeat   let policy = constantDelay 60000 <> limitRetries 1000   success <- retrying policy (\_retryStatus result -> return (not result)) $ const $-    (liftIO $ T.readFile seleniumErrPath) >>= \case+    liftIO (T.readFile seleniumErrPath) >>= \case       t | readyMessage `T.isInfixOf` t -> return True-      _ -> (liftIO $ T.readFile seleniumOutPath) >>= \case+      _ -> liftIO (T.readFile seleniumOutPath) >>= \case         t | readyMessage `T.isInfixOf` t -> return True         _ -> return False   unless success $ liftIO $ do     interruptProcessGroupOf p >> waitForProcess p     error [i|Selenium server failed to start after 60 seconds|] -  capabilities <- configureDownloadCapabilities downloadDir (configureHeadlessCapabilities runMode capabilities')+  capabilities <- configureHeadlessCapabilities wdOptions runMode capabilities'+                  >>= configureDownloadCapabilities downloadDir    -- Make the WebDriver   WebDriver <$> pure (T.unpack webdriverName)@@ -198,13 +199,27 @@ seleniumErrFileName = "stderr.txt"  -- | Add headless configuration to the Chrome browser-configureHeadlessCapabilities (RunHeadless (HeadlessConfig {..})) caps@(W.Capabilities {W.browser=browser@(W.Chrome {..})}) = caps { W.browser = browser' }-  where browser' = browser { W.chromeOptions = "--headless":resolution:chromeOptions }-        resolution = [i|--window-size=#{w},#{h}|]-        (w, h) = fromMaybe (1920, 1080) headlessResolution+configureHeadlessCapabilities :: Constraints m => WdOptions -> RunMode -> W.Capabilities -> m W.Capabilities+configureHeadlessCapabilities wdOptions (RunHeadless (HeadlessConfig {..})) caps@(W.Capabilities {W.browser=browser@(W.Chrome {..})}) = do+  headlessArg <- liftIO (detectChromeVersion (chromeBinaryPath wdOptions)) >>= \case+    Left err -> do+      warn [i|Couldn't determine chrome version when configuring headless capabilities (err: #{err}); passing --headless|]+      return "--headless"+    Right (ChromeVersion (major, _, _, _))+      -- See https://www.selenium.dev/blog/2023/headless-is-going-away/+      | major >= 110 -> return "--headless=new"+      | otherwise -> return "--headless" +  let browser' = browser { W.chromeOptions = headlessArg:resolution:chromeOptions }++  return (caps { W.browser = browser' })++  where+    resolution = [i|--window-size=#{w},#{h}|]+    (w, h) = fromMaybe (1920, 1080) headlessResolution+ -- | Add headless configuration to the Firefox capabilities-configureHeadlessCapabilities (RunHeadless (HeadlessConfig {..})) caps@(W.Capabilities {W.browser=(W.Firefox {..}), W.additionalCaps=ac}) = caps { W.additionalCaps = additionalCaps }+configureHeadlessCapabilities _ (RunHeadless (HeadlessConfig {..})) caps@(W.Capabilities {W.browser=(W.Firefox {..}), W.additionalCaps=ac}) = return (caps { W.additionalCaps = additionalCaps })   where     additionalCaps = case L.findIndex (\x -> fst x == "moz:firefoxOptions") ac of       Nothing -> ("moz:firefoxOptions", A.object [("args", A.Array ["-headless"])]) : ac@@ -222,8 +237,8 @@     addHeadlessArg xs | (A.String "-headless") `V.elem` xs = xs     addHeadlessArg xs = (A.String "-headless") `V.cons` xs -configureHeadlessCapabilities (RunHeadless {}) browser = error [i|Headless mode not yet supported for browser '#{browser}'|]-configureHeadlessCapabilities _ browser = browser+configureHeadlessCapabilities _ (RunHeadless {}) browser = error [i|Headless mode not yet supported for browser '#{browser}'|]+configureHeadlessCapabilities _ _ browser = return browser   configureDownloadCapabilities downloadDir caps@(W.Capabilities {W.browser=browser@(W.Firefox {..})}) = do