
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
expect-protractor
Advanced tools
> 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.
expect-protractor is a library which provides a light-weight matchers for the Protractor and Jasmine test frameworks.
To use expect-protractor in your project, run:
npm i -D expect-protractor
Add the expect-protractor module to the your protractor.config.js
file in the onPrepare
function and wrap it into the beforeEach
function.
// importing module
const customMatchers = require('expect-protractor');
exports.config = {
onPrepare() {
// add matchers in the beforeEach hook
beforeEach(() => jasmine.addMatchers(customMatchers));
},
};
// 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"]
}
}
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');
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);
expect-protractor is MIT licensed.
FAQs
> 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.
We found that expect-protractor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.