expect-protractor
expect-protractor is a library which provides a light-weight matchers for the Protractor and Jasmine test frameworks.
Table of Contents
Getting Started
Installation
To use expect-protractor in your project, run:
npm i -D expect-protractor
Importing and Adding
Add the expect-protractor module to the your protractor.config.js
file in the onPrepare
function and wrap it into the beforeEach
function.
protractor.config.js
// importing moduleconst customMatchers = ; exportsconfig = { // add matchers in the beforeEach hook ; };
protractor.config.ts
// importing module; exports.config =;
Also you can add the expect-protractor module directly in your test.
// importing moduleconst customMatchers = ; ;
Also, if you are faced with the TypeScript compilation errors when running your tests, add the typeRoots entry in the tsconfig.json, with the right order:
Usage
Example - asserting element's text with toHaveText
function that comes with the expect-protractor library.
Without the expect-protractor library:
;
After adding the expect-protractor library:
await ;
Example - asserting element's value with toHaveValue
function that comes with the expect-protractor library.
Without the expect-protractor library:
;
After adding the expect-protractor library:
await ;
API
toBeDisplayed - verifies that element is displayed on the page.
Example:
await ;
toBePresent - verifies that element is present in the DOM.
Example:
await ;
toContainText - verifies that element contains text.
Example:
await ;
toHaveText - verifies element's text.
Example:
await ;
toContainValue - verifies that element contains value.
Example:
await ;
toHaveValue - verifies element's value.
Example:
await ;
toHaveAttribute - verifies element has an attribute .
Example:
await ;
toHaveCssValue - verifies element has an css value .
Example:
await ;
toContainCssValue - verifies element contains an css value .
Example:
await ;
toBeDisabled - verifies that element is disabled.
Example:
await ;
toBeSelected - verifies that element is selected(checked).
Example:
await ;
toHaveLink - verifies element's link(href attribute).
Example:
await ;
toContainLink - verifies element contains link(href attribute).
Example:
await ;
toContainClass - verifies element contains class names.
Example:
await ;
toHaveCount - verifies element's length.
Example:
await ;
toBeClickable - verifies element is clickable.
Example:
await ;
toHaveTitle - verifies title.
Example:
await ;
toContainTitle - verifies that title contains text.
Example:
await ;
toHaveUrl - verifies current url.
Example:
await ;
toContainUrl - verifies that current url contains text.
Example:
await ;
toHaveWindowsCount - verifies window tabs count.
Example:
await ;
toHaveWindowsCountMoreThan - verifies window tabs count greater than.
Example:
await ;
toHaveWindowsCountLessThan - verifies window tabs count less than.
Example:
await ;
License
expect-protractor is MIT licensed.