Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NoriSte/cypress-otp

Enter a valid OTP token in your UI tests.
https://github.com/NoriSte/cypress-otp

Last synced: 3 months ago
JSON representation

Enter a valid OTP token in your UI tests.

Awesome Lists containing this project

README

        

# Cypress OTP

Enter a valid OTP token in your UI tests

[![Build Status](https://travis-ci.com/NoriSte/cypress-otp.svg?branch=master)](https://travis-ci.com/NoriSte/cypress-otp)
[![Build Cron](https://img.shields.io/badge/build%20cron-weekly-44cc11.svg)](https://travis-ci.com/NoriSte/cypress-otp)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/) ![npm](https://img.shields.io/npm/dw/cypress-otp?color=CB3836)

Cypress OTP

Use this plugin to insert a valid OTP token in a [Cypress](https://www.cypress.io) test.

# Installation

```bash
npm i -D cypress-otp
# or
yarn add -D cypress-otp
```

then open your `cypress/plugins/index.js` file and register a new task

```javascript
module.exports = on => {
on("task", {
generateOTP: require("cypress-otp")
});
};
```

# How to use it

To get an OTP code

```javascript
cy.task("generateOTP", "YOUR_SECRET").then(token => {
cy.get("#otp-token").type(token);
});
```

Take a look at the [example test](cypress/integration/cypress-otp.test.js) source code.

# Tips

- the plugin saves the last used secret so you can avoid to pass it every time. You can even set it at the beginning of your test suite

```javascript
before(() => {
cy.task("generateOTP", "YOUR_SECRET");
});
```

and then consume the `generateOTP` task

```javascript
cy.task("generateOTP").then(token => {
cy.get("#otp-token").type(token);
});
```

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Stefano Magni
Stefano Magni

💻 ⚠️

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!