Safe Haskell | None |
---|---|
Language | Haskell2010 |
Test.Sandwich.WebDriver
Description
Introduce WebDriver servers and sessions.
Synopsis
- introduceWebDriver :: forall context (m :: Type -> Type). (BaseMonad m context, HasSomeCommandLineOptions context) => WebDriverDependencies -> WdOptions -> SpecFree (ContextWithWebdriverDeps context) m () -> SpecFree context m ()
- introduceWebDriverViaNix :: forall (m :: Type -> Type) context. (BaseMonad m context, HasSomeCommandLineOptions context, HasNixContext context) => WdOptions -> SpecFree (ContextWithWebdriverDeps context) m () -> SpecFree context m ()
- introduceWebDriverViaNix' :: forall (m :: Type -> Type) context. (BaseMonad m context, HasSomeCommandLineOptions context, HasNixContext context) => NodeOptions -> WdOptions -> SpecFree (ContextWithWebdriverDeps context) m () -> SpecFree context m ()
- defaultWebDriverDependencies :: WebDriverDependencies
- data WebDriverDependencies = WebDriverDependencies {}
- withSession :: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) => Session -> ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a -> ExampleT context m a
- withSession1 :: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) => ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a -> ExampleT context m a
- withSession2 :: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) => ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a -> ExampleT context m a
- getSessions :: (MonadReader context m, WebDriverMonad m context) => m [Session]
- closeCurrentSession :: (MonadLogger m, WebDriverSessionMonad m context) => m ()
- closeSession :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => Session -> WebDriver -> m ()
- closeAllSessions :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => WebDriver -> m ()
- closeAllSessionsExcept :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => [Session] -> WebDriver -> m ()
- type Session = String
- allocateWebDriver :: forall (m :: Type -> Type) context. (BaseMonad m context, HasFile context "java", HasFile context "selenium.jar", HasBrowserDependencies context) => WdOptions -> OnDemandOptions -> ExampleT context m WebDriver
- cleanupWebDriver :: forall (m :: Type -> Type) context. BaseMonad m context => WebDriver -> ExampleT context m ()
- introduceBrowserDependenciesViaNix :: forall (m :: Type -> Type) context. (MonadUnliftIO m, HasBaseContext context, HasNixContext context, HasSomeCommandLineOptions context) => SpecFree (LabelValue "browserDependencies" BrowserDependencies :> context) m () -> SpecFree context m ()
- introduceBrowserDependenciesViaNix' :: forall (m :: Type -> Type) context. (MonadUnliftIO m, HasBaseContext context, HasNixContext context, HasSomeCommandLineOptions context) => NodeOptions -> SpecFree (LabelValue "browserDependencies" BrowserDependencies :> context) m () -> SpecFree context m ()
- introduceWebDriver' :: forall (m :: Type -> Type) context. BaseMonad m context => WebDriverDependencies -> (WdOptions -> ExampleT (ContextWithBaseDeps context) m WebDriver) -> WdOptions -> SpecFree (ContextWithWebdriverDeps context) m () -> SpecFree context m ()
- addCommandLineOptionsToWdOptions :: SomeCommandLineOptions -> WdOptions -> WdOptions
- webdriver :: Label "webdriver" WebDriver
- data WebDriver
- type HasWebDriverContext context = HasLabel context "webdriver" WebDriver
- webdriverSession :: Label "webdriverSession" WebDriverSession
- type WebDriverSession = (Session, IORef WDSession)
- type HasWebDriverSessionContext context = HasLabel context "webdriverSession" WebDriverSession
- type BaseMonad (m :: Type -> Type) context = (HasCallStack, MonadUnliftIO m, MonadMask m, HasBaseContext context)
- type ContextWithBaseDeps context = LabelValue "browserDependencies" BrowserDependencies :> (FileValue "java" :> (FileValue "selenium.jar" :> context))
- type ContextWithWebdriverDeps context = LabelValue "webdriver" WebDriver :> ContextWithBaseDeps context
- type WebDriverMonad (m :: Type -> Type) context = (HasCallStack, MonadUnliftIO m, HasWebDriverContext context)
- type WebDriverSessionMonad (m :: Type -> Type) context = (WebDriverMonad m context, MonadReader context m, HasWebDriverSessionContext context)
- data OnDemandOptions
- defaultOnDemandOptions :: OnDemandOptions
- module Test.Sandwich.WebDriver.Config
Introducing a WebDriver server
Arguments
:: forall context (m :: Type -> Type). (BaseMonad m context, HasSomeCommandLineOptions context) | |
=> WebDriverDependencies | How to obtain dependencies |
-> WdOptions | |
-> SpecFree (ContextWithWebdriverDeps context) m () | |
-> SpecFree context m () |
Introduce a WebDriver
, using the given WebDriverDependencies
.
A good default is defaultWebDriverDependencies
.
introduceWebDriverViaNix Source #
Arguments
:: forall (m :: Type -> Type) context. (BaseMonad m context, HasSomeCommandLineOptions context, HasNixContext context) | |
=> WdOptions | Options |
-> SpecFree (ContextWithWebdriverDeps context) m () | |
-> SpecFree context m () |
Introduce a WebDriver
using the current NixContext
.
This will pull everything required from the configured Nixpkgs snapshot.
introduceWebDriverViaNix' Source #
Arguments
:: forall (m :: Type -> Type) context. (BaseMonad m context, HasSomeCommandLineOptions context, HasNixContext context) | |
=> NodeOptions | |
-> WdOptions | Options |
-> SpecFree (ContextWithWebdriverDeps context) m () | |
-> SpecFree context m () |
Same as introduceWebDriverViaNix
, but allows passing custom NodeOptions
.
Non-Nix dependency fetching
When you aren't using Nix, these types specify how to obtain the necessary dependencies.
defaultWebDriverDependencies :: WebDriverDependencies Source #
This configuration will
- Use
java
from the PATH, failing if it isn't found. - Download Selenium to
/tmp/tools
, reusing the one there if found. - Use
firefox
from the PATH as the browser. - Download a compatible
geckodriver
to/tmp/tools
, reusing the one there if found. - If applicable, it will also get
Xvfb
,fluxbox
, and/orffmpeg
from the PATH.
But, it's easy to customize this behavior. You can define your own WebDriverDependencies
and customize
how each of these dependencies are found.
data WebDriverDependencies Source #
This type describes how we should obtain all the dependencies needed to launch a WebDriver session. You can configure them individually.
Constructors
WebDriverDependencies | |
Fields
|
Running an example in a given session
Once you have a WebDriver
in context, you can run one or more sessions.
Each session will open an independent browser instance.
Arguments
:: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) | |
=> Session | Session to run |
-> ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a | |
-> ExampleT context m a |
Run a given example using a given Selenium session.
Arguments
:: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) | |
=> ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a | Wrapped action |
-> ExampleT context m a |
Convenience function. withSession1 = withSession "session1"
.
Arguments
:: forall (m :: Type -> Type) context a. (MonadMask m, MonadBaseControl IO m, HasBaseContext context, HasSomeCommandLineOptions context, WebDriverMonad m context) | |
=> ExampleT (LabelValue "webdriverSession" WebDriverSession :> context) m a | Wrapped action |
-> ExampleT context m a |
Convenience function. withSession2 = withSession "session2"
.
Managing sessions
getSessions :: (MonadReader context m, WebDriverMonad m context) => m [Session] Source #
Get all existing session names.
closeCurrentSession :: (MonadLogger m, WebDriverSessionMonad m context) => m () Source #
Close the current session.
closeSession :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => Session -> WebDriver -> m () Source #
Close the given session.
closeAllSessions :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => WebDriver -> m () Source #
Close all sessions.
closeAllSessionsExcept :: (HasCallStack, MonadLogger m, MonadUnliftIO m) => [Session] -> WebDriver -> m () Source #
Close all sessions except those listed.
Lower-level allocation functions
Arguments
:: forall (m :: Type -> Type) context. (BaseMonad m context, HasFile context "java", HasFile context "selenium.jar", HasBrowserDependencies context) | |
=> WdOptions | Options |
-> OnDemandOptions | |
-> ExampleT context m WebDriver |
Allocate a WebDriver using the given options.
cleanupWebDriver :: forall (m :: Type -> Type) context. BaseMonad m context => WebDriver -> ExampleT context m () Source #
Clean up the given WebDriver.
introduceBrowserDependenciesViaNix Source #
Arguments
:: forall (m :: Type -> Type) context. (MonadUnliftIO m, HasBaseContext context, HasNixContext context, HasSomeCommandLineOptions context) | |
=> SpecFree (LabelValue "browserDependencies" BrowserDependencies :> context) m () | Child spec |
-> SpecFree context m () | Parent spec |
Introduce BrowserDependencies
via Nix, using the command line options.
This is useful to create the context for functions like allocateWebDriver
.
introduceBrowserDependenciesViaNix' Source #
Arguments
:: forall (m :: Type -> Type) context. (MonadUnliftIO m, HasBaseContext context, HasNixContext context, HasSomeCommandLineOptions context) | |
=> NodeOptions | |
-> SpecFree (LabelValue "browserDependencies" BrowserDependencies :> context) m () | Child spec |
-> SpecFree context m () | Parent spec |
Same as introduceBrowserDependenciesViaNix
, but allows passing custom NodeOptions
.
Arguments
:: forall (m :: Type -> Type) context. BaseMonad m context | |
=> WebDriverDependencies | Dependencies |
-> (WdOptions -> ExampleT (ContextWithBaseDeps context) m WebDriver) | |
-> WdOptions | |
-> SpecFree (ContextWithWebdriverDeps context) m () | |
-> SpecFree context m () |
Same as introduceWebDriver
, but with a controllable allocation callback.
addCommandLineOptionsToWdOptions :: SomeCommandLineOptions -> WdOptions -> WdOptions Source #
Merge the options from the CommandLineOptions
into some WdOptions
.
Context types
WebDriver
type HasWebDriverContext context = HasLabel context "webdriver" WebDriver Source #
WebDriverSession
webdriverSession :: Label "webdriverSession" WebDriverSession Source #
type HasWebDriverSessionContext context = HasLabel context "webdriverSession" WebDriverSession Source #
Shorthands
These are used to make type signatures shorter.
type BaseMonad (m :: Type -> Type) context = (HasCallStack, MonadUnliftIO m, MonadMask m, HasBaseContext context) Source #
type ContextWithBaseDeps context Source #
Arguments
= LabelValue "browserDependencies" BrowserDependencies :> (FileValue "java" :> (FileValue "selenium.jar" :> context)) | Browser dependencies |
type ContextWithWebdriverDeps context = LabelValue "webdriver" WebDriver :> ContextWithBaseDeps context Source #
type WebDriverMonad (m :: Type -> Type) context = (HasCallStack, MonadUnliftIO m, HasWebDriverContext context) Source #
type WebDriverSessionMonad (m :: Type -> Type) context = (WebDriverMonad m context, MonadReader context m, HasWebDriverSessionContext context) Source #
On demand options
data OnDemandOptions Source #
How to obtain certain binaries "on demand". These may or not be needed based on WdOptions
, so
they will be obtained as needed.