Safe Haskell | Safe-Infered |
---|
Test.WebDriver.Commands
Contents
Description
This module exports basic WD actions that can be used to interact with a browser session.
- createSession :: Capabilities -> WD WDSession
- closeSession :: WD ()
- sessions :: WD [(SessionId, Capabilities)]
- getCaps :: WD Capabilities
- openPage :: String -> WD ()
- forward :: WD ()
- back :: WD ()
- refresh :: WD ()
- getCurrentURL :: WD String
- getSource :: WD Text
- getTitle :: WD Text
- screenshot :: WD ByteString
- setImplicitWait :: Integer -> WD ()
- setScriptTimeout :: Integer -> WD ()
- setPageLoadTimeout :: Integer -> WD ()
- newtype Element = Element Text
- data Selector
- findElem :: Selector -> WD Element
- findElems :: Selector -> WD [Element]
- findElemFrom :: Element -> Selector -> WD Element
- findElemsFrom :: Element -> Selector -> WD [Element]
- click :: Element -> WD ()
- submit :: Element -> WD ()
- getText :: Element -> WD Text
- sendKeys :: Text -> Element -> WD ()
- sendRawKeys :: Text -> Element -> WD ()
- clearInput :: Element -> WD ()
- attr :: Element -> Text -> WD (Maybe Text)
- cssProp :: Element -> Text -> WD (Maybe Text)
- elemPos :: Element -> WD (Int, Int)
- elemSize :: Element -> WD (Word, Word)
- isSelected :: Element -> WD Bool
- isEnabled :: Element -> WD Bool
- isDisplayed :: Element -> WD Bool
- tagName :: Element -> WD Text
- activeElem :: WD Element
- elemInfo :: Element -> WD Value
- (<==>) :: Element -> Element -> WD Bool
- (</=>) :: Element -> Element -> WD Bool
- executeJS :: FromJSON a => [JSArg] -> Text -> WD a
- asyncJS :: FromJSON a => [JSArg] -> Text -> WD (Maybe a)
- data JSArg = forall a . ToJSON a => JSArg a
- newtype WindowHandle = WindowHandle Text
- currentWindow :: WindowHandle
- getCurrentWindow :: WD WindowHandle
- closeWindow :: WindowHandle -> WD ()
- windows :: WD [WindowHandle]
- focusWindow :: WindowHandle -> WD ()
- maximize :: WD ()
- getWindowSize :: WD (Word, Word)
- setWindowSize :: (Word, Word) -> WD ()
- getWindowPos :: WD (Int, Int)
- setWindowPos :: (Int, Int) -> WD ()
- focusFrame :: FrameSelector -> WD ()
- data FrameSelector
- data Cookie = Cookie {}
- mkCookie :: Text -> Text -> Cookie
- cookies :: WD [Cookie]
- setCookie :: Cookie -> WD ()
- deleteCookie :: Cookie -> WD ()
- deleteVisibleCookies :: WD ()
- getAlertText :: WD Text
- replyToAlert :: Text -> WD ()
- acceptAlert :: WD ()
- dismissAlert :: WD ()
- moveTo :: (Int, Int) -> WD ()
- moveToCenter :: Element -> WD ()
- moveToFrom :: (Int, Int) -> Element -> WD ()
- clickWith :: MouseButton -> WD ()
- data MouseButton
- mouseDown :: WD ()
- mouseUp :: WD ()
- withMouseDown :: WD a -> WD a
- doubleClick :: WD ()
- data Orientation
- getOrientation :: WD Orientation
- setOrientation :: Orientation -> WD ()
- getLocation :: WD (Int, Int, Int)
- setLocation :: (Int, Int, Int) -> WD ()
- storageSize :: WebStorageType -> WD Integer
- getAllKeys :: WebStorageType -> WD [Text]
- deleteAllKeys :: WebStorageType -> WD ()
- getKey :: WebStorageType -> Text -> WD Text
- setKey :: WebStorageType -> Text -> Text -> WD Text
- deleteKey :: WebStorageType -> Text -> WD ()
- uploadFile :: FilePath -> WD ()
- uploadRawFile :: FilePath -> Integer -> ByteString -> WD ()
- uploadZipEntry :: Entry -> WD ()
- touchClick :: Element -> WD ()
- touchDown :: (Int, Int) -> WD ()
- touchUp :: (Int, Int) -> WD ()
- touchMove :: (Int, Int) -> WD ()
- touchScroll :: (Int, Int) -> WD ()
- touchScrollFrom :: (Int, Int) -> Element -> WD ()
- touchDoubleClick :: Element -> WD ()
- touchLongClick :: Element -> WD ()
- touchFlick :: (Int, Int) -> WD ()
- touchFlickFrom :: Int -> (Int, Int) -> Element -> WD ()
- availableIMEEngines :: WD [Text]
- activeIMEEngine :: WD Text
- checkIMEActive :: WD Bool
- activateIME :: Text -> WD ()
- deactivateIME :: WD ()
- serverStatus :: WD Value
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.
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
Page info
getCurrentURL :: WD StringSource
Gets the URL 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.
setPageLoadTimeout :: Integer -> WD ()Source
Sets the amount of time to wait for a page to finish loading before throwing a Timeout
exception
Web elements
An opaque identifier for a web page element.
Specifies element(s) within a DOM tree using various selection methods.
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
submit :: Element -> WD ()Source
Submit a form element. This may be applied to descendents of a form element as well.
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
cssProp :: Element -> Text -> WD (Maybe Text)Source
Retrieve the value of an element's computed CSS property
isSelected :: Element -> WD BoolSource
Determine if the element is selected.
isDisplayed :: Element -> WD BoolSource
Determine if the element is displayed.
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
)
An existential wrapper for any ToJSON
instance. This allows us to pass
parameters of many different types to Javascript code.
Windows
currentWindow :: WindowHandleSource
A special WindowHandle
that always refers to the currently focused window.
getCurrentWindow :: WD WindowHandleSource
Returns a handle to the currently focused window
closeWindow :: WindowHandle -> WD ()Source
Closes the given window
windows :: WD [WindowHandle]Source
Returns a list of all windows available to the session
focusWindow :: WindowHandle -> WD ()Source
getWindowSize :: WD (Word, Word)Source
Get the dimensions of the current window.
getWindowPos :: WD (Int, Int)Source
Get the coordinates of the current window.
Focusing on frames
focusFrame :: 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
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 -> 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.
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
Get the text of an alert dialog.
replyToAlert :: Text -> WD ()Source
Sends keystrokes to Javascript prompt() dialog.
Accepts the currently displayed alert dialog.
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.
Press and hold the left mouse button down. Note that undefined behavior occurs if the next mouse command is not mouseUp.
withMouseDown :: WD a -> WD aSource
Perform the given action with the left mouse button held down. The mouse is automatically released afterwards.
Double click at the current mouse location.
Screen orientation
data Orientation Source
A 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
HTML 5 Web Storage
storageSize :: WebStorageType -> WD IntegerSource
Get the current number of keys in a web storage area.
getAllKeys :: WebStorageType -> WD [Text]Source
Get a list of all keys from a web storage area.
deleteAllKeys :: WebStorageType -> WD ()Source
Delete all keys within a given web storage area.
getKey :: 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.
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 :: FilePath -> WD ()Source
Uploads a file from the local filesystem by its file path.
Arguments
:: 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 :: 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.
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.
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.
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.
IME support
activateIME :: Text -> WD ()Source
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