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

Safe HaskellNone
LanguageHaskell2010

Test.WebDriver.Commands

Contents

Description

This module exports basic WD actions that can be used to interact with a browser session.

Synopsis

Sessions

createSession :: WebDriver wd => Capabilities -> wd WDSession Source #

Create a new session with the given Capabilities. The returned session becomes the "current session" for this action.

Note: if you're using runSession to run your WebDriver commands, you don't need to call this explicitly.

closeSession :: WebDriver wd => wd () Source #

Close the current session and the browser associated with it.

sessions :: WebDriver wd => wd [(SessionId, Capabilities)] Source #

Retrieve a list of active sessions and their Capabilities.

getActualCaps :: WebDriver wd => wd Capabilities Source #

Get the actual server-side Capabilities of the current session.

Browser interaction

Web navigation

openPage :: WebDriver wd => String -> wd () Source #

Opens a new page by the given URL.

forward :: WebDriver wd => wd () Source #

Navigate forward in the browser history.

back :: WebDriver wd => wd () Source #

Navigate backward in the browser history.

refresh :: WebDriver wd => wd () Source #

Refresh the current page

Page info

getCurrentURL :: WebDriver wd => wd String Source #

Gets the URL of the current page.

getSource :: WebDriver wd => wd Text Source #

Get the current page source

getTitle :: WebDriver wd => wd Text Source #

Get the title of the current page.

saveScreenshot :: WebDriver wd => FilePath -> wd () Source #

Save a screenshot to a particular location

screenshot :: WebDriver wd => wd ByteString Source #

Grab a screenshot of the current page as a PNG image

screenshotBase64 :: WebDriver wd => wd ByteString Source #

Grab a screenshot as a base-64 encoded PNG image. This is the protocol-defined format.

Timeouts

setImplicitWait :: WebDriver wd => Integer -> wd () Source #

Sets the amount of time (ms) we implicitly wait when searching for elements.

setScriptTimeout :: WebDriver wd => Integer -> wd () Source #

Sets the amount of time (ms) we wait for an asynchronous script to return a result.

setPageLoadTimeout :: WebDriver wd => Integer -> wd () Source #

Sets the amount of time (ms) to wait for a page to finish loading before throwing a Timeout exception.

Web elements

data Selector Source #

Specifies element(s) within a DOM tree using various selection methods.

Constructors

ById Text 
ByName Text 
ByClass Text

(Note: multiple classes are not allowed. For more control, use ByCSS)

ByTag Text 
ByLinkText Text 
ByPartialLinkText Text 
ByCSS Text 
ByXPath Text 

Searching for elements

findElem :: WebDriver wd => Selector -> wd Element Source #

Find an element on the page using the given element selector.

findElems :: WebDriver wd => Selector -> wd [Element] Source #

Find all elements on the page matching the given selector.

findElemFrom :: WebDriver wd => Element -> Selector -> wd Element Source #

Search for an element using the given element as root.

findElemsFrom :: WebDriver wd => Element -> Selector -> wd [Element] Source #

Find all elements matching a selector, using the given element as root.

Interacting with elements

click :: WebDriver wd => Element -> wd () Source #

Click on an element.

submit :: WebDriver wd => Element -> wd () Source #

Submit a form element. This may be applied to descendents of a form element as well.

getText :: WebDriver wd => Element -> wd Text Source #

Get all visible text within this element.

Sending key inputs to elements

sendKeys :: WebDriver wd => Text -> Element -> wd () Source #

Send a sequence of keystrokes to an element. All modifier keys are released at the end of the function. Named constants for special modifier keys can be found in Test.WebDriver.Common.Keys

sendRawKeys :: WebDriver wd => Text -> Element -> wd () Source #

Similar to sendKeys, but doesn't implicitly release modifier keys afterwards. This allows you to combine modifiers with mouse clicks.

clearInput :: WebDriver wd => Element -> wd () Source #

Clear a textarea or text input element's value.

Element information

