Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NoriSte/cypress-otp
Enter a valid OTP token in your UI tests.
https://github.com/NoriSte/cypress-otp
Last synced: about 3 hours ago
JSON representation
Enter a valid OTP token in your UI tests.
- Host: GitHub
- URL: https://github.com/NoriSte/cypress-otp
- Owner: NoriSte
- Created: 2019-03-25T16:35:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-07T20:52:25.000Z (over 1 year ago)
- Last Synced: 2024-11-09T18:25:15.798Z (4 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/cypress-otp
- Size: 276 KB
- Stars: 50
- Watchers: 1
- Forks: 7
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-cypress - Cypress OTP - Valid OTP token generation for Cypress. (Uncategorized / Uncategorized)
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)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)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!