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

protractor-numerator

v1.1.6

Published

Readable functions for getting elements by their numbers inside Protractor tests

Downloads

440

Readme

protractor-numerator

Build Status npm version NPM License

This module gives you readable functions for getting elements by their numbers inside Protractor tests

Supported versions

Node.js:

  • 6.x
  • 7.x
  • 8.x
  • 9.x
  • 10.x

Protractor:

  • 4.x
  • 5.x

Installation

npm install protractor-numerator --save-dev

Importing and enabling

You can require protractor-numerator in onPrepare block inside protractor.config.js. Here is a short config example:

exports.config = {
    directConnect: true,

    framework: 'jasmine2',

    specs: [
        'spec.js'
    ],

    capabilities: {
        browserName: 'chrome'
    },

    onPrepare: function () {
        global.numerator = require('protractor-numerator').numerator;
        protractor.ElementArrayFinder.prototype = Object.assign(
            protractor.ElementArrayFinder.prototype, numerator);
        // Some other code that needs to be executed before all tests
    }
};

Usage

For example let's take a small HTML list:

<ul class="items">
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
    <li>Fourth</li>
    <li>Fifth</li>
    <li>Sixth</li>
    <li>Seventh</li>
    <li>Eighth</li>
    <li>Ninth</li>
    <li>Tenth</li>
    <li>Eleventh</li>
    <li>Twelfth</li>
    <li>Thirteenth</li>
    <li>Fourteenth</li>
    <li>Fifteenth</li>
    <li>Sixteenth</li>
    <li>Seventeenth</li>
    <li>Eighteenth</li>
    <li>Nineteenth</li>
    <li>Twentieth</li>
</ul>

Inside your Protractor end-to-end tests you can get any element of this list like this:

// Get all <li> elements from the list with class "items" and select one particular element by its number:
let listItemSecond = element.all(by.css('.items li')).second();
let listItemThird = element.all(by.xpath('//li[ancestor::*[@class="items"]]')).third();
let listItemFourth = element.all(by.css('.items li')).fourth();
let listItemFifth = element.all(by.css('.items li')).fifth();
let listItemSixth = element.all(by.css('.items li')).sixth();
let listItemSeventh = element.all(by.css('.items li')).seventh();
let listItemEighth = element.all(by.css('.items li')).eighth();
let listItemNinth = element.all(by.css('.items li')).ninth();
let listItemTenth = element.all(by.css('.items li')).tenth();
let listItemEleventh = element.all(by.css('.items li')).eleventh();
let listItemTwelfth = element.all(by.css('.items li')).twelfth();
let listItemThirteenth = element.all(by.css('.items li')).thirteenth();
let listItemFourteenth = element.all(by.css('.items li')).fourteenth();
let listItemFifteenth = element.all(by.css('.items li')).fifteenth();
let listItemSixteenth = element.all(by.css('.items li')).sixteenth();
let listItemSeventeenth = element.all(by.css('.items li')).seventeenth();
let listItemEighteenth = element.all(by.css('.items li')).eighteenth();
let listItemNineteenth = element.all(by.css('.items li')).nineteenth();
let listItemTwentieth = element.all(by.css('.items li')).twentieth();

// Now you can do whatever you want with any element for example validate its text:
expect(listItemSecond.getText()).toBe('Second');
expect(listItemThird.getText()).toBe('Third');
expect(listItemFourth.getText()).toBe('Fourth');
expect(listItemFifth.getText()).toBe('Fifth');
expect(listItemSixth.getText()).toBe('Sixth');
expect(listItemSeventh.getText()).toBe('Seventh');
expect(listItemEighth.getText()).toBe('Eighth');
expect(listItemNinth.getText()).toBe('Ninth');
expect(listItemTenth.getText()).toBe('Tenth');
expect(listItemEleventh.getText()).toBe('Eleventh');
expect(listItemTwelfth.getText()).toBe('Twelfth');
expect(listItemThirteenth.getText()).toBe('Thirteenth');
expect(listItemFourteenth.getText()).toBe('Fourteenth');
expect(listItemFifteenth.getText()).toBe('Fifteenth');
expect(listItemSixteenth.getText()).toBe('Sixteenth');
expect(listItemSeventeenth.getText()).toBe('Seventeenth');
expect(listItemEighteenth.getText()).toBe('Eighteenth');
expect(listItemNineteenth.getText()).toBe('Nineteenth');
expect(listItemTwentieth.getText()).toBe('Twentieth');

Thanks

If this plugin was helpful for you, please give it a ★ Star on Github