attr :: WebDriver wd => Element -> Text -> wd (Maybe Text) Source #

Retrieve the value of an element's attribute

cssProp :: WebDriver wd => Element -> Text -> wd (Maybe Text) Source #

Retrieve the value of an element's computed CSS property

elemPos :: WebDriver wd => Element -> wd (Int, Int) Source #

Retrieve an element's current position.

elemSize :: WebDriver wd => Element -> wd (Word, Word) Source #

Retrieve an element's current size.

isSelected :: WebDriver wd => Element -> wd Bool Source #

Determine if the element is selected.

isEnabled :: WebDriver wd => Element -> wd Bool Source #

Determine if the element is enabled.

isDisplayed :: WebDriver wd => Element -> wd Bool Source #

Determine if the element is displayed.

tagName :: WebDriver wd => Element -> wd Text Source #

Return the tag name of the given element.

activeElem :: WebDriver wd => wd Element Source #

Return the element that currently has focus.

elemInfo :: WebDriver wd => Element -> wd Value Source #

Deprecated: This command does not work with Marionette (Firefox) driver, and is likely to be completely removed in Selenium 4

Describe the element. Returns a JSON object whose meaning is currently undefined by the WebDriver protocol.

Element equality

(<==>) :: WebDriver wd => Element -> Element -> wd Bool infix 4 Source #

Determines if two element identifiers refer to the same element.

(</=>) :: WebDriver wd => Element -> Element -> wd Bool infix 4 Source #

Determines if two element identifiers refer to different elements.

Javascript

executeJS :: (Foldable f, FromJSON a, WebDriver wd) => f JSArg -> Text -> wd a Source #

Inject a snippet of Javascript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the script is returned and converted to an instance of FromJSON.

The first parameter defines a sequence of arguments to pass to the javascript function. Arguments of type Element will be converted to the corresponding DOM element. Likewise, any elements in the script result will be returned to the client as Elements.

The second parameter defines the script itself in the form of a function body. The value returned by that function will be returned to the client. The function will be invoked with the provided argument list and the values may be accessed via the arguments object in the order specified.

When using executeJS, GHC might complain about an ambiguous type in situations where the result of the executeJS call is ignored/discard. Consider the following example:

	jsExample = do
		e <- findElem (ById "foo")
		executeJS [] "someAction()"
		return e

Because the result of the executeJS is discarded, GHC cannot resolve which instance of the fromJSON class to use when parsing the Selenium server response. In such cases, we can use the ignoreReturn helper function located in Test.WebDriver.JSON. ignoreReturn has no runtime effect; it simply helps the type system by expicitly providing a fromJSON instance to use.

	import Test.WebDriver.JSON (ignoreReturn)
	jsExample = do
		e <- findElem (ById "foo")
		ignoreReturn $ executeJS [] "someAction()"
		return e

asyncJS :: (Foldable f, FromJSON a, WebDriver wd) => f JSArg -> Text -> wd (Maybe a) Source #

Executes a snippet of Javascript code asynchronously. This function works similarly to executeJS, except that the Javascript is passed a callback function as its final argument. The script should call this function to signal that it has finished executing, passing to it a value that will be returned as the result of asyncJS. A result of Nothing indicates that the Javascript function timed out (see setScriptTimeout)

data JSArg Source #

An existential wrapper for any ToJSON instance. This allows us to pass parameters of many different types to Javascript code.

Constructors

ToJSON a => JSArg a 

Windows

currentWindow :: WindowHandle Source #

A special WindowHandle that always refers to the currently focused window. This is also used by the Default instance.

getCurrentWindow :: WebDriver wd => wd WindowHandle Source #

Returns a handle to the currently focused window

closeWindow :: WebDriver wd => WindowHandle -> wd () Source #

Closes the given window

windows :: WebDriver wd => wd [WindowHandle] Source #

Returns a list of all windows available to the session

maximize :: WebDriver wd => wd () Source #

