Select Page
Automation Testing

Best Cypress Plugins Every Tester Must Know

Save loads of time and effort in your Cypress automation testing by using our list of the best Cypress plugins.

Best Cypress Plugins Every Tester Must Know - Blog
Listen to this blog

A Cypress plugin is a JavaScript module that extends the functionality of the Cypress test runner. They have the ability to create new commands, modify existing commands, and register custom task runners. So knowing the best Cypress plugins can be very useful as you will be able to save a lot of time and streamline your automation testing. Being a leading automation testing company, we have listed out the Best Cypress Plugins we have used in our projects. We have also explained the functionality of these plugins and have mentioned how you can install them as well.

It is important to note that Cypress plugins can be created by anyone. So you can also create a plugin if different projects share a common functionality or utility function that can use one.

But the great advantage here is that Cypress already has a wide range of community-created plugins that cover most of the required functionality such as using XPath, creating HTML reports, and so on.

But before we take a look at the best Cypress plugins and their functionalities, we’ll have to know how to install them.

Installing a Cypress Plugin

Once you have identified a Cypress plugin you wish to use, there are a few standard steps you’ll have to follow to add it to your project. Let’s find out what they are.

But there will be exceptions in a few cases and you’ll need to do a few extra steps to use the plugin. We will explore those exceptions when we look into the best Cypress plugins in detail.

1. Add it as a dependency to your project by using this command

npm install --save-dev @name_of_the_plugin

2. Register the plugin in your Cypress configuration file (cypress.config.js)

Add the object into the “plugins” array as shown in the below example

{
  "name": "@name_of_the_plugin"
}

Now that we are aware of the prerequisites you’ll need to know, let’s head directly to our list of the Best Cypress Plugins and find out what makes them so great.

Best Cypress Plugins

@badeball/cypress-cucumber-preprocessor

It is a customized version of the cypress-cucumber-preprocessor plugin that you can use to write Cypress tests in the Gherkin format.

The advantage here is that Gherkin uses natural language statements that make the automation tests very easy to read and understand. Apart from technical people being able to understand the tests, people with no technical knowledge also will be able to understand them. Since that is an important aspect of automation testing, we have added this plugin to our list of the best Cypress plugins.

Once you have installed and registered the plugin using the above-mentioned instructions, you will be able to write your tests using the Gherkin syntax and save them with the .feature file extension. These files will be parsed and converted into executables by the plugin.

@bahmutov/cypress-esbuild-preprocessor

It is a plugin that uses esbuild, a JavaScript bundler to preprocess your test files before they are run by Cypress.

If you are using JavaScript features such as JSX or TypeScript in your tests, this plugin would be useful as esbuild will convert these features to plain JavaScript that can be run in older browsers too.

@badeball/cypress-cucumber-preprocessor/esbuild

The @badeball/cypress-cucumber-preprocessor/esbuild plugin is a custom version of one of the best Cypress plugins we have seen already. As the name suggests, it is a modified version of the cypress-cucumber-preprocessor plugin.

The @badeball/cypress-cucumber-preprocessor/esbuild plugin extends the functionality of writing tests using the Gherkin language by using esbuild. You will be able to transpile your test files using esbuild and parse them using Cucumber before they are run by Cypress.

This can be very useful if you are using modern JavaScript features such as JSX or TypeScript in your tests.

@cypress/xpath

Using an XPath to locate elements for your automation tests is a very common practice in automation testing. And you can make use of the @cypress/xpath plugin to add support for using XPath expressions in your tests.

It can be particularly useful when you have to target elements that don’t have unique ID attributes, or if you want to locate elements based on their exact position or relative position with respect to other elements.

You can target elements in your tests by using the cy.xpath() command.

Cypress-iframe

iframes are HTML elements that allow you to embed another HTML document within the current page. They are used in numerous websites as they can be useful for displaying content from external sources or for separating different sections of a page.

If the site you are testing does have an iframe, you’ll have to know how to interact with it in your automation tests. So you can make use of the cypress-iframe plugin to shift the focus of your tests to an iframe element.

Cy-verify-downloads

As the name suggests, this Cypress plugin can be used to validate if a file has been downloaded during your automation testing. It is common for applications to offer file downloads to their users and that is why this plugin has found its spot in our list of best Cypress plugins.

It basically uses two arguments to fulfill its purpose, and they are the file path and the expected content of the download file. So you can use cy.verifyDownload() command to ensure that your application is generating and serving the correct files to users.

Multiple-cucumber-html-reporter

Reporting is a very important part of automation testing and we have chosen a plugin that will help you generate HTML reports for your tests. The Multiple-cucumber-html-reporter is a plugin for the Cucumber test framework that generates an HTML report for your tests.

Cucumber is a tool that allows you to write tests using natural language statements (written in the Gherkin syntax), and the Multiple-cucumber-html-reporter plugin allows you to generate an HTML report that shows the results of these tests.

Of our list of the best Cypress plugins, this is the only plugin that has an exception when it comes to using it after installation and registration. You’ll have to configure the plugin to generate the report in the format you want.

As usual, you can use the below command to install the plugin as a dependency on your project.

npm install --save-dev multiple-cucumber-html-reporter

After which, you’ll have to configure the plugin by creating a JavaScript file that requires the plugin. You can configure the JavaScript file with the appropriate conditions based on which your HTML report will be generated. Let’s take a look at an example to help you understand it clearly.

Example:

Let’s generate an HTML report based on the JSON files in the “path/to/json/files” directory and save it to the “path/to/report/directory” directory. We will be including metadata about the browser & platform used to run the tests and a few custom data such as the title and additional details about the project and release.

const reporter = require("multiple-cucumber-html-reporter");
 
reporter.generate({
  jsonDir: "path/to/json/files",
  reportPath: "path/to/report/directory",
  metadata: {
    browser: {
      name: "chrome",
      version: "78.0"
    },
    device: "Desktop",
    platform: {
      name: "Windows",
      version: "10"
    }
  },
  customData: {
    title: "My Report",
    data: [
      { label: "Project", value: "My Project" },
      { label: "Release", value: "1.0.0" },
      { label: "Execution Date", value: "January 1, 2020" }
    ]
  }
});

cypress-file-upload

Similar to applications having the provision to download files, the ability to upload files from the local system to the server is also a common function. So you can make use of this plugin to test if your application uploads a file as expected.

cy.upload_file is the command you’ll have to use to get this functionality.

Conclusion

As mentioned earlier, there are so many great Cypress plugins and we found these to be the most important ones that every automation tester must know. We hope you are now clear about how to install, register, and use all of the best Cypress plugins we’ve gone through in our blog. Even if you wish to use any other Cypress plugin, you can make use of the standard installation and registration process to get started with it. Being an experienced automated testing as a service provider, we have published numerous informative blogs about Cypress and will be publishing more. So make sure to subscribe to our newsletter to ensure you do not miss out on any of our latest posts.

Comments(0)

Submit a Comment

Your email address will not be published.

Talk to our Experts

Amazing clients who trust us


image
image
image
image
image
image