# Macros

# checkbox

# checkbox(driver, selector, set, maxMs, tries) ⇒ Promise.<*>

Checks or unchecks a checkbox based on set parameter

Returns: Promise.<*> - returns the webdriver element

Param Description
driver webdriver instance
selector selector to find
set boolean true/false value to set checkbox to or ensure its already set to
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.checkbox(driver, 'input[type="checkbox"]', true);

# clear

# clear(driver, selector) ⇒ Promise

Clear a given text field

Returns: Promise - returns the webdriver element

Param Description
driver webdriver instance
selector selector to find

Example

await macro.clear(driver, 'input[type="email"]');

# click

# click(driver, selector, maxMs, tries) ⇒ Promise

Gets an element via getElement, clicks on it

Returns: Promise - The webdriver element that was clicked

Param Description
driver webdriver instance
selector selector to find
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.click(driver, '#id-of-element');
await macro.click(driver, '#id-of-element', 10000);
await macro.click(driver, '#id-of-element', 10000, 10);

# clickByPartialText

# clickByPartialText(driver, text, maxMs, tries) ⇒ Promise

Click an element by the partial text inside it

Returns: Promise - The webdriver element that was clicked

Param Description
driver webdriver instance
text substring (case sensitive) to match the element to be clicked.
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.clickByPartialText(driver, 'Partial Text');
await macro.clickByPartialText(driver, 'Partial Text', 10000);
await macro.clickByPartialText(driver, 'Partial Text', 10000, 10);

# clickByText

# clickByText(driver, text, maxMs, tries) ⇒ Promise

Click an element by the exact text inside it (gets first one)

Returns: Promise - The webdriver element that was clicked

Param Description
driver webdriver instance
text exact text (case sensitive) inside the element to be clicked
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.clickByText(driver, 'Exact Text');
await macro.clickByText(driver, 'Exact Text', 10000);
await macro.clickByText(driver, 'Exact Text', 10000, 10);

# confirmPrompt

# confirmPrompt(driver, maxMs) ⇒ Promise.<boolean>

Confirm/Accept a prompt that pops up. Will try at one second interval for up to maxMs milliseconds

Returns: Promise.<boolean> - returns true if confirmed, false if nothing confirmed.

Param Description
driver webdriver instance
maxMs maximum amount of time to wait

Example

await macro.confirmPrompt(driver);
await  macro.confirmPrompt(driver, 30000);

# csvParse

# csvParse(path) ⇒ Promise

Read and parse the CSV file found at path using NodeCSV parse

Param Description
path path to CSV file on file system

Example

const csvData = await macro.csvParse(path);
for (const row of csvData) {
  logger.info(row);
}

# csvWrite

# csvWrite(data, filename) ⇒ Promise

Write CSV data to a temporary file

Returns: Promise - path to the written file

Param Description
data CSV data to write
filename optional filename

Example

const path = await macro.csvWrite(csvData);
const fullPath = await macro.csvWrite(csvData, 'mycsv.csv');

# dismissAlert

# dismissAlert(driver, maxMs) ⇒ Promise.<boolean>

Close alert that pops up. Will wait up to maxMs.

Returns: Promise.<boolean> - returns true if alert closed, false if nothing closed.

Param Description
driver webdriver instance
maxMs maximum amount of time to wait

Example

await macro.dismissAlert(driver);
await macro.dismissAlert(driver, 30000);

# downloadFile

# downloadFile(url, filename, headers) ⇒ Promise

Downloads a file from URL provided and stores it in the /tmp directory returns the filepath

Returns: Promise - filepath of the file

Param Description
url URL of file to download
filename (optional) filename to save as in /tmp directory
headers (optional) custom HTTP headers

Example

const path = await macro.downloadFile('https://example.com/file.txt');
const fullPath = await macro.downloadFile('https://example.com/file.txt', 'myfile.txt');
const customHeader = await macro.downloadFile('https://example.com/file.txt', 'myfile.txt', {'custom-header': 'Hello'});

# downloadFileBrowser

# downloadFileBrowser(driver, url, filename) ⇒ Promise

Downloads a file from URL provided via the browser (keeping session intact) and stores it in the download directory with filename

