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

nightwatch-ui-attributes-validator

v2.0.2

Published

This package allows you to validate the UI attributes against baseline using NightwatchJS.

Downloads

9

Readme

Validate UI attributes using NightwatchJS

This package allows you to validate the UI attributes against baseline using NightwatchJS.

What is a baseline?

A baseline is a simple JSON file that will have different elements and their attributes that we you would like to validate. You can create multiple baseline files according to your need.

A typical example of a baseline file sample1.json

[
  {
    "tag": "h2",
    "selector": "//h2[contains(text(),'HELPING MILLIONS OF SMILES')]",
    "text": "HELPING MILLIONS OF SMILES",
    "attributes": {
      "font-family": "\"Open Sans\", sans-serif",
      "font-weight": 800,
      "color": "rgb(22, 68, 107)",
      "font-size": "48px",
      "line-height": "52px",
      "letter-spacing": "normal",
      "text-transform": "uppercase",
      "display": "block"
    }
  },
  {
    "tag": "a",
    "selector": "//a[@id="tryItOn]",
    "text": "Try it On",
    "attributes": {
      "font-family": "\"Open Sans\", sans-serif",
      "font-weight": 800,
      "color": "rgb(22, 68, 107)",
      "font-size": "24",
      "line-height": "32px",
      "letter-spacing": "normal",
      "text-transform": "lowercase",
    }
  }
]
  • Version 1.0.4, supports passing a baseline file with extension js. sample2.js
module.exports = [
  {
    "tag": "span",
    "selector": "//div[@class='coh-inline-element navigation-section']/ul/li/span[text()='Products']",
    "text": "Products",
    "attributes": {
      "font-family": "\"Open Sans\", sans-serif",
      "font-weight": 600,
      "color": "rgb(26, 68, 151)",
      "font-size": "18px",
      "line-height": "26px",
      "letter-spacing": "normal",
      "display": "inline-block"
    }
  }
]
  • This package identifies elements using either of the 2 approaches
  1. By passing a unique text
[
  {
    "tag": "h2",
    "text": "HELPING MILLIONS OF SMILES",
    "attributes": {
      "font-family": "\"Open Sans\", sans-serif",
      "font-weight": 800,
    }
  },
]

Note: In the above example HELPING MILLIONS OF SMILES is an unique text on the screen

  1. By passing the exact xpath of the element
[
    {
    "tag": "a",
    "selector": "//a[@id="tryItOn]",
    "text": "Try it On",
    "attributes": {
      "font-family": "\"Open Sans\", sans-serif",
      "font-weight": 800,
    }
  }
]

Note: In the above example, the selector of an element has been defined. Also if both text and selector is provided for an element, preference is given to the selector of the element.

Configuration

  1. Install the package using command:
npm install nightwatch-UI-atrributes-validator
  1. Add custom command to the configuration of nightwatch.conf.js. You can refer the link
  custom_commands_path: [
    './node_modules/nightwatch-UI-atrributes-validator/commands'
  ]
  1. Add custom assertion to the configuration of nightwatch.conf.js. You can refer the link
  custom_assertions_path: [
    './node_modules/nightwatch-UI-atrributes-validator/assertions'
  ]
  1. Lastly pass the path of the baseline folder to the configuration, under the nightwatch.conf.js
  globals: {
    baselineDirPath : "./baseline",
  }

Usage

Types of parameters validateBaseline assertions accepts | Input types | description | | :---------- | ----------------------------------------- | | file | Can pass a js or json file path which resides under baseline folder| | array | Accepts element attributes in array format| | object | Accepts element attributes in object format|

Below are few examples:

To use the above, we simply need to use the custom command validateBaseline and it accepts 1 parameter.

  1. fileName of the baseline
describe('Verify the UI attributes of homepage', function() {
  it('Verify the UI attributes for 414 screen', function(browser) {
    browser
      .url('https://example.com/')
      .assert.validateBaseline("sample1.json") // Or .assert.validateBaseline("sample2.js")
      .end();
  });
});

Here: In the above example sample1.json is file under baseline folder. 2. attributes of the element in Object format

const elementAttributes = {
    "tag": "p",
    "selector": "//div[@id='block-globalannouncementarea']",
    "text": "New! Itch Protect Wash",
    "attributes": {
      "font-family": "Jost",
      "font-weight": 500,
      "color": "rgb(255, 255, 255)",
      "font-size": "17px",
      "line-height": "24px",
      "letter-spacing": "normal",
      "text-align": "center",
      "display": "inline-block"
    }
};
describe('Verify the UI attributes of homepage', function() {
  it('Verify the UI attributes for 414 screen', function(browser) {
    browser
      .url('https://example.com/')
      .assert.validateBaseline(elementAttributes)
      .end();
  });
});
  1. attributes of the element in an array format
const elementAttributes = [
    {
        "tag": "p",
        "selector": "//div[@id='block-globalannouncementarea']",
        "text": "New! Itch Protect Wash",
        "attributes": {
          "font-family": "Jost",
          "font-weight": 500,
          "color": "rgb(255, 255, 255)",
          "font-size": "17px",
          "line-height": "24px",
          "letter-spacing": "normal",
          "text-align": "center",
          "display": "inline-block"
        }
    },
    {
        "tag": "p",
        "selector": "//div[@id='block-globalannouncementarea']",
        "text": "New! Itch Protect Wash",
        "attributes": {
          "font-family": "Jost",
          "font-weight": 500,
          "color": "rgb(255, 255, 255)",
          "font-size": "17px",
          "line-height": "24px",
          "letter-spacing": "normal",
          "text-align": "center",
          "display": "inline-block"
        }
    }
];

describe('Verify the UI attributes of homepage', function() {
  it('Verify the UI attributes for 414 screen', function(browser) {
    browser
      .url('https://example.com/')
      .assert.validateBaseline(elementAttributes)
      .end();
  });
});

Output

You can choose the kind of reports you need, by using nightwatch provided reporters.Here's a for reference.

Note: This package works with NightwatchJS & NightwatchJS with CucumberJS integration too :)