# Built-Ins

In both the context of a test or a module. Bionic Metrics provides certain built-in modules that can be referenced and used.

This is a non-exhaustive list with links to documentation for various built-ins:

# macro - Documentation

Macros are Bionic Metrics maintained functions for performing a wide variety of actions.

# logger

The logger allows you to log messages both to a test and these messages are also streamed to the Dashboard for real-time feedback.

Examples:

logger.log('Log message');
logger.info('Info message');
logger.warn('Warning message');
logger.error(`Error message ${error.toString}`);
logger.verbose('Verbose message');

# data

The data object is initialized by the inputs to a test suite and can hold data like usernames and passwords.

Data initialized in a setup suite will be available to the tests. The data is always initialized by the parent suite - when cleanup and setup suites are used, inputs on those suites are ignored in liue of using the parent suite's data inputs.

Data can be passed from test to test in serial execution mode; but this is not recommended. We recommend making your tests independent and idempotent so that they can be run in parallel and unordered.

Data set by test(s) is available and passed to the cleanup suite. This is useful for things like cleaning up created users or other assets that may have auto-generated values.

# Example

logger.info(data.username); // assumes username is a suite input.

# driver, By, until, Key - Documentation

Selenium-Webdriver built ins are available for direct use, but we recommend using the Bionic Metrics macros whereever possible.

# axios - Documentation

Axios is fantastic promise-based HTTP client for Node JS. It is useful for any type of API communication or testing

# email - Documentation

Methods for receiving emails are documented in another guide liked here

# setTargetVersion

If your application under test has a version string or Git Hash or this is available via an API request, you can set the target version found for this test using setTargetVersion and it will appear on your dashboard as well as your results as a filterable property of the result.

# Example

const version = '7.0.2/2020-06-05-1620/staging'; // extracted from an HTML element or an API request
setTargetVersion(version);

Set Target Version

Set Target Version Result

# expect - Documentation

Jest's expect can be used to complex assertions with nicely formatted error messages and exceptions.

# xpath, x

Bionic Metrics Macros by default expect a CSS Selector, but an xpath can also be provided to a macro:

# Example

await macro.click(driver, xpath('//*[@id="id"]'));
await macro.click(driver, x('//*[@id="id"]'));

If you have any questions, please contact us on Slack or support@bionicmetrics.com