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-css-booster

v2.0.0

Published

custom css locators for Protractor

Downloads

2,452

Readme

What can it do?

Finding an web element using XPATH is not a right choice to make as it slows down the element finding mechanism. But, due to the lack of CSS support for multiple use cases, still XPATH use to gather some space in your testing world.

Worry not! Here comes Protractor-CSS-Booster! :hatching_chick:

protractor-css-booster is lightweight plugin to help you to find out web elements by using special custom selectors. All the custom locator uses CSS selector as an input to accomplish the task for you.

Now, you can find web elements such as:

  1. Finding Grand Parent Element
  2. Finding Parent Element
  3. Finding Next Sibling
  4. Finding Previous Sibling
  5. Finding any Following Sibling
  6. Finding First Child Element
  7. Finding Last Child Element

And, guess what, everything you can find using :collision: CSS Selectors :collision:

IE Support added from version 1.0.9

Installation

Install this module locally with the following command to be used as a (dev-)dependency:

npm install --save protractor-css-booster
npm install --save-dev protractor-css-booster

Usage

protractor-css-booster supports NodeJS 8 or higher

Configuration

protractor-css-booster can be used as a plugin in your protractor configuration file with the following code:

exports.config = {
  // ... the rest of your config
  plugins: [
    {
      // The module name
      package: "protractor-css-booster"
    }
  ]
};

Using CSS Booster

You can now have the flexibility to use protractor-css-booster in two ways - 1. using css selector 2. using prototype function (in this case you need to use await / resolve promise by "then") Refer below examples

Suppose your HTML

  <div>
      <h2>Thor's Biodata</h2>
      <div id='borr'>
         <p id="odin">
           <a id="thor"> baby thor </a>
         </p>
      </div>
      <div>
        <ul id="schoolBook">
            <li id="name">Thor</li>
            <li id="age">Million Years</li>
            <li id="home">Asgard</li>
        </ul>
      </div>

    </div>

find GrandParent:

This Locator helps to identify the grand parent element of a target element

You can find the grand parent by:

const target = await element(by.css("#schoolBook")).grandParent(); // returns <div id='borr'> <p id="odin"> <a id="thor"> baby thor </a></p></div>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.grandParentOf("#schoolBook")); // returns <div id='borr'> <p id="odin"> <a id="thor"> baby thor </a></p></div>

find Parent:

This Locator helps to identify the parent element of a target element

You can find the parent by:

const target = await element(by.css("#thor")).parent(); // returns <p id="odin"><a id="thor"> baby thor </a> </p>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.parentOf("#thor")); // returns  <p id="odin"><a id="thor"> baby thor </a> </p>
target.click(); //proceed with your desired operation

find Next Sibling:

The nextSiblingOf locator returns the node immediately following the specified node, in the same tree level.

You can find the next sibling by:

const target = await element(by.css("#name")).nextSibling(); // returns <li id="age">Million Years</li>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.nextSiblingOf("#name")); //  returns <li id="age">Million Years</li>
target.click(); //proceed with your desired operation

find Previous Sibling:

The prevSiblingOf locator returns the previous element of the specified element, in the same tree level.

You can find the previous sibling by:

const target = await element(by.css("#age")).prevSibling(); // returns <li id="name">Thor</li>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.prevSiblingOf("#age")); // returns <li id="name">Thor</li>
target.click(); //proceed with your desired operation

find Following Sibling:

The followingSibling locator returns the following sibling of a given element. This should always be used with element chain as the second element finder.

It will help you to omit the xpath's //following-sibling:: dependency

You can find the following sibling by:

const target = await element(by.css("#name")).nextSibling(); // returns <li id="age">Million Years</li>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.cssContainingText("#name", "Thor")).element(
  by.followingSibling("#age")
); // returns <li id="age">Million Years</li>

find First Child:

The firstChildOf locator returns the first child element of the specified element.

You can find the first child by:

const target = await element(by.css("#schoolBook")).firstChild(); // returns <li id="name">Thor</li>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.firstChildOf("#schoolBook")); // returns <li id="name">Thor</li>
target.click(); //proceed with your desired operation

find Last Child:

The lastChildOf locator returns the last child element of the specified element.

You can find the last child by:

const target = await element(by.css("#schoolBook")).lastChild(); // returns <li id="home">Asgard</li>
target.click(); //proceed with your desired operation

Or you can use as by-locator style,

const target = element(by.lastChildOf("#schoolBook")); // returns <li id="home">Asgard</li>
target.click(); //proceed with your desired operation

Sample Test Files:

Using prototype function sample test cases can be found here

using as "by-locator" sample test cases can be found here

Tell me your issues

you can raise any issue here

Contribution

Any pull request is welcome keeping proper code structure.

If works for you, kindly give a star. :star2:

- Copyright © 2019- Abhinaba Ghosh