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

Safe HaskellSafe-Infered

Test.WebDriver.Commands

Contents

Description

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

Synopsis

Sessions

createSession :: Capabilities -> WD WDSessionSource

Create a new session with the given Capabilities. This command resets the current session ID to that of the new session.

closeSession :: WD ()Source

Close the current session and the browser associated with it.

sessions :: WD [(SessionId, Capabilities)]Source

Retrieve a list of active sessions and their Capabilities.

getCaps :: WD CapabilitiesSource

Get the actual Capabilities of the current session.

Browser interaction

Web navigation

openPage :: String -> WD ()Source

Opens a new page by the given URL.

forward :: WD ()Source

Navigate forward in the browser history.

back :: WD ()Source

Navigate backward in the browser history.

refresh :: WD ()Source

Refresh the current page

Page info

getCurrentURL :: WD StringSource

Gets the URL of the current page.

getSource :: WD TextSource

Get the current page source

getTitle :: WD TextSource

Get the title of the current page.

screenshot :: WD ByteStringSource

Grab a screenshot of the current page as a PNG image

Timeouts

setImplicitWait :: Integer -> WD ()Source

Sets the amount of time we implicitly wait when searching for Elements.

setScriptTimeout :: Integer -> WD ()Source

Sets the amount of time we wait for an asynchronous script to return a result

Web elements

newtype Element Source

An opaque identifier for a web page element.

Constructors

Element Text 

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 :: Selector -> WD ElementSource

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

findElems :: Selector -> WD [Element]Source

Find all elements on the page matching the given selector.

findElemFrom :: Element -> Selector -> WD ElementSource

Search for an element using the given element as root.

findElemsFrom :: Element -> Selector -> WD [Element]Source

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

Interacting with elements

click :: Element -> WD ()Source

Click on an element.

submit :: Element -> WD ()Source

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

getText :: Element -> WD TextSource

Get all visible text within this element.

sendKeys :: Text -> Element -> WD ()Source

Send a sequence of keystrokes to an element. All modifier keys are released at the end of the function. For more information about modifier keys, see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value

sendRawKeys :: 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 :: Element -> WD ()Source

Clear a textarea or text input element's value.

Element information

attr :: Element -> Text -> WD (Maybe Text)Source

Retrieve the value of an element's attribute

cssProp :: Element -> Text -> WD (Maybe Text)Source

Retrieve the value of an element's computed CSS property

elemPos :: Element -> WD (Int, Int)Source

Retrieve an element's current position.

elemSize :: Element -> WD (Word, Word)Source

Retrieve an element's current size.

isSelected :: Element -> WD BoolSource

Determine if the element is selected.

isEnabled :: Element -> WD BoolSource

Determine if the element is enabled.

isDisplayed :: Element -> WD BoolSource

Determine if the element is displayed.

tagName :: Element -> WD TextSource

Return the tag name of the given element.

activeElem :: WD ElementSource

Return the element that currently has focus.

elemInfo :: Element -> WD ValueSource

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

Element equality

(<==>) :: Element -> Element -> WD BoolSource

Determines if two element identifiers refer to the same element.

(</=>) :: Element -> Element -> WD BoolSource

Determines if two element identifiers refer to different elements.

Javascript

executeJS :: FromJSON a => [JSArg] -> Text -> WD aSource

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

asyncJS :: FromJSON a => [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

forall a . ToJSON a => JSArg a 

Instances

Windows

newtype WindowHandle Source

An opaque identifier for a browser window

Constructors

WindowHandle Text 

currentWindow :: WindowHandleSource

A special WindowHandle that always refers to the currently focused window.

getCurrentWindow :: WD WindowHandleSource

Returns a handle to the currently focused window

focusWindow :: WindowHandle -> WD ()Source

Switches focus to a given window.

closeWindow :: WindowHandle -> WD ()Source

Closes the given window

windows :: WD [WindowHandle]Source

Returns a list of all windows available to the session

getWindowSize :: WindowHandle -> WD (Word, Word)Source

Get the dimensions of the given window.

setWindowSize :: WindowHandle -> (Word, Word) -> WD ()Source

Set the dimensions of the given window.

getWindowPos :: WindowHandle -> WD (Int, Int)Source

Get the coordinates of the given window.

setWindowPos :: WindowHandle -> (Int, Int) -> WD ()Source

Set the coordinates of the given window.

Cookies

data Cookie Source

Cookies are delicious delicacies.

cookies :: WD [Cookie]Source

Retrieve all cookies visible to the current page.

setCookie :: 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 :: Cookie -> WD ()Source

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

deleteVisibleCookies :: WD ()Source

Delete all visible cookies on the current page.

Alerts

getAlertText :: WD TextSource

Get the text of an alert dialog.

replyToAlert :: Text -> WD ()Source

Sends keystrokes to Javascript prompt() dialog.

acceptAlert :: WD ()Source

Accepts the currently displayed alert dialog.

dismissAlert :: WD ()Source

Dismisses the currently displayed alert dialog.

Mouse gestures

moveTo :: (Int, Int) -> WD ()Source

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

moveToCenter :: Element -> WD ()Source

Moves the mouse to the center of a given element.

moveToFrom :: (Int, Int) -> Element -> WD ()Source

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

clickWith :: MouseButton -> WD ()Source

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

mouseDown :: WD ()Source

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

mouseUp :: WD ()Source

Release the left mouse button.

withMouseDown :: WD a -> WD aSource

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

doubleClick :: WD ()Source

Double click at the current mouse location.

Touch gestures

touchClick :: Element -> WD ()Source

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

touchDown :: (Int, Int) -> WD ()Source

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

touchUp :: (Int, Int) -> WD ()Source

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

touchMove :: (Int, Int) -> WD ()Source

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

touchScroll :: (Int, Int) -> WD ()Source

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

touchScrollFrom :: (Int, Int) -> Element -> WD ()Source

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

touchDoubleClick :: Element -> WD ()Source

Emulate a double click on a touch device.

touchLongClick :: Element -> WD ()Source

Emulate a long click on a touch device.

touchFlick :: (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.

touchFlickFromSource

Arguments

:: Int

flick velocity

-> (Int, Int)

a location relative to the given element

-> Element

the given element

-> WD () 

Emulate a flick on the touch screen.

Screen orientation

getOrientation :: WD OrientationSource

Get the current screen orientation for rotatable display devices.

setOrientation :: Orientation -> WD ()Source

Set the current screen orientation for rotatable display devices.

Geo-location

getLocation :: WD (Int, Int, Int)Source

Get the current geographical location of the device.

setLocation :: (Int, Int, Int) -> WD ()Source

Set the current geographical location of the device.

IME support

Server information

serverStatus :: WD ValueSource

Get information from the server as a JSON Object. For more information about this object see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/status