# Cypress Tests

Support for the [Cypress Testing Framework](https://www.cypress.io) has now been integrated into D.T.

With Cypress, you can easily create declarative tests, debug them visually and automatically run them in your continuous integration builds.

## Getting started

From the terminal, navigate to the `disciple-tools-theme` directory and execute `npm run cy:open`; which should display the Cypress Launchpad.

From there, select the `E2E Testing` option; which should then display the following browser selection view.

![Cypress Browser Selection](/files/lwh2pvpKx5xnFFshh2KU)

See [Cyress Open The App](https://docs.cypress.io/app/get-started/open-the-app) guide for more details.

On browser selection, you should then be taken to the End To End (E2E) view; as shown below.

![Cypress E2E View](/files/gV1PNvER8HiUAZs96dWP)

## E2E Folder Structure

The view from the previous section, displays all E2E tests created under the `./cypress/e2e` directory; which is organised as follows:

* **./cypress/e2e/contacts/**
  * Siloed unit tests, covering the testing of `contacts` post type related functionality; such as creating, updating and deleting records, searching, etc.
  * Please follow the pattern shown, when introducing tests for new features.
* **./cypress/support/commands.js**
  * A holding area for custom functions; typically duplicate code; which can be encapsulated into a global function.
  * The following custom functions have been created:
    * *dtLogin()*
      * D.T frontend login.

## Running Environment

Currently, all tests are run locally; so, you'll need to update the base url and admin credentials within the `./cypress.config.js` file.

```js
import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
    baseUrl: '<LOCAL_DEV_INSTANCE_HTTP_URL>'
  },
  dt: {
    credentials: {
      admin: {
        username: '<LOCAL_DEV_ADMIN_USR>',
        password: '<LOCAL_DEV_ADMIN_PWD>'
      }
    }
  }
});
```

Lastly, the following Cypress user guides also provide useful information, for gaining a better understanding of the framework.

* [Cypress - Your First Test](https://docs.cypress.io/app/end-to-end-testing/writing-your-first-end-to-end-test)
* [Cypress - Testing Your App](https://docs.cypress.io/app/end-to-end-testing/testing-your-app)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.disciple.tools/local-setup/cypress-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
