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

Safe HaskellNone

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 WDSessionSource

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

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.

getCaps :: WebDriver wd => wd CapabilitiesSource

Get the actual 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 StringSource

Gets the URL of the current page.

getSource :: WebDriver wd => wd TextSource

Get the current page source

getTitle :: WebDriver wd => wd TextSource

Get the title of the current page.

screenshot :: WebDriver wd => wd ByteStringSource

Grab a screenshot of the current page as a PNG image

Timeouts

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

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

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

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

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

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

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 :: WebDriver wd => Selector -> wd ElementSource

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 ElementSource

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 TextSource

Get all visible text within this element.

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. For more information about modifier keys, see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value

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 BoolSource

Determine if the element is selected.

isEnabled :: WebDriver wd => Element -> wd BoolSource

Determine if the element is enabled.

isDisplayed :: WebDriver wd => Element -> wd BoolSource

Determine if the element is displayed.

tagName :: WebDriver wd => Element -> wd TextSource

Return the tag name of the given element.

activeElem :: WebDriver wd => wd ElementSource

Return the element that currently has focus.

elemInfo :: WebDriver wd => Element -> wd ValueSource

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

Element equality

(<==>) :: WebDriver wd => Element -> Element -> wd BoolSource

Determines if two element identifiers refer to the same element.

(</=>) :: WebDriver wd => Element -> Element -> wd BoolSource

Determines if two element identifiers refer to different elements.

Javascript

executeJS :: (WebDriver wd, 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 :: (WebDriver wd, 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

currentWindow :: WindowHandleSource

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

getCurrentWindow :: WebDriver wd => wd WindowHandleSource

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.

data FrameSelector Source

Specifies the frame used by focusFrame

Constructors

WithIndex Integer 
WithName Text

focus on a frame by name or ID

WithElement Element

focus on a frame Element

DefaultFrame

focus on the first frame, or the main document if iframes are used.

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

cookName :: Text
 
cookValue :: Text
 
cookPath :: Maybe Text

path of this cookie. if Nothing, defaults to /

cookDomain :: Maybe Text

domain of this cookie. if Nothing, the current pages domain is used

cookSecure :: Maybe Bool

Is this cookie secure?

cookExpiry :: Maybe Integer

Expiry date expressed as seconds since the Unix epoch Nothing indicates that the cookie never expires

mkCookie :: Text -> Text -> CookieSource

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 TextSource

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.

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 aSource

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

As of Selenium 2.21, Web Storage is only supported on iOS and Android platforms

storageSize :: WebDriver wd => WebStorageType -> wd IntegerSource

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 TextSource

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 TextSource

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.

Mobile device support

Screen orientation

getOrientation :: WebDriver wd => wd OrientationSource

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.

touchFlickFromSource

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

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.

uploadRawFileSource

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

serverStatus :: WebDriver wd => 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