Maximizes the current window if not already maximized

getWindowSize :: WebDriver wd => wd (Word, Word) Source #

Get the dimensions of the current window.

setWindowSize :: WebDriver wd => (Word, Word) -> wd () Source #

Set the dimensions of the current window.

getWindowPos :: WebDriver wd => wd (Int, Int) Source #

Get the coordinates of the current window.

setWindowPos :: WebDriver wd => (Int, Int) -> wd () Source #

Set the coordinates of the current window.

Focusing on frames

focusFrame :: WebDriver wd => FrameSelector -> wd () Source #

Switch focus to the frame specified by the FrameSelector.

Cookies

data Cookie Source #

Cookies are delicious delicacies. When sending cookies to the server, a value of Nothing indicates that the server should use a default value. When receiving cookies from the server, a value of Nothing indicates that the server is unable to specify the value.

Constructors

Cookie 

Fields

mkCookie :: Text -> Text -> Cookie Source #

Creates a Cookie with only a name and value specified. All other fields are set to Nothing, which tells the server to use default values.

cookies :: WebDriver wd => wd [Cookie] Source #

Retrieve all cookies visible to the current page.

setCookie :: WebDriver wd => Cookie -> wd () Source #

Set a cookie. If the cookie path is not specified, it will default to "/". Likewise, if the domain is omitted, it will default to the current page's domain

deleteCookie :: WebDriver wd => Cookie -> wd () Source #

Delete a cookie. This will do nothing is the cookie isn't visible to the current page.

deleteVisibleCookies :: WebDriver wd => wd () Source #

Delete all visible cookies on the current page.

Alerts

getAlertText :: WebDriver wd => wd Text Source #

Get the text of an alert dialog.

replyToAlert :: WebDriver wd => Text -> wd () Source #

Sends keystrokes to Javascript prompt() dialog.

acceptAlert :: WebDriver wd => wd () Source #

Accepts the currently displayed alert dialog.

dismissAlert :: WebDriver wd => wd () Source #

Dismisses the currently displayed alert dialog.

Mouse gestures

moveTo :: WebDriver wd => (Int, Int) -> wd () Source #

Moves the mouse to the given position relative to the active element.

moveToCenter :: WebDriver wd => Element -> wd () Source #

Moves the mouse to the center of a given element.

moveToFrom :: WebDriver wd => (Int, Int) -> Element -> wd () Source #

Moves the mouse to the given position relative to the given element.

clickWith :: WebDriver wd => MouseButton -> wd () Source #

Click at the current mouse position with the given mouse button.

data MouseButton Source #

A mouse button

mouseDown :: WebDriver wd => wd () Source #

Press and hold the left mouse button down. Note that undefined behavior occurs if the next mouse command is not mouseUp.

mouseUp :: WebDriver wd => wd () Source #

Release the left mouse button.

withMouseDown :: WebDriver wd => wd a -> wd a Source #

Perform the given action with the left mouse button held down. The mouse is automatically released afterwards.

doubleClick :: WebDriver wd => wd () Source #

Double click at the current mouse location.

HTML 5 Web Storage

storageSize :: WebDriver wd => WebStorageType -> wd Integer Source #

Get the current number of keys in a web storage area.

getAllKeys :: WebDriver wd => WebStorageType -> wd [Text] Source #

Get a list of all keys from a web storage area.

deleteAllKeys :: WebDriver wd => WebStorageType -> wd () Source #

Delete all keys within a given web storage area.

getKey :: WebDriver wd => WebStorageType -> Text -> wd Text Source #

Get the value associated with a key in the given web storage area. Unset keys result in empty strings, since the Web Storage spec makes no distinction between the empty string and an undefined value.

setKey :: WebDriver wd => WebStorageType -> Text -> Text -> wd Text Source #

Set a key in the given web storage area.

deleteKey :: WebDriver wd => WebStorageType -> Text -> wd () Source #

Delete a key in the given web storage area.

HTML 5 Application Cache

