From abc08989b8d867211721ed6c0b51e40e98693be7 Mon Sep 17 00:00:00 2001 From: vs-qaaug Date: Mon, 14 Oct 2024 16:56:53 +0300 Subject: [PATCH] Solution --- cypress.config.js | 1 + cypress/e2e/registration.cy.js | 42 +++++++++++++++++++++++++++++++--- cypress/support/commands.js | 3 +++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index b04dabfa..f1089972 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,6 +2,7 @@ const { defineConfig } = require('cypress'); module.exports = defineConfig({ e2e: { + baseUrl: 'https://demoqa.com/automation-practice-form', setupNodeEvents(on, config) { } } diff --git a/cypress/e2e/registration.cy.js b/cypress/e2e/registration.cy.js index a64e4c5b..0bc3cd37 100644 --- a/cypress/e2e/registration.cy.js +++ b/cypress/e2e/registration.cy.js @@ -1,11 +1,47 @@ -/// - describe('Student Registration page', () => { before(() => { - + cy.visit(''); }); it('', () => { + it('should register a new student with valid data', () => { + cy.findByPlaceholder('First Name') + .type('Vasiliy'); + cy.findByPlaceholder('Last Name') + .type('Petrov'); + cy.findByPlaceholder('name@example.com') + .type('vpetrov@mail.com'); + cy.get('label[for="gender-radio-1"]').click(); + cy.findByPlaceholder('Mobile Number') + .type('3548952632'); + cy.get('#dateOfBirthInput').click(); + cy.get('.react-datepicker__month-select').select('February'); + cy.get('.react-datepicker__year-select').select('1977'); + cy.get('.react-datepicker__day--020').click(); + cy.get('#subjectsContainer').type('Arts{enter}'); + cy.get('label[for="hobbies-checkbox-2"]').click(); + cy.findByPlaceholder('Current Address') + .type('Saharova 85, Kyiv'); + cy.get('#state').click(); + cy.get('#react-select-3-option-1').click(); + cy.get('#city').click(); + cy.get('#react-select-4-option-2').click(); + cy.get('#submit').click(); + + cy.get('.modal-header').contains('Thanks for submitting the form'); + cy.contains('tr', 'Student Name').should('contain', 'Vasiliy Petrov'); + cy.contains('tr', 'Student Email').should('contain', 'vpetrov@mail.com'); + cy.contains('tr', 'Gender').should('contain', 'Male'); + cy.contains('tr', 'Mobile').should('contain', '3548952632'); + cy.contains('tr', 'Date of Birth').should('contain', 'February'); + cy.contains('tr', 'Date of Birth').should('contain', '1977'); + cy.contains('tr', 'Date of Birth').should('contain', '20'); + cy.contains('tr', 'Subjects').should('contain', 'Arts'); + cy.contains('tr', 'Hobbies').should('contain', 'Reading'); + cy.contains('tr', 'Address').should('contain', 'Saharova 85, Kyiv'); + cy.contains('tr', 'State and City').should('contain', 'Uttar Pradesh'); + cy.contains('tr', 'State and City').should('contain', 'Merrut'); }); }); +}); \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 119ab03f..cc64ab18 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,6 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +Cypress.Commands.add('findByPlaceholder', (placeholder) => { + cy.get(`[placeholder="${placeholder}"]`); + }); \ No newline at end of file