Returns: Promise - filepath of the file

Param Description
driver webdriver instance
url URL of file to download
filename (optional) filename to save as in /tmp directory
const path = await macro.downloadFileBrowser(driver, 'https://example.com/file.txt');
const fullPath = await macro.downloadFileBrowser(driver, 'https://example.com/file.txt', 'myfile.txt');

# dragAndDrop

# dragAndDrop(src, dst) ⇒ Promise

Drag and one element onto another.

Param Description
src source webdriver element
dst target webdriver element

Example

const dragMe = await macro.getElementByText(driver, 'Let\'s Get Started');
const dests = await macro.getElements(driver, '.drag-handle');
const target = dests[2]; // move it over
await macro.dragAndDrop(driver, dragMe, target);

# dragAndDropFile

# dragAndDropFile(driver, targetSelector, fileUrl, filename) ⇒ Promise

Drag and drop a file (downloads url) and drops on target selector's element

Returns: Promise - returns the target webelement

Param Description
driver webdriver instance
targetSelector CSS selector of the drop target usually a file input
fileUrl URL of the file to download and drop
filename optional filename to save file as

Example

await macro.dragAndDropFile(driver, 'div[filedrop]', 'https://example.com/example.png');
await macro.dragAndDropFile(driver, 'input[type="file"]', 'https://example.com/example.png', 'myfile.png');

# elementContains

# elementContains(driver, selector, text, maxMs) ⇒ Promise

From the element found by selector, look for a child element with text that matches text Will wait up to maxMs or the default wait time

Param Description
driver webdriver instance
selector CSS selector
text Text to find on the page somewhere
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.elementContains(driver, 'table.example-table', 'Company XYZ');
await macro.elementContains(driver, 'table.example-table', 'Company XYZ', 60000);

# enter

# enter(driver, selector, keys, maxMs, tries) ⇒ Promise

Clear and then type into an element

Returns: Promise - the element

Param Description
driver webdriver instance
selector selector to find
keys keys to type Can also use Key.Chord
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.enter(driver, '#text-input', 'Hello World');
await macro.enter(driver, '#text-input', 'Hello World', 20000);
await macro.enter(driver, '#text-input', 'Hello World', 20000, 5);

# fileExists

# fileExists(exactFilename, maxMs) ⇒ Promise

Checks for the presence of a downloaded file in the temporary directory.

Returns: Boolean true if file exists, false if the file does not exist

Param Description
exactFilename exact filename that was downloaded (/tmp/ is prepended to this)

Example

await macro.fileExists('file.csv');
await macro.fileExists('file.csv', 30000);

# freshTab

# freshTab(driver) ⇒ string

Open a new tab and close the old one

Param
driver

Example

await macro.freshTab(driver);

# get

# get(driver, url, maxMs) ⇒ Promise.<*>

Gets the URL provided but will time out after maxMs

Param Description
driver webdriver element
url URL to get
maxMs max milliseconds to wait until throwing an error

Example

await macro.get(driver, 'https://bionicmetrics.com');
await macro.get(driver, 'https://bionicmetrics.com', 30000);

# getActions

# getActions(driver) ⇒ Promise.<*>

Gets the webdriver actions in bridge mode. See: Actions API Documentation

Returns: Promise.<*> - actions

Param Description
driver webdriver element

Example

const actions = await macro.getActions(driver);
await actions.click(target)
    .sendKeys(Key.chord(Key.HOME))
    .keyDown(Key.SHIFT)
    .sendKeys(Key.END)
    .keyUp(Key.SHIFT)
    .perform();

# getChildElement

# getChildElement(driver, parent, selector, maxMs) ⇒ Promise

Gets a child element of parent webelement by css selector waits for it to be located and visible default timeout is 15 seconds

Returns: Promise - the element

Param Description
driver webdriver instance
parent parent webdriver element
selector CSS selector of the child
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const parent = await macro.getElement(driver, '.parent-element');
const child = await macro.getChildElement(driver, parent, '.child-selector');
const child = await macro.getChildElement(driver, parent, '.child-selector', 30000);

# getChildElementByPartialText

# getChildElementByPartialText(driver, parent, text, maxMs) ⇒ Promise

