sandwich-webdriver-0.3.0.0: Sandwich integration with Selenium WebDriver
Safe HaskellNone
LanguageHaskell2010

Test.Sandwich.WebDriver

Description

Introduce WebDriver servers and sessions.

Synopsis

Introducing a WebDriver server

introduceWebDriver Source #

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/or ffmpeg 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.

withSession Source #

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.

withSession1 Source #

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".

withSession2 Source #

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.

type Session = String Source #

Session is just a String name.

Lower-level allocation functions

allocateWebDriver Source #

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.

introduceWebDriver' Source #

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.

Context types

WebDriver

type HasWebDriverContext context = HasLabel context "webdriver" WebDriver Source #

WebDriverSession

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 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.

Re-exports