API

Browser

Browser

Browser is the main entry point in each step, it's your direct connection to the browser running the test.

import { step } from '@flood/element'
default () => {
  step("Start", async browser => {
    await browser.visit("https://challenge.flood.io")
  })
}

Methods

Browser.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>

Browser.blur(locator)

Removes focus from the specified DOM element.

Parameters

Browser.clear(locatable)

Clears the selected value of an input or select control.

Parameters

Browser.clearBrowserCache()

Clear browser cache.

Parameters

Browser.clearBrowserCookies()

Clear browser cookies.

Parameters

Browser.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:

step("Start", async browser => {
  await browser.click(By.partialLinkText('Start'))
})

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

Browser.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

Browser.emulateDevice(deviceName)

Configure Browser to emulate a given device

Parameters

Browser.evaluate(fn, ...args)

Parameters

  • fn [EvaluateFn][evaluatefn]
  • args any[]
  • returns: Promise<any>

Browser.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

Browser.findElements(locator)

Uses the provided locator to find all elements matching the locator condition, returning an array of ElementHandles

Parameters

Browser.focus(locator)

Makes the element located by the first argument the receiver of future input.

Parameters

Browser.highlightElement(element)

Highlight an element. Useful in concert with takeScreenshot to tweak your locators.

Parameters

Browser.maybeFindElement(locator)

Uses the provided locator to find the first element it matches, returning an ElementHandle.

Parameters

Browser.press(keyCode[, options])

Presses a key on the keyboard specified by key code. For example, [Key.ALT][key.alt]

Parameters

Browser.selectByIndex(locatable, index)

Selects an option within a <select> tag by its index in the list.

Parameters

Browser.selectByText(locatable, text)

Selects an option within a <select> tag by matching its visible text.

Parameters

Browser.selectByValue(locatable, ...values)

Selects an option within a <select> tag using the value of the <option> element.

Parameters

Browser.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:

await browser.click("#input_address")
await browser.sendKeys("Hello, World!", Key.ENTER)

Parameters

Browser.setUserAgent(userAgent)

Set Browser to send a custom User Agent (UA) string

Parameters

Browser.switchTo()

Switch the focus of the browser to another frame, tab, or window.

Parameters

Browser.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

Browser.title()

Returns the title of the current page

Parameters

Browser.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:

step("Step 1", async browser => {
  await browser.type(By.css("#email"), "user@example.com")
})

Parameters

Browser.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:

step("Start", async browser => {
  await browser.visit("https://example.com")
})

Parameters

Browser.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:

step('Start', async browser => {
  await browser.wait(Until.elementIsVisible(By.css('h1.title')))
})

You can use either a numeric value in seconds to wait for a specific time, or a Condition, for more flexible conditions.

Parameters

Browser.waitForNavigation()

Parameters

Driver

Driver is an alias to Browser. Please use Browser when possible.

Notice:

This is kept for simplifying migrations from Selenium WebDriver.js.

Locatable

Locatable represents anything able to be located, either a string selector or a Locator. Locators are generally created using By methods.

[Locator][] | [ElementHandle][] | string

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.

[Locatable][] | null

[EvaluateFn]: <>