cyberpress
v1.0.2
Published
Create fully customizable cypress-cucumber project with just one command
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 -gThen, run the command:
cyberpressIt 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 successfully3. 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
Open Cypress Test Runner
npm run cypressCloudRun Tests Headlessly
npm run headlessRunRun Tests in Headed Mode
npm run headedRunRecord Run in Cypress Dashboard
npm run recordRun Specific Feature File
npm run specFeature --feature=your-feature-nameRecord Run of Specific Feature File
npm run recordSpecFeature --feature=your-feature-nameRun Tests with Specific Tag
npm run specTag --tag=@your-tagRecord Run of Tests with Specific Tag
npm run recordSpecTag --tag=@your-tag
Notes
- The
specFeature,recordSpecFeature,specTag, andrecordSpecTagscripts 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=loginRun all tests tagged with @smoke:
npm run specTag --tag=@smokeRecord a run of all @regression tests:
npm run recordSpecTag --tag=@regressionThese 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
- Keep your POM JSON files focused on element selectors.
- Use descriptive names for your elements in the POM files.
- Leverage the
Elements.getElement()method in your step definitions for robust element selection. - 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.
