npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crds-cypress-login

v3.0.0

Published

Cypress methods to log in to Crossroads

Downloads

26

Readme

Authentication Tools

This package allows a user to login to Crossroads.net domains without using the login page.

Tools provided include:

Install with

npm install crds-cypress-login

MP Login

Allows an existing user to login to crossroads.net through Ministry Platform authentication, without using the UI.

Create Login Custom Command

Create a custom Cypress login command in your cypress/support/commands.js file so it can be configured once and reused by any test. The MinistryPlatformLoginPlugin constructor requires an environment: int, demo or an empty string for prod. No other environment variables are required.

// Import and configure the plugin
import { MinistryPlatformLoginPlugin } from 'crds-cypress-login';
const mpPlugin = MinistryPlatformLoginPlugin('int');

// Create custom login command
Cypress.Commands.add('mpLogin', (email, password) => {
  return cy.wrap(mpPlugin.GetLoginCookies(email, password), {timeout: cy.responseTimeout})
    .then((cookies) => {
      cookies.forEach((c) => {
        cy.setCookie(c.name, c.value);
      });
      return cy.reload();
    });
});

Now it can be used in your test:

it('Tests logged in functionality', () => {
  cy.mpLogin('[email protected]', 'password123')
  .then(() => {
    //Test stuff inside a .then() clause
    //because logging in and reloading the page takes a bit
    //and you want it to be ready before continuing to test
  });
});

Create Stay Logged In Custom Command

If you want a user to stay logged in between tests, create a stay logged in command in your cypress/support/commands.js. This example assumes you've already configured the mpPlugin variable above.

// Create custom stay logged in command
Cypress.Commands.add('mpStayLoggedIn', () => {
  mpPlugin.GetLoginCookieNames()
    .forEach((c) => {
      Cypress.Cookies.preserveOnce(c);
    });
});

Now it can be used in your tests like:

before(() => {
  cy.mpLogin('[email protected]', 'password123');
});

beforeEach(() => {
  cy.mpStayLoggedIn();
});

it('Logged in test', () => {
  //User is logged in
});

it('Still logged in', () => {
  //User is still logged in
});

Details for the curious

The MinistryPlatformLoginPlugin does not use Cypress commands so its functions need to be manipulated a bit for them to work correctly with Cypress tests.

  • The mpPlugin.GetLoginCookies returns a Promise that is not a native Cypress Promise, so it must be called inside a cy.wrap clause so Cypress can access its results in sync with the test. mpPlugin.GetLoginCookies makes an API request, so we also need to configure its timeout to match the cy.request() timeout by adding the {timeout: 30000} option.
  • The mpPlugin.GetLoginCookieNames returns an array of strings directly, so it does not need to be wrapped to be in sync with Cypress tests. Unfortunately the Cypress.Cookies.preserveOnce() function does not seem to accept a list of strings containing cookie names, so each must be configured individually.

Okta Login

Allows an existing user to sign in to crossroads.net through Okta authentication, without using the UI.

Create Login Custom Command

Create a custom Cypress login command in your cypress/support/commands.js file so it can be configured once and reused by any test. The OktaLoginPlugin constructor requires two parameters; the Okta domain used for authentication (ex. https://authpreview.crossroads.net) and an Okta Application Client ID with PKCE enabled. No other environment variables are required.

// Import and configure the plugin
import { OktaLoginPlugin } from 'crds-cypress-login';
const oktaPlugin = OktaLoginPlugin(`https://authpreview.crossroads.net`, `exampleClientId`);

// Create custom command
Cypress.Commands.add('oktaLogin', (email, password) => {
  return cy.wrap(oktaPlugin.login(email, password), {timeout: 30000});
});

Now it can be used in your tests:

it('Tests logged in functionality', () => {
  cy.oktaLogin('[email protected]', 'password123')
  .then(() => {
    // The login function does not navigate anywhere, so navigate somewhere first
    cy.visit('/');
    // test stuff
  });
});

The Okta login process does not navigate anywhere or reload a page when it is complete, so tests will need handle this themselves.

Log out between tests

Okta stores session information in localstorage, not cookies, so a user will stay logged in between tests automatically. This is probably not what you want, so use cy.clearLocalStorage() between tests if you would like to log a user out.

Details for the curious

Like the MinistryPlatformLoginPlugin, the OktaLoginPlugin does not use Cypress commands so its functions need to be manipulated a bit for them to work correctly with Cypress tests.

  • The oktaPlugin.login returns a Promise that is not a native Cypress Promise, so it must be called inside a cy.wrap clause so Cypress can access its results in sync with the test. It also makes an API request, so we need to configure its timeout to match the cy.request() timeout by adding the {timeout: 30000} option.