Get an element by the partial text inside within the scope of the parent WebElement (e.g. child of parent)

Returns: Promise - the element

Param Description
driver webdriver instance
parent webelement of parent
text case-sensitive partial text inside the child element to get
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const parent = await macro.getElement(driver, '.parent-element');
const child = await macro.getChildElementByPartialText(driver, parent, 'Partial Text');
const child = await macro.getChildElementByPartialText(driver, parent, 'Partial Text', 30000);

# getChildElementByText

# getChildElementByText(driver, parent, text, maxMs) ⇒ Promise

Get an element by the text inside within the scope of the parent WebElement (e.g. child of parent)

Returns: Promise - the element

Param Description
driver webdriver instance
parent webelement of parent
text exact case-sensitive text inside the child element to get
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const parent = await macro.getElement(driver, '.parent-element');
const child = await macro.getChildElementByText(driver, parent, 'Exact Text');
const child = await macro.getChildElementByText(driver, parent, 'Exact Text', 30000);

# getClipboardContent

# getClipboardContent() ⇒ Promise

Returns the current contents of the clipboard

Param Description
driver webdriver instance

Example

const content = await macro.getClipboardContent();
logger.info(`Content is : ${content}`);

# getCurrentUrl

# getCurrentUrl(driver) ⇒ Promise.<(!Promise.<string>|Promise.<*>)>

Return the current URL of the browser

Param Description
driver webdriver instance

Example

const url = await macro.getCurrentUrl(driver);
logger.info(`Current URL is : ${url}`);

# getElement

# getElement(driver, selector, maxMs) ⇒ Promise

Gets an element by css selector waits for it to be located and visible

Returns: Promise - the element

Param Description
driver webdriver instance
selector selector to find
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const el = await macro.getElement(driver, '#id-of-element');
const el = await macro.getElement(driver, 'input[type="file"]', 15000);

# getElementByPartialText

# getElementByPartialText(driver, text, maxMs) ⇒ Promise

Get an element by a partial string match. Case sensitive.

Returns: Promise - the element

Param Description
driver webdriver instance
text case-sensitive partial text inside the target element
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const el = await macro.getElementByPartialText(driver, 'Partial Text of Element');
const el = await macro.getElementByPartialText(driver, 'Partial Text', 15000);

# getElementByText

# getElementByText(driver, text, maxMs) ⇒ Promise

Get an element by the text inside. Case sensitive.

Returns: Promise - the element

Param Description
driver webdriver instance
text case-sensitive exact text inside the target element
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const el = await macro.getElementByText(driver, 'Exact Text of Element');
const el = await macro.getElementByText(driver, 'Exact Text', 15000);

# getElementText

# getElementText(driver, selector, maxMs) ⇒ Promise.<String>

Get an element's text content so

Hello There
and the examples below will return "Hello There"

Returns: Promise.<String> - a string value of the element's text content

Param Description
driver webdriver instance
selector CSS selector
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const textContent = await macro.getElementText(driver, '#myElement');
const textContent = await macro.getElementText(driver, '#myElement', 40000);

# getElements

# getElements(driver, selector, maxMs) ⇒ Promise

Get elements by css selector

Returns: Promise - an array of the webdriver elements that match the CSS selector

Param Description
driver webdriver instance
selector CSS selector to match
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const els = await macro.getElements(driver, 'tr');
const els = await macro.getElements(driver, '.some-css-class', 10000);
logger.info(`There are ${els.length} elements`);

# getEnabledElement

# getEnabledElement(driver, selector, maxMs) ⇒ Promise

Get an element by CSS selector and wait until it is enabled.

Returns: Promise - the element

Param Description
driver webdriver instance
selector CSS selector
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const el = await macro.getEnabledElement(driver, 'button.css-class');
const el = await macro.getEnabledElement(driver, 'button.css-class', 10000);

# getEnabledElementByText

# getEnabledElementByText(driver, text, maxMs) ⇒ Promise

Get an element by exact text and wait for it to be enabled

Returns: Promise - the element

Param Description
driver webdriver instance
text exact text inside the element to get
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const el = await macro.getEnabledElementByText(driver, 'Exact Text');
const el = await macro.getEnabledElementByText(driver, 'Exact Text', 10000);

