Test.Runner.Browser
Browser automation.
This module lets you drive a real browser via the W3C WebDriver protocol.
See tests/src/Tests/Browser.gren for full usage examples.
Permissions
Subsystem permissions needed for browser tests.
You can create these manually in your program's init, or if you trust the
package to gather permissions for you, get them from the
initialize convenient function.
Convenience function to get a Permissions record.
Note: Because this is used as part of your application initialization, it
implicitly gives the package unlimited permissions. If you want more control,
you'll need to create your own Permissions record. See the
README section on Subsystems and Permissions for an example.
Running Browser Tests
Start an automated browser session.
This gives you a Session value that you can pass to the other
functions in this module that manipulate or query the session.
Options for configuring the browser session. Create with options and
customize with setVisibility and setPort.
Default options: headless browser on port 9515.
Set whether browser runs headless or with a visible window.
Set the webdriver communicaiton port (default: 9515).
Whether Chrome runs with a visible window or headless.
See setVisibility.
A browser session. You get this from withSession and is
required for the browser interaction functions.
Navigation
Get the current page URL.
Get the current page title.
Finding Elements
Find a single element by CSS selector.
Find all elements matching a CSS selector.
A reference to a DOM element found via findElement or
findElements.
Element Interaction
Click an element.
Send keystrokes to an element. Use Test.Runner.Key for special
keys like Enter, Escape, Backspace, etc.
import Test.Runner.Key as Key
-- Type text then press Enter:
Browser.sendKeys ("hello" ++ Key.enter) input session
Modifier keys (Key.shift, Key.control, Key.alt, Key.meta) are sticky —
they stay held down and apply to subsequent characters until released with
Key.null:
-- Type "HELlo" (shift held for first 3 chars, then released):
Browser.sendKeys (Key.shift ++ "hel" ++ Key.null ++ "lo") input session
Clear the contents of an input element.
Get the visible text of an element.
Get an attribute value of an element.
Screenshots
Capture a screenshot of the current viewport and save it to the given path.
Capture a screenshot of a specific element and save it to the given path.
A screenshot captured from the browser. Created by
screenshot or elementScreenshot.
Errors
Errors that can occur during a browser session.
ChromeDriverErrormeans we got an error directly from chromedriver.HttpErrormeans we got an error trying to communicate with chromedriver.FileSystemErrormeans we got an error interacting with the filesystem (e.g. saving a screenshot).