Skip to content

Commit

Permalink
move sendMessage method into a command
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine-Pinto committed Oct 17, 2020
1 parent 7f4d585 commit f4a24fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 47 deletions.
27 changes: 5 additions & 22 deletions cypress/integration/contactForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Beginner Challenge
Create an automated test that completes the contact us form on the homepage, submits it, and asserts that the form was completed successfully.
Create an automated test that completes the contact us form on the homepage,
submits it, and asserts that the form was completed successfully.
*/

describe('/contactForm', () => {
Expand Down Expand Up @@ -42,31 +43,13 @@ describe('/contactForm', () => {
.should('be.visible')
})

it('Submit a contact request', () => {
it.only('Submit a contact request', () => {
//Save name and subject in variables to check in the end if submit of the contact form was successfull and response message contains these the name and subject
let name = cy.faker.name.findName()
let subject = 'CypressTest '+ cy.faker.lorem.word()
let email = cy.faker.internet.email()

//Fill in the contact form input fields with generated fake Data by faker.js
cy.get('input#name')
.should('be.visible')
.type(name)
cy.get('input#email')
.type(cy.faker.internet.email())
cy.get('input#phone')
.type(cy.faker.phone.phoneNumber())
cy.get('input#subject')
.type(subject)
cy.get('textarea#description')
.type(cy.faker.lorem.text())

//Click on the 'submit' button
cy.get('button#submitContact')
.click()

//Check if response message contains name and subject from the contact form
cy.contains('h2', name)
cy.contains('p', subject)
cy.sendMessage(name, subject, email)
})

})
48 changes: 23 additions & 25 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add("sendMessage", (name, subject,email) => {
//Fill in the contact form input fields with generated fake Data by faker.js and the parameters
cy.get('input#name')
.should('be.visible')
.type(name)
cy.get('input#email')
.type(email)
cy.get('input#phone')
.type(cy.faker.phone.phoneNumber())
cy.get('input#subject')
.type(subject)
cy.get('textarea#description')
.type(cy.faker.lorem.lines())

//Click on the 'submit' button
cy.get('button#submitContact')
.click()

//Check if response message contains name and subject from the contact form
cy.contains('h2', name)
cy.contains('p', subject)
})

0 comments on commit f4a24fe

Please # to comment.