openedx / cypress-e2e-tests

Cypress E2E Tests for Open edX applications
GNU Affero General Public License v3.0
15 stars 25 forks source link

cypress-e2e-tests

This repo contains e2e tests written in Cypress for different Open edX applications



Introduction to Cypress

Cypress is a relatively new automated tests tool which is gaining popularity at a very rapid pace

Here is the home page for Cypress if someone wants to look it up

https://www.cypress.io/

Cypress has very strong documentation so a new comer could find most of the information from their own site

https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell

Also as a starting point it would be good to go through these tutorial videos

https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices



E2E Tests Repo

This repo is meant to contain a sample for e2e tests:

Authentication MFE (Active)

With time we will add more projects in the repo



Protocols for Test Design

We don't yet have well defined protocols for writing Cypress tests for Open edX application, so this work was mostly experimental

The first project was MIT Journals (which has since been deprecated and removed).

In the second project, Authentication MFE, the following approach was used:

The tests for Authentication MFE are present in following path

https://github.com/openedx/cypress-e2e-tests/tree/master/cypress/integration/authenticationMFE

To manage multiple projects customized config files are used so user is able to run any project without making any change in the code

Config files for projects are placed here

https://github.com/openedx/cypress-e2e-tests/tree/master/config



Test Setup

Installations

You need to have Node.js installed before using Cypress.

For rest of the installations move to project folder in command prompt and type

npm install

which will install Cypress and other supporting tools


Environment Variables

Following Environment Vars should be set before running the tests

CYPRESS_LMS_USER_EMAIL

CYPRESS_LMS_USER_PASSWORD

Note: The above are credentials for a normal edX user who does not have access to admin portal

CYPRESS_ADMIN_USER_EMAIL

CYPRESS_ADMIN_USER_PASSWORD

Note: The above are credentials for an admin portal valid user

Following environment vars would be required for using google api to read gmail inbox

CYPRESS_GMAIL_ID

CYPRESS_GMAIL_CLIENT_ID

CYPRESS_GMAIL_CLIENT_SECRET

CYPRESS_GMAIL_ACCESS_TOKEN

CYPRESS_GMAIL_REFRESH_TOKEN

Note: You can use the method descibed in the below link to get these auth tokens for any personal gmail account

https://developers.google.com/identity/protocols/OAuth2WebServer#creatingcred


Run Tests

To run admin portal tests in interactive mode use following command

npm run cy:openAuthnMFE

To run admin portal tests in normal mode use following command

npm run cy:runAuthnMFE


Using ES LInt

ESLint is also setup in the repo, you can use it by typing following command in terminal

npm run lint


Docker Setup

Docker setup is also available for those who want to run the tests without doing any installations

To run the tests in Docker


Running Tests in Interactive Mode using Docker

You can also execute tests in interactive mode directly from Docker, for that you would need to do some extra steps

As a pre-requisite you need to install XQuartz using following command

brew cask install xquartz

or install it directly from https://www.xquartz.org/

To configure XQuartz

To run the tests