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

nitro-automated-testing

v2.0.0

Published

Nitro Automated Testing Framework

Downloads

16

Readme

Nitro Automated Testing Framework

Nitro Automated Testing Framework is build on top of the Selenium JS, which is simplified by creating tests using a JSON object file and report templates to define the test workflow. Also can be split a workflow into different small modules.

Steps to create a Test

  • Add elements and actions

tests/data/signup.data.js

import { By, until } from 'selenium-webdriver';

export const signupTest = {
  url: "signup",
  delay: {
    // To Add a delay of 3 seconds before start the test
    beforeLoad: 3,
    // To Add a delay of 3 seconds after the form submission
    afterSubmission: 3
  },
  tests: {
    elements: {
      controls: [
        {
          // Type of Element
          type: "input",
          // CSS selector to identify the HTML element
          selector: "[name=email]",
          // Action to be performed
          action: "sendKeys",
          // Value to fill
          value: "[email protected]"
        },
        {
          type: "textarea",
          selector: "#message",
          action: "sendKeys",
          value: `Lorem ipsum dolor sit amet`
        },
        {
          type: "checkbox",
          selector: "#agree",
          action: "click",
          value: true
        },
        {
          type: "radio",
          selector: "[name=gender][value=male]",
          action: "click",
          value: true
        },
        {
          type: "select",
          selector: "#country",
          action: "selectByValue",
          value: "US"
        }
      ],
      // Define the Submit Button
      submit: "[name=submit]",
      wait: async (driver) => {
        // Optional Custom Wait Function, (Only if required)
        await driver.wait(async () => {
          const bodyClass = await driver.findElement(By.css('body')).getAttribute('class');
          return !bodyClass.includes('onloading');
        }, 3000, 'The body still has the onloading class');
      }
    }
  },
  validator: async (driver) => {
    // Wait for the success or error message to be displayed and be visible
    let currentUrl = await driver.getCurrentUrl();

    let messageElement = await driver.wait(until.elementLocated(By.css('#output')), 3000);

    await driver.wait(until.elementIsVisible(messageElement), 3000);
    // let title = await driver.getTitle();

    // Verify the message content
    return await messageElement.getText().then((text) => {
      let message = text;
      console.log('Message Text:', message); // Debugging output

      let result = (message.includes('Success')) ? 'Signup successful' : 'Signup failed';
      
      // Data that are required to show in Report
      return {
        result,
        message,
        currentUrl,
        timestamp: new Date().toISOString()
      };
    });
  }
};
  • Create a template for the Report

tests/template/signup.report.js

import { nitroTest } from "nitro-automated-testing";

export const getSignupReport = async (ob) => {
  return `
# Signup Test Report

**Browser:** ${(nitroTest.Browser[process.env.BROWSER] || nitroTest.Browser.CHROME).toUpperCase()}

**Current URL:** ${ob.currentUrl}

**Result:** ${ob.result}

**Message:** ${ob.message}

**Timestamp:** ${ob.timestamp}

`;
}
  • Create Signup Function, if needed we can add custom Selenium JS scripts

tests/signup.js

// tests/signup.js
import { signupTest } from './data/signup.data.js';
import { nitroTest } from "nitro-automated-testing";

export const signup = async (driver) => {
  await driver.get(`${process.env.protocol}://${process.env.domain}${process.env.port ? `:${process.env.port}` : ''}/${signupTest.url}`);

  // Wait for 3 seconds before proceeding
  await nitroTest.sleep(signupTest.delay.beforeLoad * 1000);

  // Interact with the form
  await nitroTest.automateData(driver, signupTest);

  const output = await signupTest.validator(driver);

  return output;
};
  • Create the main test.js file which will be entry point js file which can be used for import various test cases and workflows:

tests/test.js

// main test script
import path from 'path';
import { fileURLToPath } from 'url';
import { signup } from './signup.js';
import { nitroTest } from "nitro-automated-testing";
import { getSignupReport } from './template/signup.report.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

(async function globalTests() {
  // Get the desired browser from environment variable or use default
  let driver = await nitroTest.getDriver();

  try {
    console.log(`👉️ ${process.env.protocol}://${process.env.domain}${process.env.port ? `:${process.env.port}` : ''}`);
    await driver.get(`${process.env.protocol}://${process.env.domain}${process.env.port ? `:${process.env.port}` : ''}`);

    // Perform the signup process
    const signupResult = await signup(driver);

    // Generate the report content
    const reportContent = await getSignupReport(signupResult);

    await nitroTest.saveReport(path.join(__dirname, './', 'test', 'reports'), reportContent);
  } finally {
    await driver.quit();
  }
})();