diff --git a/cypress/e2e/registration.cy.js b/cypress/e2e/registration.cy.js index a64e4c5b..e4e2f483 100644 --- a/cypress/e2e/registration.cy.js +++ b/cypress/e2e/registration.cy.js @@ -1,11 +1,50 @@ +import { generateUser } from '../support/commands'; /// - describe('Student Registration page', () => { before(() => { - + cy.visit('https://demoqa.com/automation-practice-form'); }); - it('', () => { + it('Enter valid data', () => { + const { + email, username, phone, lastname, + address, gender, hobby, subject + } = generateUser(); + + cy.get('#firstName').type(username); + cy.get('#lastName').type(lastname); + cy.get('#userEmail').type(email); + cy.get('#userNumber').type(phone); + cy.get('#currentAddress').type(address); + + cy.get('#genterWrapper > .col-md-9').type(gender); + cy.get('#hobbiesWrapper > .col-md-9').type(gender); + cy.get('.subjects-auto-complete__value-container').type(subject); + cy.contains('#react-select-2-option-0', subject).click(); + + cy.get('#dateOfBirthInput').click(); + cy.contains('select', 'October').select('November'); + cy.contains('select', '2024').select('1990'); + cy.contains('.react-datepicker__day--009', '9') + .click(); + + cy.get('#state').type('{downarrow}{enter}'); + cy.get('#city').type('{downarrow}{enter}'); + + cy.get('#submit').click(); + cy.contains('tr', 'Student Name') + .should('contain', username) + .and('contain', lastname); + cy.contains('tr', 'Student Email').should('contain', email); + cy.contains('tr', 'Gender').should('contain', gender); + cy.contains('tr', 'Mobile').should('contain', phone); + cy.contains('tr', 'Subject').should('contain', subject); + cy.contains('tr', 'Date of Birth') + .should('contain', 'November').and('contain', '1990'); + cy.contains('tr', 'Hobbies').should('contain', hobby); + cy.contains('tr', 'Address').should('contain', address); + cy.contains('tr', 'State and City') + .should('contain', 'Uttar Pradesh Lucknow'); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 119ab03f..661fa315 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,29 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +const faker = require('@faker-js/faker').faker; +const genders = ['Male', 'Female', 'Other']; +const hobbies = ['Sports', 'Reading', 'Music']; +const subjects = ['Math', 'Science', 'History']; +function generateUser() { + const randomNumber = Math.round(Math.random() * 1000); + const username = `user${randomNumber}`; + const lastname = `user${randomNumber}${randomNumber}`; + const email = `${username}@mail.com`; + const phone = Math.round(Math.random() * 10000000000); + const randomIndexGender = Math.floor(Math.random() * genders.length); + const randomIndexHobby = Math.floor(Math.random() * hobbies.length); + const randomIndexSubject = Math.floor(Math.random() * subjects.length); + const address = faker.location.streetAddress(); + return { + email, + username, + phone, + lastname, + address, + gender: genders[randomIndexGender], + hobby: hobbies[randomIndexHobby], + subject: subjects[randomIndexSubject] + }; +} +module.exports = { generateUser };