# getHtml

# getHtml(driver, element) ⇒ Promise.<String>

Get the html of the element (getAttribute('outerHTML'))

Returns: Promise.<String> - String representation of the element

Param Description
driver webdriver instance
element the webelement

Example

const el = await macro.getElement(driver, '#some-id');
const html = await macro.getHtml(driver, el);
logger.info(html);

# getInputValue

# getInputValue(driver, selector, maxMs) ⇒ Promise.<String>

Get the value of an input via the selector and return the current value for the input.

Returns: Promise.<String> - a string value of the input

Param Description
driver webdriver instance
selector CSS selector
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const inputValue = await macro.getInputValue(driver, '#myInput');
const inputValue = await macro.getInputValue(driver, '#myInput', 40000);

# getParentElement

# getParentElement(driver, selector, maxMs) ⇒ Promise

Get the immediate parent of the element found via CSS selector

Returns: Promise - the parent of the element found by the selector

Param Description
driver webdriver instance
selector CSS selector
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const parent = await macro.getParentElement(driver, '.child-element');
const parent = await macro.getParentElement(driver, '.child-element', 40000);

# getParent

# getParent(driver, child, levels) ⇒ Promise

Gets the immediate parent of the child passed in

Param Description
driver webdriver instance
child webelement of which to get parent
levels number parents to go up (e.g. 2 will go up two parents) if omitted default is 1

Example

const child = await macro.getElement(driver, '.child');
const parent = await macro.getParent(driver, child);
const get5Parent = await macro.getParent(driver, '.child-element', 5); // 5 layers up

# getPdfText

# getPdfText(url) ⇒ Promise

Get a PDF at URL, extract all its text and return it

Returns: Promise - returns a string with all text of the PDF

Param Description
url of the target PDF

Example

const pdfText = await macro.getPdfText('https://example.com/test.pdf');
logger.info(pdfText);

# getPdfTextFile

# getPdfTextFile(path) ⇒ Promise

Get a PDF at file path, extract all its text and return it

Returns: Promise - returns a string with all text of the PDF

Param Description
path of the target PDF on the local file system

Example

const pdfText = await macro.getPdfText('/tmp/file.pdf');
logger.info(pdfText);

# getSimpleUrlDate

# getSimpleUrlDate() ⇒ string

Get a string date of the current date in simple string format e.g. 05-2019 Example

logger.info(await macro.getSimpleUrlDate());

# guid

# guid(len) ⇒ string

Generate and return a guid

Returns: uuidv4 guid shortened to len characters

Param Description
len optional length to strip up to maxlen of uuidv4

Example

const guid8 = await macro.guid(8);
const full = await macro.guid();

# highlightLine

# highlightLine(driver, selector, maxMs) ⇒ Promise

Get the element by selector, then use actions to go to the beginning of the line and shift-highlight the line

Returns: Promise - the target element

Param Description
driver webdriver element
selector target element to perform these on
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.highlightLine(driver, 'p.editor');

# highlightLines

# highlightLines(driver, selector, lines, maxMs) ⇒ Promise

Get the element by selector, then use actions to go to the beginning of the line and shift-highlight the line for N lines

Returns: Promise - the target element

Param Description
driver webdriver element
selector target element to perform these on
lines number of lines to highlight
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.highlightLines(driver, 'p.editor', 5);

# hover

# hover(driver, selector, maxMs) ⇒ Promise

Hover over the element found by selector

Param Description
driver webdriver instance
selector CSS selector of element to hover over
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.hover(driver, 'header.navbar-css');

# inputFile

# inputFile(driver, selector, url, filename) ⇒ Promise.<*>

Download and input a file into a file input

Param Description
driver webdriver instance
selector CSS selector for input[type="file"]
url URL of the file to download and then input
filename optional filename to use when downloading the file

Example

await macro.inputFile(driver, 'input[type="file"]', 'https://example.com/file.txt');

# inputLocalFile

# inputLocalFile(driver, selector, path) ⇒ Promise.<*>

Download and input a file into a file input

Param Description
driver webdriver instance
selector CSS selector for input[type="file"]
path /tmp path of the local file

Example

