From ee84a67bfa077b3d0a6f0c0393afc22a39df2c9f Mon Sep 17 00:00:00 2001 From: Arbona Alapont Date: Fri, 17 Nov 2023 13:57:42 +0100 Subject: [PATCH] cypress test --- .gitignore | 8 ++++- templates/base.html | 2 +- templates/index.html | 1 + templates/new_topic.html | 1 + tests/cypress/cypress.config.js | 20 +++++++++++ tests/cypress/cypress/e2e/create-group.cy.js | 22 ++++++++++++ tests/cypress/cypress/e2e/create_topic.cy.js | 35 ++++++++++++++++++++ tests/cypress/cypress/fixtures/example.json | 5 +++ tests/cypress/cypress/support/commands.js | 25 ++++++++++++++ tests/cypress/cypress/support/e2e.js | 20 +++++++++++ tests/cypress/package.json | 5 +++ 11 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 tests/cypress/cypress.config.js create mode 100644 tests/cypress/cypress/e2e/create-group.cy.js create mode 100644 tests/cypress/cypress/e2e/create_topic.cy.js create mode 100644 tests/cypress/cypress/fixtures/example.json create mode 100644 tests/cypress/cypress/support/commands.js create mode 100644 tests/cypress/cypress/support/e2e.js create mode 100644 tests/cypress/package.json diff --git a/.gitignore b/.gitignore index 52f67ba..3ff3f83 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,10 @@ dmypy.json .idea #poetry -poetry.lock \ No newline at end of file +poetry.lock + +# Node +tests/cypress/node_modules + +#Visual Studio Code +tests/cypress/package-lock.json \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index c3d197c..90a22a8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -125,7 +125,7 @@

♠ PyLabar ♠

{% if username %} {% endif %} {% block content %}{% endblock %} diff --git a/templates/index.html b/templates/index.html index c49e90e..43a0f24 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,6 +43,7 @@

Pylabar - Log in

diff --git a/templates/new_topic.html b/templates/new_topic.html index 1b0d9f1..906d9c1 100644 --- a/templates/new_topic.html +++ b/templates/new_topic.html @@ -57,6 +57,7 @@

Nuevo topic

diff --git a/tests/cypress/cypress.config.js b/tests/cypress/cypress.config.js new file mode 100644 index 0000000..5c94096 --- /dev/null +++ b/tests/cypress/cypress.config.js @@ -0,0 +1,20 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + env: { + CYPRESS_BASE_URL: "http://localhost:80", + CYPRESS_USERNAME: "Juanjo", + CYPRESS_PASSWORD: "pass123" + }, + + production: { + CYPRESS_BASE_URL: "https://www.example.com", + CYPRESS_USERNAME: "production_user", + CYPRESS_PASSWORD: "tu_contraseña_produccion", + }, + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/tests/cypress/cypress/e2e/create-group.cy.js b/tests/cypress/cypress/e2e/create-group.cy.js new file mode 100644 index 0000000..6e4d5dc --- /dev/null +++ b/tests/cypress/cypress/e2e/create-group.cy.js @@ -0,0 +1,22 @@ +describe('template spec', () => { + beforeEach(() => { + cy.viewport(2048, 1043); + + cy.visit(Cypress.env("CYPRESS_BASE_URL")); + cy.wait(1000); + + cy.get('#user_code').type(Cypress.env("CYPRESS_USERNAME")); + cy.wait(1000); + + cy.get('#password').type( + Cypress.env("CYPRESS_PASSWORD") + ); + cy.wait(1000); + cy.get("#login-button").click(); + cy.wait(1000); + cy.url().should("include", "/home"); + }); + it('passes', () => { + cy.visit('https://example.cypress.io') + }) +}) \ No newline at end of file diff --git a/tests/cypress/cypress/e2e/create_topic.cy.js b/tests/cypress/cypress/e2e/create_topic.cy.js new file mode 100644 index 0000000..bcc3dfe --- /dev/null +++ b/tests/cypress/cypress/e2e/create_topic.cy.js @@ -0,0 +1,35 @@ +describe('template spec', () => { + beforeEach(() => { + cy.viewport(2048, 1043); + + cy.visit(Cypress.env("CYPRESS_BASE_URL")); + cy.wait(1000); + + cy.get('#user_code').type(Cypress.env("CYPRESS_USERNAME")); + cy.wait(1000); + + cy.get('#password').type( + Cypress.env("CYPRESS_PASSWORD") + ); + cy.wait(1000); + cy.get("#login-button").click(); + cy.wait(1000); + cy.url().should("include", "/home"); + }); + it('passes', () => { + cy.log("Vamos a crear un topic"); + cy.get("#new-topic-button").click(); + cy.wait(1000); + cy.get('#title').type("Prueba cypress"); + cy.wait(1000); + cy.get("#close_date").type("2024-12-30"); + cy.wait(1000); + cy.get('#group').find('option').first().then(($option) => { + const valorPrimerElemento = $option.attr('value'); + + cy.get('#group').select(valorPrimerElemento); + }); + cy.wait(1000); + cy.get("#save-topic-button").click(); + }) +}) \ No newline at end of file diff --git a/tests/cypress/cypress/fixtures/example.json b/tests/cypress/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/tests/cypress/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/tests/cypress/cypress/support/commands.js b/tests/cypress/cypress/support/commands.js new file mode 100644 index 0000000..66ea16e --- /dev/null +++ b/tests/cypress/cypress/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// 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) => { ... }) \ No newline at end of file diff --git a/tests/cypress/cypress/support/e2e.js b/tests/cypress/cypress/support/e2e.js new file mode 100644 index 0000000..0e7290a --- /dev/null +++ b/tests/cypress/cypress/support/e2e.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/e2e.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') \ No newline at end of file diff --git a/tests/cypress/package.json b/tests/cypress/package.json new file mode 100644 index 0000000..da63a8e --- /dev/null +++ b/tests/cypress/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "cypress": "^13.5.1" + } +}