webdriver-0.6.0.1: a Haskell client for the Selenium WebDriver protocol

Safe HaskellNone

Test.WebDriver.JSON

Contents

Description

A collection of convenience functions for using and parsing JSON values within WD. All monadic parse errors are converted to asynchronous BadJSON exceptions.

These functions are used internally to implement webdriver commands, and may be useful for implementing non-standard commands.

Synopsis

Access a JSON object key

(!:) :: (MonadBaseControl IO wd, FromJSON a) => Object -> Text -> wd aSource

This operator is a wrapper over Aeson's .: operator.

Conversion from JSON within WD

Apostrophes are used to disambiguate these functions from their Data.Aeson counterparts.

parseJSON' :: MonadBaseControl IO wd => FromJSON a => ByteString -> wd aSource

Parse a lazy ByteString as a top-level JSON Value, then convert it to an instance of FromJSON..

fromJSON' :: MonadBaseControl IO wd => FromJSON a => Value -> wd aSource

Convert a JSON Value to an instance of FromJSON.

Tuple functions

Convenience functions for working with tuples.

JSON object constructors

single :: ToJSON a => Text -> a -> ValueSource

Construct a singleton JSON object from a key and value.

pair :: (ToJSON a, ToJSON b) => (Text, Text) -> (a, b) -> ValueSource

Construct a 2-element JSON object from a pair of keys and a pair of values.

triple :: (ToJSON a, ToJSON b, ToJSON c) => (Text, Text, Text) -> (a, b, c) -> ValueSource

Construct a 3-element JSON object from a triple of keys and a triple of values.

Extracting JSON objects into tuples

parsePair :: (MonadBaseControl IO wd, FromJSON a, FromJSON b) => String -> String -> String -> Value -> wd (a, b)Source

Parse a JSON Object as a pair. The first two string arguments specify the keys to extract from the object. The third string is the name of the calling function, for better error reporting.

parseTriple :: (MonadBaseControl IO wd, FromJSON a, FromJSON b, FromJSON c) => String -> String -> String -> String -> Value -> wd (a, b, c)Source

Parse a JSON Object as a triple. The first three string arguments specify the keys to extract from the object. The fourth string is the name of the calling function, for better error reporting.

Conversion from parser results to WD

These functions are used to implement the other functions in this module, and could be used to implement other JSON convenience functions

apResultToWD :: (MonadBaseControl IO wd, FromJSON a) => Result Value -> wd aSource

Convert an attoparsec parser result to WD.

aesonResultToWD :: MonadBaseControl IO wd => Result a -> wd aSource

Convert an Aeson parser result to WD.

Parse exception

newtype BadJSON Source

An error occured when parsing a JSON value.

Constructors

BadJSON String 

no return value type

data NoReturn Source

A type indicating that we expect no return value from the webdriver request. Its FromJSON instance parses successfully for any values that indicate lack of a return value (a notion that varies from server to server).

Constructors

NoReturn 

Instances