Skip to content

Better support for Firefox on macOS #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sandwich.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
run: cabal test sandwich-quickcheck

- name: Test (sandwich-webdriver)
run: cabal test sandwich-webdriver
run: cabal test sandwich-webdriver --test-option="--headless"

- uses: actions/cache/save@v4
if: always() && steps.cache-restore.outputs.cache-hit != 'true'
Expand Down
5 changes: 4 additions & 1 deletion demos/demo-webdriver-nix/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import Test.Sandwich.WebDriver
import Test.WebDriver.Commands


-- 5/5/2025: we use nixpkgsMaster here because support for Firefox on macOS finally landed recently as firefox-bin.
-- Once a Nixpkgs release contains firefox-bin, we can switch to that.

simple :: TopSpecWithOptions
simple = introduceNixContext (nixpkgsReleaseDefault { nixpkgsDerivationAllowUnfree = True }) $
simple = introduceNixContext (nixpkgsMaster { nixpkgsDerivationAllowUnfree = True }) $
introduceWebDriverViaNix defaultWdOptions $ do
it "opens Google and searches" $ withSession1 $ do
openPage [i|https://www.google.com|]
Expand Down
26 changes: 26 additions & 0 deletions sandwich-contexts/lib/Test/Sandwich/Contexts/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module Test.Sandwich.Contexts.Nix (

-- * Nixpkgs releases #releases#
, nixpkgsReleaseDefault
, nixpkgsMaster
, nixpkgsRelease2411
, nixpkgsRelease2405
, nixpkgsRelease2311

Expand Down Expand Up @@ -119,6 +121,30 @@ data NixpkgsDerivation =
, nixpkgsDerivationAllowUnfree :: Bool
} deriving (Show, Eq)

-- | Nixpkgs master, accessed 5\/5\/2025.
-- You can compute updated values for this release (or others) by running
-- nix-prefetch-github NixOS nixpkgs --rev master
nixpkgsMaster :: NixpkgsDerivation
nixpkgsMaster = NixpkgsDerivationFetchFromGitHub {
nixpkgsDerivationOwner = "NixOS"
, nixpkgsDerivationRepo = "nixpkgs"
, nixpkgsDerivationRev = "5a837cb8662b841d5e3f491791aa1c389f68b25e"
, nixpkgsDerivationSha256 = "sha256-/LHyhxNwop/1lyg9kclGHBpyBadLFZda4z0QOzERUKY="
, nixpkgsDerivationAllowUnfree = False
}

-- | Nixpkgs release 24.11, accessed 5\/5\/2025.
-- You can compute updated values for this release (or others) by running
-- nix-prefetch-github NixOS nixpkgs --rev release-24.05
nixpkgsRelease2411 :: NixpkgsDerivation
nixpkgsRelease2411 = NixpkgsDerivationFetchFromGitHub {
nixpkgsDerivationOwner = "NixOS"
, nixpkgsDerivationRepo = "nixpkgs"
, nixpkgsDerivationRev = "c6aca34d2ca2ce9e20b722f54e684cda64b275c2"
, nixpkgsDerivationSha256 = "sha256-U3VKPi5D2oLBFzaMI0jJLJp8J64ZLjz+EwodUS//QWc="
, nixpkgsDerivationAllowUnfree = False
}

-- | Nixpkgs release 24.05, accessed 11\/9\/2024.
-- You can compute updated values for this release (or others) by running
-- nix-prefetch-github NixOS nixpkgs --rev release-24.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Control.Monad.Logger
import Control.Monad.Reader
import Data.String.Interpolate
import System.FilePath
import System.Info (os)
import Test.Sandwich
import Test.Sandwich.Contexts.Files
import Test.Sandwich.Contexts.Nix
Expand Down Expand Up @@ -141,8 +142,13 @@ introduceBrowserDependenciesViaNix' nodeOptions = introduce' nodeOptions "Introd
let useChrome = BrowserDependenciesChrome <$> getBinaryViaNixPackage @"google-chrome-stable" "google-chrome"
<*> getBinaryViaNixPackage @"chromedriver" "chromedriver"

let useFirefox = BrowserDependenciesFirefox <$> getBinaryViaNixPackage @"firefox" "firefox"
<*> getBinaryViaNixPackage @"geckodriver" "geckodriver"
let useFirefox = case os of
"darwin" -> do
-- The only Firefox version that currently works on Darwin as of 5/5/2025 is firefox-bin
firefox <- buildNixSymlinkJoin ["firefox-bin"] >>= (liftIO . defaultFindFile "firefox")
BrowserDependenciesFirefox firefox <$> getBinaryViaNixPackage @"geckodriver" "geckodriver"
_ -> BrowserDependenciesFirefox <$> getBinaryViaNixPackage @"firefox" "firefox"
<*> getBinaryViaNixPackage @"geckodriver" "geckodriver"

deps <- case optFirefox of
Just UseChrome -> useChrome
Expand Down
34 changes: 18 additions & 16 deletions sandwich-webdriver/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ import Data.Text as T
import UnliftIO.Temporary
import Data.Time.Clock
import Data.String.Interpolate
import Test.Sandwich.Contexts.Nix
import System.FilePath
import Test.WebDriver.Commands
import Test.Sandwich.WebDriver
import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy as BL


spec :: TopSpec
spec = do
it "works" $ do
2 `shouldBe` 2
spec :: TopSpecWithOptions
spec = introduceNixContext (nixpkgsMaster { nixpkgsDerivationAllowUnfree = True }) $
introduceWebDriverViaNix defaultWdOptions $ do
it "opens Google and searches" $ withSession1 $ do
openPage [i|https://www.google.com|]
search <- findElem (ByCSS [i|*[title="Search"]|])
click search
sendKeys "Haskell Sandwich" search
findElem (ByCSS [i|input[type="submit"]|]) >>= click

-- it "successfully runs obtainChromeDriver" $ do
-- withSystemTempDirectory "test-download" $ \dir -> do
-- obtainChromeDriver dir (DownloadChromeDriverAutodetect Nothing) >>= \case
-- Right x -> info [i|Got chromedriver: #{x}|]
-- Left err -> expectationFailure (T.unpack err)

-- it "successfully runs obtainGeckoDriver" $ do
-- withSystemTempDirectory "test-download" $ \dir -> do
-- obtainGeckoDriver dir (DownloadGeckoDriverAutodetect Nothing) >>= \case
-- Right x -> info [i|Got geckoDriver: #{x}|]
-- Left err -> expectationFailure (T.unpack err)
Just dir <- getCurrentFolder
screenshot >>= liftIO . BL.writeFile (dir </> "screenshot.png")


main :: IO ()
main = runSandwich options spec
main = runSandwichWithCommandLineArgs options spec
where
options = defaultOptions {
optionsTestArtifactsDirectory = defaultTestArtifactsDirectory
Expand Down
Loading