await macro.inputLocalFile(driver, 'input[type="file"]', '/tmp/file.txt');

# isodate

# isodate() ⇒ string

Get an ISO 8601 Date String of current date Example

logger.info(`ISO: ${await macro.isodate()}`);

# newman

# newman(collectionUrlOrJson, options) ⇒ Promise

Run a Postman collection using Newman

Param Description
collectionUrlOrJson URL to collection JSON or direct JSON exported from Postman
options Options for Newman - Documentation

Returns: Promise resolving to {summary, htmlUrl, jsonUrl}

Return Object Description
summary Summary object returned by Newman - Documentation
htmlUrl URL of the html report for the run
jsonUrl URL of the JSON report for the run

Guide: Newman Guide

Example

// Using URL for collection
const collectionUrl = 'https://url-to-collection/collection.json';
const options = {}; // https://github.com/postmanlabs/newman#newmanrunoptions-object--callback-function--run-eventemitter
const {summary, htmlUrl, jsonUrl} = await macro.newman(collectionUrl, options);

// Using JSON directly
const collection = {/*postman collection v2.1*/}
const newmanOptions = {}; // https://github.com/postmanlabs/newman#newmanrunoptions-object--callback-function--run-eventemitter
const {summary, htmlUrl, jsonUrl} = await macro.newman(collectionUrl, collection)

# pageContains

# pageContains(driver, text, maxMs) ⇒ Promise

Waits until the page contains some text, throws error if text is not found within the wait time.

Param Description
driver webdriver instance
text Text to find on the page somewhere
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.pageContains(driver, 'Lorem');
await macro.pageContains(driver, 'Hello There', 30000);

# qrCode

# qrCode(driver) ⇒ String

Scans the visible page for a QR Code. If a QR Code is found, it is scanned and the QR code value is returned.

Returns: String - String value of QR Code scanned

Param Description
driver webdriver instance

Example

const qrString = await macro.qrCode(driver);

# randomNumber

# randomNumber(digits) ⇒ number

Get random number of N digits

Returns: number - random number of N digits

Param Description
digits number of digits for the number e.g. 5 may return 12345

Example

const rn = await macro.randomNumber(10);

# readFile

# readFile(path) ⇒ Promise

Reads the file at path and returns its text contents

Param
path

Example

const text = await macro.readFile('/tmp/file.txt');
logger.info(text);

# refresh

# refresh(driver) ⇒ Promise

Refresh the current page

Param Description
driver webdriver instance

Example

await macro.refresh(driver);

# scopedClick

# scopedClick(driver, parent, selector, maxMs, tries) ⇒ Promise

Clicks on the element selected by selector that is a child of the web element parent

Returns: Promise - the element that was clicked

Param Description
driver webdriver instance
parent Parent element of the scope
selector CSS selector of element to click
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

const parent = await macro.getElement(driver, '.parent-element');
await macro.scopedClick(driver, parent, '.child-element');
await macro.scopedClick(driver, parent, '.child-element', 10000);
await macro.scopedClick(driver, parent, '.child-element', 10000, 4);

# scopedClickByPartialText

# scopedClickByPartialText(driver, parent, text, maxMs, tries) ⇒ Promise

Click by partial text a child of parent

Returns: Promise - the element that was clicked

Param Description
driver webdriver instance
parent Parent element of the scope
text case-sensitive substring inside target element
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

const parent = await macro.getElement(driver, '.parent-element');
await macro.scopedClickByPartialText(driver, parent, 'partial text');
await macro.scopedClickByPartialText(driver, parent, 'partial text', 10000);
await macro.scopedClickByPartialText(driver, parent, 'partial text', 10000, 4);

# scopedClickByText

# scopedClickByText(driver, parent, text, maxMs, tries) ⇒ Promise

Click by exact text a child of parent

Returns: Promise - the element that was clicked

Param Description
driver webdriver instance
parent Parent element of the scope
text case-sensitive exact text inside target element
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

const parent = await macro.getElement(driver, '.parent-element');
await macro.scopedClickByText(driver, parent, 'exact text');
await macro.scopedClickByText(driver, parent, 'exact text', 10000);
await macro.scopedClickByText(driver, parent, 'exact text', 10000, 4);

