Skip to content

Commit c1a8bfa

Browse files
author
Wusi
committed
cypress-tests
1 parent 4eb21cf commit c1a8bfa

File tree

17 files changed

+1953
-0
lines changed

17 files changed

+1953
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
cypress/videos
3+
cypress/screenshots
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-include ../.env
2+
3+
node_modules:
4+
npm install
5+
6+
dev: node_modules
7+
CYPRESS_MAILSLURP_API_KEY=$(API_KEY) npm run dev
8+
9+
test: node_modules
10+
CYPRESS_MAILSLURP_API_KEY=$(API_KEY) npm run test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Cypress MailSlurp plugin example
2+
How to use MailSlurp with Cypress JS. Loads a demonstration app, signs up with a new email address, receives confirmation code, extracts code and submits. Sees welcome screen.
3+
4+
## Run
5+
`API_KEY=your-api-key make test`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"requestTimeout": 30000,
3+
"responseTimeout": 30000,
4+
"defaultCommandTimeout": 30000
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// <reference types="cypress-mailslurp" />
2+
describe("user sign up test with mailslurp plugin", function () {
3+
// use cypress-mailslurp plugin to create an email address before test
4+
before(function () {
5+
return cy.mailslurp()
6+
.then(mailslurp => mailslurp.createInbox())
7+
.then(inbox => {
8+
// save inbox id and email address to this (make sure you use function and not arrow syntax)
9+
cy.wrap(inbox.id).as('inboxId')
10+
cy.wrap(inbox.emailAddress).as('emailAddress')
11+
})
12+
});
13+
it("01 - can load the demo application", function () {
14+
// get wrapped email address and assert contains a mailslurp email address
15+
expect(this.emailAddress).to.contain("@mailslurp");
16+
// visit the demo application
17+
cy.visit("https://playground.mailslurp.com")
18+
cy.title().should('contain', 'React App');
19+
});
20+
// use function instead of arrow syntax to access aliased values on this
21+
it("02 - can sign up using email address", function () {
22+
// click sign up and fill out the form
23+
cy.get("[data-test=sign-in-create-account-link]").click()
24+
// use the email address and a test password
25+
cy.get("[name=email]").type(this.emailAddress).trigger('change');
26+
cy.get("[name=password]").type('test-password').trigger('change');
27+
// click the submit button
28+
cy.get("[data-test=sign-up-create-account-button]").click();
29+
});
30+
it("03 - can receive confirmation code by email", function () {
31+
// app will send user an email containing a code, use mailslurp to wait for the latest email
32+
cy.mailslurp()
33+
// use inbox id and a timeout of 30 seconds
34+
.then(mailslurp => mailslurp.waitForLatestEmail(this.inboxId, 30000, true))
35+
// extract the confirmation code from the email body
36+
.then(email => /.*verification code is (\d{6}).*/.exec(email.body!!)!![1])
37+
// fill out the confirmation form and submit
38+
.then(code => {
39+
cy.get("[name=code]").type(code).trigger('change');
40+
cy.get("[data-test=confirm-sign-up-confirm-button]").click();
41+
})
42+
});
43+
// fill out sign in form
44+
it("04 - can sign in with confirmed account", function () {
45+
// use the email address and a test password
46+
cy.get("[data-test=username-input]").type(this.emailAddress).trigger('change');
47+
cy.get("[data-test=sign-in-password-input]").type('test-password').trigger('change');
48+
// click the submit button
49+
cy.get("[data-test=sign-in-sign-in-button]").click();
50+
});
51+
// can see authorized welcome screen
52+
it("05 - can see welcome screen", function () {
53+
// click sign up and fill out the form
54+
cy.get("h1").should("contain", "Welcome");
55+
});
56+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
import "cypress-mailslurp";
20+
21+
22+
// Alternatively you can use CommonJS syntax:
23+
// require('./commands')

0 commit comments

Comments
 (0)