From 91725302287430c6d1301af1713aed51dec59a4e Mon Sep 17 00:00:00 2001 From: Kate Hubko Date: Tue, 3 Sep 2024 15:27:17 +0300 Subject: [PATCH 1/4] Advanced --- cypress.config.js | 17 +++++++++-------- cypress/e2e/signUp.cy.js | 16 ++++++++++++++++ cypress/support/commands.js | 11 +++++++++++ cypress/support/generate.js | 10 ++++++++++ 4 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 cypress/support/generate.js diff --git a/cypress.config.js b/cypress.config.js index d811e2a..d2a59e0 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,9 +1,10 @@ -const { defineConfig } = require('cypress'); - -module.exports = defineConfig({ +module.exports = { e2e: { - setupNodeEvents(on, config) { - // implement node event listeners here - } - } -}); + baseUrl: 'https://react-redux.realworld.io', + viewportWidth: 650, + viewportHeight: 850, + defaultCommandTimeout: 10000, + }, +}; + + diff --git a/cypress/e2e/signUp.cy.js b/cypress/e2e/signUp.cy.js index 87cc96d..4a587d4 100644 --- a/cypress/e2e/signUp.cy.js +++ b/cypress/e2e/signUp.cy.js @@ -1,5 +1,21 @@ +/// + +import { generateUser } from '../support/generate'; + describe('Sign Up page', () => { it('should provide an ability to register new account', () => { + const user = generateUser(); + + // Перехід на сторінку реєстрації з правильним URL + cy.visit('/#/register'); + + // Взаємодія з елементами форми реєстрації + cy.get('input[placeholder="Username"]').type(user.username); + cy.get('input[placeholder="Email"]').type(user.email); + cy.get('input[placeholder="Password"]').type(user.password); + cy.get('button[type="submit"]').click(); + // Перевірка успішної реєстрації + cy.get('.navbar').should('contain', user.username); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 119ab03..135bce1 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,14 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +import { faker } from '@faker-js/faker'; + + +Cypress.Commands.add('generateUser', () => { + const randomNumber = Math.random().toString().slice(2, 6); + const username = faker.internet.userName() + '_' + randomNumber; + const email = `${username}@mail.com`; + const password = '12345Qwert!'; + + return { email, password, username }; +}); diff --git a/cypress/support/generate.js b/cypress/support/generate.js new file mode 100644 index 0000000..c63ecc0 --- /dev/null +++ b/cypress/support/generate.js @@ -0,0 +1,10 @@ +import { faker } from '@faker-js/faker'; + +export function generateUser() { + const randomNumber = Math.random().toString().slice(2, 6); + const username = faker.internet.userName() + '_' + randomNumber; + const email = `${username}@mail.com`; + const password = '12345Qwert!'; + + return { email, password, username }; +} From 39ed32cf6c681ed8c3c986bcf1d6dbd000c32426 Mon Sep 17 00:00:00 2001 From: Kate Hubko Date: Tue, 3 Sep 2024 15:31:46 +0300 Subject: [PATCH 2/4] Advanced --- cypress.config.js | 2 -- cypress/e2e/signUp.cy.js | 5 ++--- cypress/support/commands.js | 1 - cypress/support/generate.js | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index d2a59e0..47386ff 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -6,5 +6,3 @@ module.exports = { defaultCommandTimeout: 10000, }, }; - - diff --git a/cypress/e2e/signUp.cy.js b/cypress/e2e/signUp.cy.js index 4a587d4..226ac4c 100644 --- a/cypress/e2e/signUp.cy.js +++ b/cypress/e2e/signUp.cy.js @@ -6,16 +6,15 @@ describe('Sign Up page', () => { it('should provide an ability to register new account', () => { const user = generateUser(); - // Перехід на сторінку реєстрації з правильним URL cy.visit('/#/register'); - // Взаємодія з елементами форми реєстрації + cy.get('input[placeholder="Username"]').type(user.username); cy.get('input[placeholder="Email"]').type(user.email); cy.get('input[placeholder="Password"]').type(user.password); cy.get('button[type="submit"]').click(); - // Перевірка успішної реєстрації + cy.get('.navbar').should('contain', user.username); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 135bce1..0cfda60 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -25,7 +25,6 @@ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) import { faker } from '@faker-js/faker'; - Cypress.Commands.add('generateUser', () => { const randomNumber = Math.random().toString().slice(2, 6); const username = faker.internet.userName() + '_' + randomNumber; diff --git a/cypress/support/generate.js b/cypress/support/generate.js index c63ecc0..9bbce87 100644 --- a/cypress/support/generate.js +++ b/cypress/support/generate.js @@ -5,6 +5,6 @@ export function generateUser() { const username = faker.internet.userName() + '_' + randomNumber; const email = `${username}@mail.com`; const password = '12345Qwert!'; - + return { email, password, username }; } From 21fb71420d3f47214f80a20f7aa917fa818596cf Mon Sep 17 00:00:00 2001 From: Kate Hubko Date: Tue, 3 Sep 2024 15:38:43 +0300 Subject: [PATCH 3/4] Advance1d --- cypress.config.js | 1 + cypress/e2e/signUp.cy.js | 1 + cypress/support/commands.js | 1 + cypress/support/e2e.js | 1 + cypress/support/generate.js | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cypress.config.js b/cypress.config.js index 47386ff..e9ae5dd 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,3 +1,4 @@ + module.exports = { e2e: { baseUrl: 'https://react-redux.realworld.io', diff --git a/cypress/e2e/signUp.cy.js b/cypress/e2e/signUp.cy.js index 226ac4c..dee8c9d 100644 --- a/cypress/e2e/signUp.cy.js +++ b/cypress/e2e/signUp.cy.js @@ -1,3 +1,4 @@ + /// import { generateUser } from '../support/generate'; diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 0cfda60..c2b7ffa 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,6 +23,7 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + import { faker } from '@faker-js/faker'; Cypress.Commands.add('generateUser', () => { diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 5df9c01..f0f87d9 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -14,6 +14,7 @@ // *********************************************************** // Import commands.js using ES2015 syntax: + import './commands'; // Alternatively you can use CommonJS syntax: diff --git a/cypress/support/generate.js b/cypress/support/generate.js index 9bbce87..1dba1b0 100644 --- a/cypress/support/generate.js +++ b/cypress/support/generate.js @@ -1,3 +1,4 @@ + import { faker } from '@faker-js/faker'; export function generateUser() { @@ -5,6 +6,6 @@ export function generateUser() { const username = faker.internet.userName() + '_' + randomNumber; const email = `${username}@mail.com`; const password = '12345Qwert!'; - + return { email, password, username }; } From 42000bd10ba568eaac56b13a1a7573281984bea5 Mon Sep 17 00:00:00 2001 From: Kate Hubko Date: Tue, 3 Sep 2024 15:43:31 +0300 Subject: [PATCH 4/4] qwed --- cypress.config.js | 1 - cypress/e2e/signUp.cy.js | 1 - cypress/support/commands.js | 1 - cypress/support/e2e.js | 1 - cypress/support/generate.js | 1 - 5 files changed, 5 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index e9ae5dd..47386ff 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,4 +1,3 @@ - module.exports = { e2e: { baseUrl: 'https://react-redux.realworld.io', diff --git a/cypress/e2e/signUp.cy.js b/cypress/e2e/signUp.cy.js index dee8c9d..226ac4c 100644 --- a/cypress/e2e/signUp.cy.js +++ b/cypress/e2e/signUp.cy.js @@ -1,4 +1,3 @@ - /// import { generateUser } from '../support/generate'; diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c2b7ffa..0cfda60 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,7 +23,6 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) - import { faker } from '@faker-js/faker'; Cypress.Commands.add('generateUser', () => { diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index f0f87d9..5df9c01 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -14,7 +14,6 @@ // *********************************************************** // Import commands.js using ES2015 syntax: - import './commands'; // Alternatively you can use CommonJS syntax: diff --git a/cypress/support/generate.js b/cypress/support/generate.js index 1dba1b0..c63ecc0 100644 --- a/cypress/support/generate.js +++ b/cypress/support/generate.js @@ -1,4 +1,3 @@ - import { faker } from '@faker-js/faker'; export function generateUser() {