@lightspeed/cypress-utilities
v0.1.6
Published
Common utilities for Cypress tests
Downloads
25
Keywords
Readme
@lightspeed/cypress-utilities
Introduction
Set of commands to use in Cypress to simplify writing tests.
Quick Start
Install
yarn add -D @lightspeed/cypress-utilities
Setup
Add the custom commands to your Cypress installation:
// In `cypress/support/commands.js`:
import '@lightspeed/cypress-utilities/add-commands';
If you use TypeScript, import types in tsconfig.json
.
{
"compilerOptions": {
"types": ["cypress", "@lightspeed/cypress-utilities"]
}
}
Commands
cy.login
Allows to log in the application using OAuth requests, without the UI.
cy.login({
authBaseUrl: 'https://accounts.myapp.com',
authUserId: '[email protected]',
authUserPassword: 'password123',
// By default `authLoginUrl` uses `${authBaseUrl}/login`, but you can change it
// if the login URL has a different base URL or login route:
authLoginUrl: 'https://accounts.myotherapp.com/my-other-login',
});
Since those options are most probably environment based, they all default to Cypress.env()
equivalent values. We recommend defining them in your cypress.env.json
(see docs) as environment variables, and simply call cy.login()
in your tests.
For example, in your cypress.env.json
:
{
"authBaseUrl": "https://accounts.myapp.com",
"authUserId": "[email protected]",
"authUserPassword": "password123"
}
Then in your Cypress tests simply write:
cy.login();
You can read the Cypress documentation on how to override these values on other environments such as CI.
Options
| Name | Description | Default |
| ------------------ | ------------------------------------------------------------------------ | --------------------------------- |
| authBaseUrl
| Base URL for the authentication server, including https://
. | Cypress.env('authBaseUrl')
|
| authUserId
| The username of the user to log in. | Cypress.env('authUserId')
|
| authUserPassword
| The password of the user to log in. | Cypress.env('authUserPassword')
|
| authLoginUrl
| (optional) Login URL to send the XHR request with username and password. | ${authBaseUrl}/login
|