Browser
Browser
is the main entry point in each step, it's your direct connection to the browser running the test.
If you're coming from Selenium, the browser
is synonymous with the Driver interface in Selenium.
If you're coming from Puppeteer, think of the Browser as a wrapper around the Puppeteer Page object.
You don't need to create a browser instance because it is passed into each step for your, and reset after each test loop.
Methods
authenticate([, username, password])
Sets the HTTP Authentication details to use if the page is presented with an authentication prompt.
Call without any args to disable authentication.
Parameters
username
?string
(Optional)password
?string
(Optional)- returns:
Promise<void>
blur(locator)
Removes focus from the specified DOM element.
Parameters
- locator
NullableLocatable
- returns: Promise<
void
>
clear(locatable)
Clears the selected value of an input or select control.
Parameters
- locatable
NullableLocatable
- returns: Promise<
void
>
clearBrowserCache()
Clear browser cache.
Parameters
- returns: Promise<
any
>
clearBrowserCookies()
Clear browser cookies.
Parameters
- returns: Promise<
any
>
click(locatable[, options])
Sends a click event to the element located at selector
. If the element is
currently outside the viewport it will first scroll to that element.
Example:
In this example we're constructing a Locatable using the By.partialLinkText()
Locator, which will match the first <a>
tag which contains the text "Start".
Parameters
- locatable
NullableLocatable
- options?
ClickOptions
(Optional) - returns: Promise<
void
>
doubleClick(locatable[, options])
Sends a double-click event to the element located by the supplied Locator or selector
. If the element is
currently outside the viewport it will first scroll to that element.
Parameters
- locatable
NullableLocatable
- options?
ClickOptions
(Optional) - returns: Promise<
void
>
emulateDevice(deviceName)
Configure Browser to emulate a given device
Parameters
- deviceName
Device
- returns: Promise<
void
>
evaluate(fn, ...args)
Parameters
- fn <function|string> Function to be evaluated in the page context
- args
any
[] - returns: Promise<
any
>
findElement(locator)
Uses the provided locator to find the first element it matches, returning an ElementHandle. If no element is found throws an error.
Parameters
- locator
NullableLocatable
- returns: Promise<ElementHandle>
findElements(locator)
Uses the provided locator to find all elements matching the locator condition, returning an array of ElementHandles
Parameters
- locator
NullableLocatable
- returns: Promise<ElementHandle>
focus(locator)
Makes the element located by the first argument the receiver of future input.
Parameters
- locator
NullableLocatable
The Locator to use to find an element to send focus to. - returns: Promise<
void
>
highlightElement(element)
Highlight an element. Useful in concert with takeScreenshot to tweak your locators.
Parameters
- element
ElementHandle
- returns: Promise<
void
>
maybeFindElement(locator)
Uses the provided locator to find the first element it matches, returning an ElementHandle.
Parameters
- locator
NullableLocatable
- returns: Promise<Element | null>
press(keyCode[, options])
Presses a key on the keyboard specified by key code. For example, [Key.ALT][key.alt]
Parameters
- keyCode
string
- options? (Optional)
- returns: Promise<
void
>
selectByIndex(locatable, index)
Selects an option within a <select>
tag by its index in the list.
Parameters
- locatable
NullableLocatable
- index
string
- returns: Promise<
string
[]>
selectByText(locatable, text)
Selects an option within a <select>
tag by matching its visible text.
Parameters
- locatable
NullableLocatable
- text
string
- returns: Promise<
string
[]>
selectByValue(locatable, ...values)
Selects an option within a <select>
tag using the value of the <option>
element.
Parameters
- locatable
NullableLocatable
- values
string
[] - returns: Promise<
string
[]>
sendKeys(...keys)
sendKeys
simulates typing a list of strings on the keyboard.
If a string is a member of Key it is pressed individually. Otherwise the string is typed.
This allows sendKeys to simulate a user typing control keys such as Key.ENTER
.
Example:
Parameters
- keys
string
[] - returns: Promise<
void
>
sendKeyCombinations(...keys)
This will simulate the act of pressing a combination of keys on the keyboard at the same time. Use commas to separate individual keys.
SOME COMBINATIONS MAY NOT WORK ON MACOS
On MacOS, some combinations are emulated by the Operating System, instead of the browser. Therefore, you may find some combinations not working as expected, like Command + A (select all), Command + C (copy), Command + V (paste), etc. More information can be found here
Example:
setUserAgent(userAgent)
Set Browser to send a custom User Agent (UA) string
Parameters
- userAgent
string
- returns: Promise<
void
>
switchTo()
Switch the focus of the browser to another frame, tab, or window.
Parameters
- returns:
TargetLocator
takeScreenshot([, options])
Takes a screenshot of the whole page and saves it to the flood/results
folder with a random sequential name. You can download the archive of your test results at the end of the test to retrieve these screenshots.
Parameters
- options?
ScreenshotOptions
(Optional) - returns: Promise<
void
>
title()
Returns the title of the current page
Parameters
- returns: Promise<
string
>
type(locatable, text[, options])
Types a string into an <input>
control, key press by key press. Use this to fill inputs as though it was typed by the user.
Example:
Parameters
- locatable
NullableLocatable
- text
string
- options? (Optional)
- returns: Promise<
void
>
visit(url[, options])
Instructs the browser to navigate to a specific page. This is typically used as the entrypoint to your test, as the first instruction it is also responsible for creating a new Browser tab for this page to load into.
Example:
Parameters
- url
string
url to visit - options?
NavigationOptions
(Optional) puppeteer navigation options - returns: Promise<
void
>
wait(timeoutOrCondition)
Creates a waiter which will pause the test until a condition is met or a timeout is reached. This can be used for validation or control flow.
Check out Until for a rich set of wait Conditions.
Example:
You can use either a numeric value in seconds to wait for a specific time, or a Condition, for more flexible conditions.
Parameters
- timeoutOrCondition
Condition
|number
- returns: Promise<
boolean
>
waitForNavigation()
Parameters
- returns: Promise<
any
>
Locatable
Locatable represents anything able to be located, either a string selector or a <Locator>. <Locator>s are generally created using <By> methods.
NullableLocatable
NullableLocatable represents a <Locatable> which could also be null.
Note that most Element location API methods accept a NullableLocatable but will throw an <Error> if its actually <null>.
NavigationOptions
An object which might have the following properties
Properties
timeout
<number> (Optional) Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.waitUntil
<string | array> (Optional) When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:"load"
- consider navigation to be finished when the load event is fired."domcontentloaded"
- consider navigation to be finished when the DOMContentLoaded event is fired."networkidle0"
- consider navigation to be finished when there are no more than 0 network connections for at least 500 ms."networkidle2"
- consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
ScreenshotOptions
Defines the screenshot options.
Properties
clip
<Object> (Optional) An object which specifies clipping region of the page. Should have the following fields:x
<number> The x-coordinate of top-left corner of clipping area.y
<number> The y-coordinate of top-left corner of clipping area.height
<number> The height of clipping area.width
<number> The width of clipping area.
encoding
<string> (Optional) The encoding of the image, can be either"base64"
or"binary"
. Defaults tobinary
.fullPage
<boolean> (Optional) When true, takes a screenshot of the full scrollable page. Defaults to false.omitBackground
<boolean> (Optional) Hides default white background and allows capturing screenshots with transparency. Defaults tofalse
.path
<string> (Optional) The file path to save the image to. The screenshot type will be inferred from file extension.
Ifpath
is a relative path, then it is resolved relative to current working directory.
If no path is provided, the image won't be saved to the disk.quality
<number> (Optional) The quality of the image, between 0-100. Not applicable topng
images.type
<string> (Optional) Specify screenshot type, can be either"jpeg"
or"png"
. Defaults topng
.