data ApplicationCacheStatus Source #

Instances

Bounded ApplicationCacheStatus Source # 
Enum ApplicationCacheStatus Source # 
Eq ApplicationCacheStatus Source # 
Ord ApplicationCacheStatus Source # 
Read ApplicationCacheStatus Source # 
Show ApplicationCacheStatus Source # 
FromJSON ApplicationCacheStatus Source # 

Mobile device support

Screen orientation

data Orientation Source #

A screen orientation

Constructors

Landscape 
Portrait 

getOrientation :: WebDriver wd => wd Orientation Source #

Get the current screen orientation for rotatable display devices.

setOrientation :: WebDriver wd => Orientation -> wd () Source #

Set the current screen orientation for rotatable display devices.

Geo-location

getLocation :: WebDriver wd => wd (Int, Int, Int) Source #

Get the current geographical location of the device.

setLocation :: WebDriver wd => (Int, Int, Int) -> wd () Source #

Set the current geographical location of the device.

Touch gestures

touchClick :: WebDriver wd => Element -> wd () Source #

Single tap on the touch screen at the given element's location.

touchDown :: WebDriver wd => (Int, Int) -> wd () Source #

Emulates pressing a finger down on the screen at the given location.

touchUp :: WebDriver wd => (Int, Int) -> wd () Source #

Emulates removing a finger from the screen at the given location.

touchMove :: WebDriver wd => (Int, Int) -> wd () Source #

Emulates moving a finger on the screen to the given location.

touchScroll :: WebDriver wd => (Int, Int) -> wd () Source #

Emulate finger-based touch scroll. Use this function if you don't care where the scroll begins

touchScrollFrom :: WebDriver wd => (Int, Int) -> Element -> wd () Source #

Emulate finger-based touch scroll, starting from the given location relative to the given element.

touchDoubleClick :: WebDriver wd => Element -> wd () Source #

Emulate a double click on a touch device.

touchLongClick :: WebDriver wd => Element -> wd () Source #

Emulate a long click on a touch device.

touchFlick :: WebDriver wd => (Int, Int) -> wd () Source #

Emulate a flick on the touch screen. The coordinates indicate x and y velocity, respectively. Use this function if you don't care where the flick starts.

touchFlickFrom Source #

Arguments

:: WebDriver wd 
=> Int

flick velocity

-> (Int, Int)

a location relative to the given element

-> Element

the given element

-> wd () 

Emulate a flick on the touch screen.

IME support

activateIME :: WebDriver wd => Text -> wd () Source #

Uploading files to remote server

These functions allow you to upload a file to a remote server. Note that this operation isn't supported by all WebDriver servers, and the location where the file is stored is not standardized.

uploadFile :: WebDriver wd => FilePath -> wd () Source #

Uploads a file from the local filesystem by its file path.

uploadRawFile Source #

Arguments

:: WebDriver wd 
=> FilePath

File path to use with this bytestring.

-> Integer

Modification time (in seconds since Unix epoch).

-> ByteString

The file contents as a lazy ByteString

-> wd () 

Uploads a raw bytestring with associated file info.

uploadZipEntry :: WebDriver wd => Entry -> wd () Source #

Lowest level interface to the file uploading mechanism. This allows you to specify the exact details of the zip entry sent across network.

Server information and logs

serverStatus :: WebDriver wd => wd Value Source #

Get information from the server as a JSON Object. For more information about this object see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#status

getLogs :: WebDriver wd => LogType -> wd [LogEntry] Source #

Retrieve the log buffer for a given log type. The server-side log buffer is reset after each request.

Which log types are available is server defined, but the wire protocol lists these as common log types: client, driver, browser, server

getLogTypes :: WebDriver wd => wd [LogType] Source #

Get a list of available log types.

data LogEntry Source #

A record that represents a single log entry.

Constructors

LogEntry 

Fields

data LogLevel Source #

Indicates a log verbosity level. Used in Firefox and Opera configuration.