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

hat-automation-tool

v2.5.0

Published

A platform independent debuggable BDD Javascript testing framework. It's simple, easy to use and not dependant to any other tool or library, using Nodejs, webdriverio and cucumber-js

Downloads

3

Readme

HAT

A platform independent debuggable BDD Javascript testing framework. It's simple, easy to use and not dependant to any other tool or library. It's built with nodeJs, webdriver.io (Next-gen WebDriver for Node.js) and cucumber-js complete with integrated API Testing.

Installation



npm install


# To run your test locally, you'll need a local selenium server running, you can install and
# launch a selenium standalone server with chrome, firefox and phantomjs drivers via the 
# following commands in a separate terminal:

yarn global add selenium-standalone@latest
selenium-standalone install && selenium-standalone start

Usage

# run 'yarn install' in a terminal window from within the project folder
node index.js -dt @inciteLogin // locally
or
yarn run bslocal chrome/@inciteLogin  // via browserstack

Options

-h, --help                   output usage information
-v, --version                output the version number
-s, --steps <path>           path to step definitions. defaults to ./step-definitions
-p, --pageObjects <path>     path to page objects. defaults to ./page-objects
-o, --sharedObjects [paths]  path to shared objects - repeatable. defaults to ./shared-objects
-b, --browser <path>         name of browser to use. defaults to chrome
-r, --reports <path>         output path to save reports. defaults to ./reports
-d, --disableTestReport [optional]  disables the test report from opening after test completion
-t, --tags <tagName>         name of tag to run
-c, --context <path>        contextual root path for project-specific features, steps, objects etc
-f, --featuresPath <path>   path to feature definitions. defaults to ./features
-e, --email [optional]      sends email reports to stakeholders
-n, --environment [<path>]  name of environment to run the framework/test in. default to dev
-g, --reportName [optional] basename for report files e.g. use report for report.json
-x, --extraSettings [optional]  further piped configs split with pipes
-w, --remoteService [optional]  which remote driver service, if any, should be used e.g. browserstack

By default tests are run using Google Chrome, to run tests using another browser supply the name of that browser along with the -b switch. Available options are:

| Browser | Example | | :--- | :--- | | Chrome | -b chrome | | Firefox | -b firefox |

The following variables are available within the Given(), When() and Then() functions:

| Variable | Description | | :--- | :--- | | driver | an instance of web driver (the browser) | | webdriverio| the raw webdriver module, providing access to static properties/methods | | page | collection of page objects loaded from disk and keyed by filename | | shared | collection of shared objects loaded from disk and keyed by filename | | helpers | a collection of helper methods things webdriver.io does not provide but really should! | | expect | instance of chai expect to expect('something').to.equal('something') | | assert | instance of chai assert to assert.isOk('everything', 'everything is ok') | | trace | handy trace method to log console output with increased visibility | | fs | exposes fs (file system) for use globally | | dir | exposes dir for getting an array of files, subdirectories or both | | request | exposes the request-promise for API testing | use for making API calls | | date | exposes the date method for logs and reports | | log | exposes the log method for output to files and emailing |

Visual Regression functionality with Resemble JS

Visual regression testing, gives the ability to take and compare whole page screenshots or of specific parts of the application / page under test. If there are Elements in the page that contain dynamic contents (like a clock or something like tip of the day), you can hide this elements before taking the screenshot by passing the selector (or an array of selectors) to the saveScreenshot function.

// ./runtime/imageCompare.js

compareImage: async (fileName) => {
  const verify = require('./imageCompare');
  await verify.assertion(fileName);
  await verify.value();
  await verify.pass();
}

// usage within page-object file:
  await verify.saveScreenshot(fileName, elementsToHide);
  await helpers.compareImage(fileName);

API Testing functionality with request-promise

Getting data from a JSON REST API

// ./runtime/helpers.js
 apiCall: function (endpoint) {
    let endPoint = ('http://endpoint.com');
    
    let options = {
        method: 'GET',
        url: endPoint,
        json: true,
        simple: false,
        resolveWithFullResponse: true,
    };
    
    return request(options)
    .then(async function (response, err) {
        if (err) {
           // API call failed
        }
        // response = API call is successful
    });
 },

Reports

HTML and JSON reports are automatically generated and stored in the default ./reports folder. This location can be changed by providing a new path using the -r command line switch:

Event handlers

You can register event handlers for the following events within the cucumber lifecycle.

const {After, Before, AfterAll, BeforeAll} = require('cucumber');

| Event | Example | |----------------|-------------------------------------------------------------| | Before | Before(function() { // This hook will be executed before all scenarios}) | | After | After(function() {// This hook will be executed after all scenarios}); | | BeforeAll | BeforeAll(function() {// perform some shared setup}); | | AfterAll | AfterAll(function() {// perform some shared teardown}); |

How to debug

Most webdriverio methods return a JavaScript Promise that is resolved when the method completes. The easiest way to step in with a debugger is to add a .then method to a selenium function and place a debugger statement within it, for example:

  When(/^I search DuckDuckGo for "([^"]*)"$/, function (searchQuery, done) {
    driver.element('#search_form_input_homepage').then(function(input) {
      expect(input).to.exist;
      debugger; // <<- your IDE should step in at this point, with the browser open
      return input;
    })
    .then(function(input){
       input.setValue(selector, searchQuery);
       input.setValue(selector, 'Enter');

       done(); // <<- let cucumber know you're done
    });
  });