Module

cy

Cypress helpers

This module gathers helpers which can be used when you E2E test your AdminBro dashboard with https://www.cypress.io/ as we do.

Usage

First, you have to import helpers to your cypress project. You can do this in:

/support/index.js or /support/commands.js

require('admin-bro/cy')

and now you can use our helpers

/// <reference types="cypress" />
/// <reference types="admin-bro/cy" />

context('resources/Company/actions/new', () => {
  before(() => {
    cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
  })

  beforeEach(() => {
    cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
    cy.visit('resources/Company/actions/new')
  })

  //...
})

What we have

Cypress helpers project is currently in the WIP/POC phase, that is why there are not much helpers here. But you can expect that gradually we will add more.

New:
  • in version 3.3

View Source admin-bro/cy/index.js, line 1

Methods

# static abGetProperty(path, selectoropt)

Usage

// your property in AdminBro
resourceOptions: {
  properties: {
    isAdmin: {...}
  }
}
// accessing it in test.
cy.abGetProperty('isAdmin', 'input[type="checkbox"]')

abGetProperty returns the wrapper Section for a given property. You can pass inner element which allows you to select input, label, options, etc. inside it.

Parameters:
Name Type Attributes Default Description
path string

path of the property

selector string <optional>
null

View Source admin-bro/cy/commands/ab-get-property.js, line 3

Example
it('shows disabled checkBox', () => {
  cy.abGetProperty('isAdmin', 'input[type="checkbox"]')
    .should('be.disabled')
    .should('not.be.checked')

  cy.abGetProperty('isAdmin', 'label')
    .click()
    .should('not.be.checked')
})

# static abKeepLoggedIn(optionsopt)

Parameters:
Name Type Attributes Description
options object <optional>
cookie object <optional>

session cookie name: default to Cypress.env('AB_COOKIE_NAME')

View Source admin-bro/cy/commands/ab-keep-logged-in.js, line 3

Example
before(() => {
  cy.abLogin()
})

beforeAll(() => {
  cy.abKeepLoggedIn({ cookie: 'my-session-cookie' })
  cy.visit('your/path')
})

# static abLogin(optionsopt)

logs you to the AdminBro. Since the system uses cookie for storing the session information, you can use module:cy.abKeepLoggedIn helper to keep it between test cases.

Parameters:
Name Type Attributes Description
options object <optional>
email object <optional>

login email: default to Cypress.env('AB_EMAIL')

password object <optional>

login password: default to Cypress.env('AB_PASSWORD')

loginPath object <optional>

default to '/login'

View Source admin-bro/cy/commands/ab-login.js, line 3

# static abLoginAPI(optionsopt)

Comparing to module:cy.abLogin it doesn't render page - just performs an API call and logs you in by storing the cookie. In order to preserve this cookie between the it() calls you have to use module:cy.abKeepLoggedIn helper.

Parameters:
Name Type Attributes Description
options object <optional>
email object <optional>

login email: default to Cypress.env('AB_EMAIL')

password object <optional>

login password: default to Cypress.env('AB_PASSWORD')

loginPath object <optional>

default to '/login'

View Source admin-bro/cy/commands/ab-login-api.js, line 3

SoftwareBrothers

Proudly built and maintained by SoftwareBrothers

Software House with a passion for both JavaScript and TypeScript.

See what we do See what we believe in

Proudly built and maintained by

SoftwareBrothers