Permalink
Fetching contributors…
Cannot retrieve contributors at this time
302 lines (223 sloc) 10.4 KB
title

Browser

Browser (also called Driver) is the main entry point in each <step>, it's your direct connection to the browser running the test.

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

methods

Browser.authenticate([, username, password])

  • username <undefined | string> (Optional)
  • password <undefined | string> (Optional)
  • returns: <Promise<void>>

Sets the HTTP Authentication details to use if the page is presented with an authentication prompt.

Call without any args to disable authentication.

Browser.blur(locator)

Removes focus from the specified DOM element.

Browser.clear(locatable)

Clears the selected value of an input or select control.

Browser.clearBrowserCache()

Clear browser cache.

Browser.clearBrowserCookies()

Clear browser cookies.

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

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.

Browser.emulateDevice(deviceName)

Configure Browser to emulate a given device

Browser.evaluate(fn, args)

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.

Browser.findElements(locator)

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

Browser.focus(locator)

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

Browser.highlightElement(element)

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

Browser.maybeFindElement(locator)

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

Browser.press(keyCode[, options])

  • keyCode <string>
  • options <undefined | {"text":"undefined | string","delay":"undefined | number"}> (Optional)
  • returns: <Promise<void>>

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

Browser.selectByIndex(locatable, index)

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

Browser.selectByText(locatable, text)

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

Browser.selectByValue(locatable, values)

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

Browser.sendKeys(keys)

  • keys <string[]>
  • returns: <Promise<void>>

Browser.setUserAgent(userAgent)

  • userAgent <string>
  • returns: <Promise<void>>

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

Browser.switchTo()

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

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.

Browser.title()

Browser.type(locatable, text[, options])

  • locatable <NullableLocatable>
  • text <string>
  • options <undefined | {"delay":"number"}> (Optional)
  • returns: <Promise<void>>

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")
})

Browser.visit(url[, options])

  • url <string> url to visit

  • options <NavigationOptions> (Optional) puppeteer navigation options

  • returns: <Promise<void>>

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")
})

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 <Condition>s.

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.

Browser.waitForNavigation()

Driver

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

Locatable

Locatable represents anything able to be located, either a string selector or a <Locator>. <Locator>s 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

BoundingBox

properties

  • height <number> The height.
  • width <number> The width.
  • x <number> The x-coordinate of top-left corner.
  • y <number> The y-coordinate of top-left corner.

ClickOptions

properties

  • button <MouseButtons> (Optional) defaults to left
  • clickCount <number> (Optional) defaults to 1
  • delay <number> (Optional) Time to wait between mousedown and mouseup in milliseconds.
    Defaults to 0.

NavigationOptions

The navigation options.

properties

  • timeout <number> (Optional) Maximum navigation time in milliseconds, pass 0 to disable timeout.
  • waitUntil <LoadEvent | LoadEvent[]> (Optional) When to consider navigation succeeded.

ScreenshotOptions

Defines the screenshot options.

properties

  • clip <BoundingBox> (Optional) An object which specifies clipping region of the page.
  • fullPage <boolean> (Optional) When true, takes a screenshot of the full scrollable page.
  • omitBackground <boolean> (Optional) Hides default white background and allows capturing screenshots with transparency.
  • path <string> (Optional) The file path to save the image to. The screenshot type will be inferred from file extension.
    If path 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 to png images.
  • type <"jpeg" | "png"> (Optional) The screenshot type.

LoadEvent

"load" | "domcontentloaded" | "networkidle0" | "networkidle2"