npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expect-protractor

v1.1.0

Published

> expect-protractor is a library which provides a light-weight matchers for the [Protractor](https://github.com/angular/protractor) and [Jasmine](https://github.com/jasmine/jasmine) test frameworks.

Downloads

591

Readme

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 module
const customMatchers = require('expect-protractor');

exports.config = {
  onPrepare() {
    // add matchers in the beforeEach hook
    beforeEach(() => jasmine.addMatchers(customMatchers));
  },
};

protractor.config.ts

// importing module
import * as customMatchers from 'expect-protractor';

exports.config = {
  onPrepare() {
    // add matchers in the beforeEach hook
    beforeEach(() => jasmine.addMatchers(customMatchers));
  },
};

Also you can add the expect-protractor module directly in your test.

// importing module
const customMatchers = require('expect-protractor');

describe('Test suite', () => {
  // add matchers in the beforeEach hook
  beforeEach(() => jasmine.addMatchers(customMatchers));

  it('should verify', () => {
    // ...
  });
});

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:

{
  "compilerOptions": {
    "typeRoots": ["node_modules/expect-protractor", "node_modules/@types"]
  }
}

Usage

Example - asserting element's text with toHaveText function that comes with the expect-protractor library.

Without the expect-protractor library:

expect(await element.getText()).toBe('Some text');

After adding the expect-protractor library:

await expect(element).toHaveText('Some text');

Example - asserting element's value with toHaveValue function that comes with the expect-protractor library.

Without the expect-protractor library:

expect(await element.getAttribute('value')).toBe('Some value');

After adding the expect-protractor library:

await expect(element).toHaveValue('Some value');

API

toBeDisplayed - verifies that element is displayed on the page.

Example:

await expect(element).toBeDisplayed();

toBePresent - verifies that element is present in the DOM.

Example:

await expect(element).toBePresent();

toContainText - verifies that element contains text.

Example:

await expect(element).toContainText('text');

toHaveText - verifies element's text.

Example:

await expect(element).toHaveText('Expected text');

toContainValue - verifies that element contains value.

Example:

await expect(element).toContainValue('value');

toHaveValue - verifies element's value.

Example:

await expect(element).toHaveValue('Expected value');

toHaveAttribute - verifies element has an attribute .

Example:

await expect(element).toHaveAttribute('expected-attribute');

toHaveCssValue - verifies element has an css value .

Example:

await expect(element).toHaveCssValue({ property: 'color', value: '#000000' });

toContainCssValue - verifies element contains an css value .

Example:

await expect(element).toContainCssValue({ property: 'color', value: '#0' });

toBeDisabled - verifies that element is disabled.

Example:

await expect(element).toBeDisabled();

toBeSelected - verifies that element is selected(checked).

Example:

await expect(element).toBeSelected();

toHaveLink - verifies element's link(href attribute).

Example:

await expect(element).toHaveLink('https://expected-link.com/');

toContainLink - verifies element contains link(href attribute).

Example:

await expect(element).toContainLink('link.com');

toContainClass - verifies element contains class names.

Example:

await expect(element).toContainClass('expected-css-name');

toHaveCount - verifies element's length.

Example:

await expect(elements).toHaveCount(3);

toBeClickable - verifies element is clickable.

Example:

await expect(element).toBeClickable();

toHaveTitle - verifies title.

Example:

await expect(browser).toHaveTitle('Expected title');

toContainTitle - verifies that title contains text.

Example:

await expect(browser).toContainTitle('title');

toHaveUrl - verifies current url.

Example:

await expect(browser).toHaveUrl('https://expected.com/');

toContainUrl - verifies that current url contains text.

Example:

await expect(browser).toContainUrl('.com');

toHaveWindowsCount - verifies window tabs count.

Example:

await expect(browser).toHaveWindowsCount(2);

toHaveWindowsCountMoreThan - verifies window tabs count greater than.

Example:

await expect(browser).toHaveWindowsCountMoreThan(3);

toHaveWindowsCountLessThan - verifies window tabs count less than.

Example:

await expect(browser).toHaveWindowsCountLessThan(2);

License

expect-protractor is MIT licensed.