Skip to content
Enter a valid OTP token in your UI tests.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets test: 💍 Test the source file Mar 25, 2019
cypress
public
src
.all-contributorsrc
.gitignore test: 💍 Test the source file Mar 25, 2019
.travis.yml
README.md docs: ✏️ Fix the tagline Mar 25, 2019
cypress.json
package.json
yarn-error.log test: 💍 Test the source file Mar 25, 2019
yarn.lock test: 💍 Test the source file Mar 25, 2019

README.md

Cypress OTP

Enter a valid OTP token in your UI tests

Commitizen friendly Build Status Open Source Love

Cypress OTP

Use this plugin to insert a valid OTP token in a Cypress test.

Installation

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

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

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

How to use it

To get an OTP code

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

Take a look at the example test 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
before(() => {
  cy.task("generateOTP", "YOUR_SECRET");
});

and then consume the generateOTP task

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

Contributors

Thanks goes to these wonderful people (emoji key):

Stefano Magni
Stefano Magni

💻 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

You can’t perform that action at this time.