Webdriver.Makemodule IO : HTTP_CLIENTWebDriver is a W3C specification to remote control a web browser. This allow you to simulate and test user interactions on your website in real life conditions, with javascript enabled, on as many browsers and operating systems you can get your hands on.
type 'a io = 'a IO.tThe client I/O monad, within which communication happens with the WebDriver server.
A connection to the WebDriver server. A session statefully holds the active windows, tabs, cookies, and other state required by the browser.
module Infix : sig ... endSince the ~session parameter is generally constant, this module provides a reader monad to sequence multiple commands within the same session. You can either pass explicitly the ~session argument or open this module.
module Error : sig ... endAll potentital errors raised by the WebDriver protocol.
exception Webdriver of Error.tEvery command that fails raises this exception, which contains some hint as to what went wrong.
In order to create a session, a connection to a WebDriver-compatible browser must be established:
host is a url where the WebDriver server can be accessed, for example "http://localhost:4444".capabilities describe the requested browser settings.module Capabilities : sig ... endThe requested capabilities when creating a new session.
module Session : sig ... endFor creating and deleting sessions manually.
val run : host:string -> Capabilities.t -> 'a cmd -> 'a iorun ~host capabilities cmd is a helper function to create a new session on host with the required capabilities, execute the cmd within that session, and finally ensure that the session is deleted on termination of cmd (from its natural death or an exception.)
module Timeouts : sig ... endConfigure the timeouts for page loads, script execution and the implicit wait when searching for elements on a page.
module Wait : sig ... endEven though the browser attempts to complete most operations before giving back control, some commands might trigger too soon and raise an error. The recommended strategy is to sleep and retry the operation repeatedly until it succeeds.
val goto : string -> unit cmdgoto url ask the browser to visit the page at url.
val current_url : string cmdThe current url.
val back : unit cmdClick the browser back button, to reload the previous url in history.
val forward : unit cmdClick the forward button, to move forward to the next url in history.
val refresh : unit cmdRefresh the current url.
module Cookie : sig ... endCookies management.
type using = [ | `cssCSS selectors, like "h1 span"
| `link_textThe exact text in an <a>...</a>
| `partial_link_textThe partial text present in a link
*)| `tag_namethe HTML tag name, like "h1" or "div"
| `xpathXPath query
*) ]A strategy to find an element on a page.
find_first `using "query" returns the first element that matches the query (interpreted with using). The element is searched inside the current frame of the current window, and if a ?from parent element is provided, the search takes place inside it.
raise (Webdriver { error = `no_such_element ; _ }) otherwise.
let* elt = find_first `css "h1 a" in ...
let* elt = find_first `xpath "//h1//a" in ...find_all `using "query" behaves like find_first, but returns a list of all elements matching the query.
attribute e attr returns the value of the HTML attribute attr of the element e.
property e prop returns Some value of the DOM property prop of the element e, or None if undefined.
The boolean status of a checkbox, a radio or an option in a select.
css e prop returns the computed value of the css property prop for the element e.
aria_role e returns the accessibility role of the element e. See ARIA Roles on MDN
aria_role e returns the accessibility label of the element e. See ARIA Labels on MDN
send_keys e str sends the string str to an input element, as if typed from a keyboard. For special keys like enter or backspace, use the predefined values in the module Key:
send_keys my_input ("hello" ^ Key.enter)module Key : sig ... endSpecial keys on a keyboard.
perform actions executes the sequence of actions for each input source. The actions are synchronized vertically, such that:
perform [ mouse [ `down button0 ; `pause ; `up button0 ]
; keyboard [ `down "a" ; `up "a" ; `pause ]
]The `pause action does nothing and is used for synchronization.
The pressed keys and buttons stay pressed at the end of the interaction, unless explicitly released.
val release : unit cmdrelease any pending keys or button from previous interactions.
An inoperative device, that can be used to time the duration of each vertical frame.
val sleep : int -> unit cmdsleep duration waits for duration in milliseconds before continuing.
A typing interaction from a keyboard.
keyboard keys is an action that simulates the typing of keys from a keyboard. The currently active element will receive the key events.
val typing : string -> key listtyping keys is a helper function to produce an alternating sequence of `down key and `up key to simulate the typing of keys:
typing "ab" = [`down "a" ; `up "a" ; `down "b" ; `up "b"] The modifier Key.alt, Key.control, Key.meta and Key.shift will be pressed differently to trigger the desired shortcut:
typing (Key.control ^ "a") (* CTRL-A *)
= [`down Key.control ; `down "a" ; `up "a" ; `up Key.control]A pointer movement to a new location, taking some duration of time (in milliseconds). The default duration is a teleportation in 0ms.
val absolute : ?duration:int -> (int * int) -> moveabsolute (x, y) moves the pointer to the position (x, y) measured from the top left of the document.
val relative : ?duration:int -> (int * int) -> moverelative (dx, dy) moves the pointer by (dx, dy) from its current location.
center ~offset:(dx, dy) elt moves the pointer to the center of the element elt offsetted by offset. The default offset is (0, 0).
val button_left : buttonThe left mouse button (at position 0).
val button_middle : buttonThe middle mouse button (at position 1).
val button_right : buttonThe right mouse button (at position 2).
type pointer = [ | pause| `cancelcancel the pointer current action
*)| `down of buttonpress down the button
*)| `up of buttonrelease a pressed button
*)| `move of movemove the pointer
*) ]An action from a mouse/touch/pen device
mouse actions describes the movement, click, etc of a mouse pointer.
touch actions describes the interactions of a touch finger device. If multiple touch devices are used in the same perform, they must have different names.
val scroll_absolute : ?duration:int -> ?x:int -> ?y:int -> unit -> scrollscroll_absolute ~x ~y () resets the scrollbar such that the position x, y falls into view, as measured from the top of the page. The default value of x and y is 0.
scroll_to ~dx ~dy elt resets the scrollbar such that the center of the element elt, offsetted by (dx, dy), is inside the view. The default offset of dx and dy is 0.
val title : string cmdThe page title of the current document.
val source : string cmdThe HTML source code of the current document.
val print : string cmdThe current page, printed as a PDF.
Returns a PNG screenshot of the current page, or of the provided ?elt.
Focus the selected frame inside the current document.
`top frame is the current document root.`id n frame is the nth frame in the page.`elt e frame is the frame associated with the HTML element e.val switch_to_parent_frame : unit cmdFocus the parent of the currently selected frame.
module Window : sig ... endWindows and tabs management.
module Alert : sig ... endPopup management: alert, confirm and prompt
excute "js" runs the js on the current page, returning its result in json.
excute_async "js" runs the js asynchronously on the current page.
This function terminates when the javascript callback arguments[0] is called, and returns its parameter as json. This can be used to block until some component has initialized:
let* _ =
execute_async
{| var k = arguments[0]; something.onload(k); |}
in
(* blocks until onload triggers k *)