From 81f924989ac3fb6e2f8f1923e224e9f60e8c0f01 Mon Sep 17 00:00:00 2001 From: LyudmilaDidkivska Date: Fri, 11 Oct 2024 18:06:09 +0300 Subject: [PATCH] Add Auto --- cypress.config.js | 31 ++++++++++++++++++++-- cypress/e2e/registration.cy.js | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index b04dabfa..134dab54 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,8 +1,35 @@ const { defineConfig } = require('cypress'); +const { faker } = require('@faker-js/faker'); module.exports = defineConfig({ e2e: { + chromeWebSecurity: false, + baseUrl: 'https://demoqa.com/automation-practice-form', + viewportHeight: 1080, + viewportWidth: 1320, setupNodeEvents(on, config) { - } - } + + on('task', { + generateUser() { + const randomIndex = Math.floor(Math.random() * 2); + const hobbies = ['Sports', 'Reading', 'Music']; + return { + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + email: faker.internet.email(), + genderId: randomIndex + 1, + phoneNumber: '9876543215', + birth: { + year: Math.floor(1950 + Math.random() * 20).toString(), + month: faker.date.month(), + day: Math.ceil(Math.random() * 27), + }, + hobby: hobbies[randomIndex], + address: faker.location.streetAddress(), + }; + }, + }); + }, + }, }); + diff --git a/cypress/e2e/registration.cy.js b/cypress/e2e/registration.cy.js index a64e4c5b..c297e80c 100644 --- a/cypress/e2e/registration.cy.js +++ b/cypress/e2e/registration.cy.js @@ -1,11 +1,53 @@ /// -describe('Student Registration page', () => { - before(() => { + Cypress.on('uncaught:exception', (err, runnable) => { + + return false; + }); +describe('Student Registration Form', () => { + + before(() => { + cy.visit('https://demoqa.com/automation-practice-form'); + cy.task('generateUser').then(generatedUser => { + user = generatedUser; + }) }); - it('', () => { + it('should fill the form and assert modal data', () => { + + cy.findByPlaceholderText('First Name').type(user.firstName); + cy.findByPlaceholderText('Last Name').type(user.lastName); + cy.get('#userEmail').type(user.email); + + + cy.get(`label[for="gender-radio-${user.genderId}"]`).click(); + + + cy.get('#userNumber').type(user.phoneNumber); + cy.get('#dateOfBirthInput').click(); + cy.get('.react-datepicker__year-select').select(user.birth.year); + cy.get('.react-datepicker__month-select').select(user.birth.month); + cy.get(`[aria-label="${user.birth.day}"]`).click(); + cy.get(`label[for="hobbies-checkbox-${user.hobby}"]`).click(); + cy.get('#currentAddress').type(user.address); + + + cy.get('#submit').click(); + + + cy.get('.modal-body').should('contain', user.firstName); + cy.get('.modal-body').should('contain', user.lastName); + cy.get('.modal-body').should('contain', user.email); + cy.get('.modal-body').should('contain', user.phoneNumber); + cy.get('.modal-body').should('contain', user.birth.day); + cy.get('.modal-body').should('contain', user.birth.month); + cy.get('.modal-body').should('contain', user.birth.year); + cy.get('.modal-body').should('contain', user.hobby); + cy.get('.modal-body').should('contain', user.address); + + + cy.get('#closeLargeModal').click(); }); });