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

cyberpress

v1.0.1

Published

Create fully customizable cypress-cucumber project with just one command

Downloads

169

Readme

Cyberpress

Cypress-Cucumber Automation Framework

This npm package provides a fully customizable Cypress-Cucumber project setup. With this framework, you only need to write POM JSON files, feature files, and step definitions to create robust end-to-end tests.

Features

  • Easy setup of Cypress with Cucumber for BDD-style testing
  • Automatic loading of Page Object Models (POM) from JSON files
  • Case-insensitive matching between POM files and feature files
  • Simplified step definitions with pre-configured imports

Installation

Install the package globally using npm:

npm install cyberpress -g

Then, run the command:

cyberpress

It will ask you a few questions about your project and then set up your project accordingly.

Note: Ensure you install the package globally; otherwise, you will need to add the package path to the PATH environment variable to run it correctly.

Usage

1. Create POM JSON Files

Create JSON files for your Page Object Models in the cypress/e2e/features/POM directory. The filename should match your feature file name (case-insensitive).

Example login.json:

{
  "usernameInput": "#username",
  "passwordInput": "#password",
  "loginButton": "#login-btn"
}

2. Write Feature Files

Create your Cucumber feature files in the cypress/e2e/features directory.

Example Login.feature:

Feature: User Login

Scenario: Successful login
  Given I am on the login page
  When I enter valid credentials
  And I click the login button
  Then I should be logged in successfully

3. Implement Step Definitions

Create step definition files in the cypress/e2e/step_definitions directory. Import the necessary dependencies as shown below:

import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import Elements from "../plugins/Elements";

Given("I am on the login page", () => {
  cy.visit("/login");
});

When("I enter valid credentials", () => {
  cy.get(Elements.getElement("usernameInput")).type("validuser");
  cy.get(Elements.getElement("passwordInput")).type("validpassword");
});

When("I click the login button", () => {
  cy.get(Elements.getElement("loginButton")).click();
});

Then("I should be logged in successfully", () => {
  cy.url().should("include", "/dashboard");
});

4. Run Your Tests

This framework provides several run options to suit different testing needs and CI/CD integrations. These can be executed using npm scripts defined in your package.json.

Available Scripts

  1. Open Cypress Test Runner

    npm run cypressCloud
  2. Run Tests Headlessly

    npm run headlessRun
  3. Run Tests in Headed Mode

    npm run headedRun
  4. Record Run in Cypress Dashboard

    npm run record
  5. Run Specific Feature File

    npm run specFeature --feature=your-feature-name
  6. Record Run of Specific Feature File

    npm run recordSpecFeature --feature=your-feature-name
  7. Run Tests with Specific Tag

    npm run specTag --tag=@your-tag
  8. Record Run of Tests with Specific Tag

    npm run recordSpecTag --tag=@your-tag

Notes

  • The specFeature, recordSpecFeature, specTag, and recordSpecTag scripts are designed to work on both Windows and Unix-like operating systems.
  • When using tags, ensure your feature files include the appropriate tags (e.g., @your-tag) above the scenarios you want to run.
  • For recording runs, make sure you have set up your project with Cypress Dashboard and have the correct record key.

Examples

Run a specific feature file:

npm run specFeature --feature=login

Run all tests tagged with @smoke:

npm run specTag --tag=@smoke

Record a run of all @regression tests:

npm run recordSpecTag --tag=@regression

These run functionalities provide flexibility in executing your tests, whether you're doing local development, debugging, or running tests in a CI/CD pipeline.

Configuration

The framework automatically loads POM files based on the feature file names. You just need to include these two lines in each of your step definition files:

import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import Elements from "../plugins/Elements";

Ensure that your POM JSON files and feature files have matching names (case-insensitive).

Best Practices

  1. Keep your POM JSON files focused on element selectors.
  2. Use descriptive names for your elements in the POM files.
  3. Leverage the Elements.getElement() method in your step definitions for robust element selection.
  4. Follow Cucumber best practices for writing clear and maintainable feature files.

Troubleshooting

If you encounter issues with element selection, ensure that:

  • Your POM JSON file name matches the feature file name (case-insensitive).
  • The element keys in your POM JSON file match those used in your step definitions.
  • Your selectors in the POM JSON file are correct and unique.

Congratulations! You are now ready to write and run your first test.