# scopedType

# scopedType(driver, parent, selector, keys, maxMs, tries) ⇒ Promise

Gets an element via getChildElement, clicks on it, and types

Returns: Promise - the element

Param Description
driver webdriver instance
parent parent element of the scope
selector selector to find
keys keys to type Can also use Key.Chord
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

const parent = await macro.getElement(driver, '.parent-element');
await macro.scopedType(driver, parent, '.child-element', 'text to type');
await macro.scopedType(driver, parent, '.child-element', 'text to type', 10000);
await macro.scopedType(driver, parent, '.child-element', 'text to type', 10000, 4);

# screenCapture

# screenCapture(driver, name) ⇒ Promise

Take a screenshot and append it to the results for this test.

Returns: Promise - returns a promise that resolves when screenshot is finished and uploaded

Param Description
driver webdriver instance
name optional name of screenshot

Example

await macro.screenCapture(driver);
await macro.screenCapture(driver, 'Screen Capture of Sign Up Screen'); // optional title for screenshot

# scrollTo

# scrollTo(driver, target, verticalOffset) ⇒ Promise.<*>

Scroll to target webelement

Returns: Promise.<*> - returns target

Param Description
driver webdriver instance
target target element to scroll to
verticalOffset offset number of pixels

Example

const target = await macro.getElement(driver, '#scroll-to-me');
await macro.scrollTo(driver, target);
await macro.scrollTo(driver, target, 100); // offset 100 px

# setClipboardContent

# setClipboardContent(text) ⇒ Promise

Set the content of the clipboard

Returns: Promise

Param Description
text target element to scroll to

Example

await macro.setClipboardContent('Hello World');

# sleep

# sleep(ms) ⇒ Promise

Sleep for ms milliseconds

Param Description
ms miliseconds to sleep[

Example

await macro.sleep(10*1000);
await macro.sleep(driver, 5000);

# switchToPopup

# switchToPopup(driver, checkForClose, tries) ⇒ Promise

Switches to the popup that is not this window and returns the current window (so you can switch back later)

Returns: Promise - the original (main window) so you can switch back later

Param Description
driver webdriver instance
checkForClose check if the window has closed (like some oauth situations)
tries number of attempts

Example

const mainWindow = await macro.switchToPopup(driver);

# switchToWindow

# switchToWindow(driver, handle, maxMs) ⇒ Promise

Switch to the window handle provided

Param Description
driver webdriver instance
handle window handle provided
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

const mainWindow = await macro.switchToPopup(driver);
await macro.switchToWindow(driver, mainWindow);

# type

# type(driver, selector, keys, maxMs, tries) ⇒ Promise

Gets an element via get Element, clicks on it, types

Returns: Promise - the element

Param Description
driver webdriver instance
selector selector to find
keys keys to type Can also use Key.Chord
maxMs maximum amount of time in milliseconds to wait until timeout.
tries will attempt this many times or 3 by default with RETRY_SLEEP_MS sleeps in between

Example

await macro.type(driver, '#target', 'text to type');
await macro.type(driver, '#target', 'text to type', 10000);
await macro.type(driver, '#target', 'text to type', 10000, 4);

# urlContains

# urlContains(driver, text, maxMs) ⇒ Promise.<*>

Wait until the url contains the provided substring, throws error if it never happens

Param Description
driver webdriver element
text substring that the url should contain
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.urlContains(driver, 'dashboard');
await macro.urlContains(driver, 'dashboard', 10000);

# waitForWindow

# waitForWindow(driver, maxMs) ⇒ Promise

Wait until getWindowHandles returns more than one handle

Param Description
driver webdriver instance
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.waitForWindow(driver);
await macro.waitForWindow(driver, 10000);

# waitUntilGone

# waitUntilGone(driver, selector, maxMs) ⇒ Promise

Wait until an element is not visible

Param Description
driver webdriver instance
selector element to wait until gone
maxMs maximum amount of time in milliseconds to wait until timeout.

Example

await macro.waitUntilGone(driver, '.modal-content');
await macro.waitUntilGone(driver, '.modal', 10000);

# year

# year() ⇒ number

Return the full current year (e.g. 2019) Example

const currentYear = await macro.year();