webdriver-0.11.0.0: a Haskell client for the Selenium WebDriver protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.WebDriver.JSON

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 a Source #

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

(.:??) :: FromJSON a => Object -> Text -> Parser (Maybe a) Source #

Due to a breaking change in the .:? operator of aeson 0.10 (see https://github.com/bos/aeson/issues/287) that was subsequently reverted, this operator was added to provide consistent behavior compatible with all aeson versions. If the field is either missing or Null, this operator should return a Nothing result.

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 a Source #

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 a Source #

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 -> Value Source #

Construct a singleton JSON object from a key and value.

pair :: (ToJSON a, ToJSON b) => (Text, Text) -> (a, b) -> Value Source #

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) -> Value Source #

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 Value 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 a Source #

Convert an attoparsec parser result to WD.

aesonResultToWD :: MonadBaseControl IO wd => Result a -> wd a Source #

Convert an Aeson parser result to WD.

Parse exception

newtype BadJSON Source #

An error occured when parsing a JSON value.

Constructors

BadJSON String 

Instances

Instances details
Exception BadJSON Source # 
Instance details

Defined in Test.WebDriver.JSON

Show BadJSON Source # 
Instance details

Defined in Test.WebDriver.JSON

Eq BadJSON Source # 
Instance details

Defined in Test.WebDriver.JSON

Methods

(==) :: BadJSON -> BadJSON -> Bool #

(/=) :: BadJSON -> BadJSON -> Bool #

parsing commands with no return value

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

Instances details
FromJSON NoReturn Source # 
Instance details

Defined in Test.WebDriver.JSON

noReturn :: WebDriver wd => wd NoReturn -> wd () Source #

Convenience function to handle webdriver commands with no return value.

ignoreReturn :: WebDriver wd => wd Value -> wd () Source #

Convenience function to ignore result of a webdriver command.