Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Latest commit

 

History

History
208 lines (148 loc) · 6.15 KB

Browser.md

File metadata and controls

208 lines (148 loc) · 6.15 KB

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/chrome"
export default () => {
  step("Start", async browser => {
    await browser.visit("https://challenge.flood.io")
  })
}

browser.authenticate([, username, password])

  • username (Optional)
  • password (Optional)
  • returns: <Promise>

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.

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.press(keyCode[, options])

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

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.setUserAgent(userAgent)

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.type(locatable, text[, options])

  • locatable <Locatable>
  • text
  • options <{"delay":"number"}> (Optional)
  • returns: <Promise>

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"), "[email protected]")
})

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

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.

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.