diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b15abc188aeaeaead05af26b9fed2c8bfc192dc2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +cypress/videos/ +cypress/screenshots/ +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cf5df41dd3ffb97e51bacc0d601ebc1b610f7274 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# SIMCAQ Frontend Run Test Using Cypress + +## Modo de uso + +### Instalando as dependências: +```bash +$ npm install +``` + +### Rodando os tests através da GUI: + +```bash +$ npx cypress run +Executar simcaq-front. +``` + +### Rodando pela CLI: +```bash +$ npx cypress run +``` + +### Arquivo com as especificações do teste: +```bash +./test/simcaq-front.js +``` \ No newline at end of file diff --git a/a b/a deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/cypress.json b/cypress.json new file mode 100644 index 0000000000000000000000000000000000000000..46d84248a6fff9c88595ebb7a0c8b9d9cbf87904 --- /dev/null +++ b/cypress.json @@ -0,0 +1,4 @@ +{ + "baseUrl": "http://simcaq.c3sl.ufpr.br/", + "integrationFolder": "./tests" +} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000000000000000000000000000000000000..da18d9352a17d427321962199a1fa43b8ab5cfe4 --- /dev/null +++ b/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" +} \ No newline at end of file diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js new file mode 100644 index 0000000000000000000000000000000000000000..fd170fba6912bb7909ed2ba96c5ff12e8cd3700f --- /dev/null +++ b/cypress/plugins/index.js @@ -0,0 +1,17 @@ +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 0000000000000000000000000000000000000000..c1f5a772e2bcbd8a318fffcf7ba25e205a92dade --- /dev/null +++ b/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 is will overwrite an existing command -- +// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) diff --git a/cypress/support/index.js b/cypress/support/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d68db96df2697e0835f5c490db0c2cc81673f407 --- /dev/null +++ b/cypress/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/index.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') diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..ac5bb8821abb9a59d8c91f170f87a88fc6ec14d0 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "cypress": "^3.3.2" + }, + "scripts": { + "cypress": "cypress open", + "cy:run": "cypress run" + }, + "devDependencies": { + "cypress": "^3.3.2" + } +} diff --git a/tests/simcaq-front.js b/tests/simcaq-front.js new file mode 100644 index 0000000000000000000000000000000000000000..fc92e256363d3c6a28f53773ea2336c4d09b1271 --- /dev/null +++ b/tests/simcaq-front.js @@ -0,0 +1,173 @@ +const TIMEOUT = {timeout: 130000}; + +describe('1 - CAQ', function() { + it('successfully loads', function() { + cy.clearLocalStorage() + cy.clearCookies() + + cy.server() + cy.route({url: 'api/v1/enrollment**', method: 'GET'}).as('getEnrollment') + cy.route({url: 'api/v1/classroom_count**', method: 'POST'}).as('postApi') + cy.visit('http://simcaq.c3sl.ufpr.br/', { + auth: { + username: 'simcaq', + password: 'simcaqeducacao' + } + }) + cy.wait(1000) + + cy.get('.caq').contains('Acessar').click() + + cy.get('.block-ui-main').should('visible') + cy.wait('@postApi', TIMEOUT) + cy.wait(Array(5).fill('@getEnrollment'), TIMEOUT) + cy.wait(300) + + cy.route({url: 'api/v1/**', method: 'GET'}).as('getApi') + cy.get('.edit-mode').click() + + let apiGetCalls = [1, 1, 0, 1, 0, 3, 1, 1, 0, 4, 1, 0, 4, 0, 1, 0, 0, 7, 3, 0, 0, 0, 0, 0] // Quantidade de get's da api por tela + for (let i = 0; i < 24; i++) { + cy.wait(300) + if (i == 9 || i == 18) // Telas que contêm um post. + cy.wait('@postApi', TIMEOUT) + if (apiGetCalls[i] > 0) + cy.wait(Array(apiGetCalls[i]).fill('@getApi'), TIMEOUT) + + cy.contains('Próximo').click() + } + cy.wait(Array(3).fill('@getApi'), TIMEOUT) + cy.get('.block-ui-main', TIMEOUT).should('not.visible').then(() => {return cy.contains('Finalizar').click()} ) + }) +}) + +describe('2 - Orçamento educacional', function() { + it('successfully loads without selecting a state', function() { + cy.clearLocalStorage() + cy.clearCookies() + + cy.server() + cy.route({url: 'api/v1/enrollment**', method: 'GET'}).as('getEnrollment') + cy.route({url: 'api/v1/classroom_count**', method: 'POST'}).as('postApi') + cy.visit('http://simcaq.c3sl.ufpr.br/', { + auth: { + username: 'simcaq', + password: 'simcaqeducacao' + } + }) + cy.wait(1000) + + cy.get('.planning').contains('Simular').click() + cy.wait('@getEnrollment', TIMEOUT) + cy.wait(300) + + cy.contains('Simular').click() + cy.wait(['@postApi', '@postApi'], TIMEOUT) // Classroom count chamada duas vezes seguidas + cy.wait(Array(5).fill('@getEnrollment'), TIMEOUT) + cy.wait(300) + + cy.get('.edit-mode').click() + cy.route({url: 'api/v1/**', method: 'GET'}).as('getApi') + cy.wait(300) + + cy.contains('4').click() + let apiGetCalls = [0, 1, 2, 0, 1, 0, 3, 1, 1, 0, 4, 1, 0, 4, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0] // Quantidade de get's da api por tela + for (let i = 0; i < 25; i++) { + cy.wait(300) + if (i == 10 || i == 19) // Telas que contêm um post. + cy.wait('@postApi', TIMEOUT) + if (apiGetCalls[i] > 0) + cy.wait(Array(apiGetCalls[i]).fill('@getApi'), TIMEOUT) + + cy.contains('Próximo').click() + } + cy.wait(Array(3).fill('@getApi'), TIMEOUT) + cy.get('.block-ui-main', TIMEOUT).should('not.visible').then(() => {return cy.contains('Finalizar').click()} ) + }) + + it('successfully loads with RS selected', function() { + cy.clearLocalStorage() + cy.clearCookies() + + cy.server() + cy.route({url: 'api/v1/enrollment**', method: 'GET'}).as('getEnrollment') + cy.route({url: 'api/v1/classroom_count**', method: 'POST'}).as('postApi') + cy.visit('http://simcaq.c3sl.ufpr.br/', { + auth: { + username: 'simcaq', + password: 'simcaqeducacao' + } + }) + cy.wait(1000) + + cy.get('.planning').contains('Simular').click() + cy.wait('@getEnrollment', TIMEOUT) + cy.wait(300) + + cy.get('.state-rs').click({force: true}) + cy.wait('@getEnrollment', TIMEOUT) + cy.wait(300) + + cy.contains('Simular').click() + cy.wait(['@postApi', '@postApi'], TIMEOUT) // Classroom count chamada duas vezes seguidas + cy.wait(Array(5).fill('@getEnrollment'), TIMEOUT) + cy.wait(300) + + cy.get('.edit-mode').click() + cy.route({url: 'api/v1/**', method: 'GET'}).as('getApi') + cy.wait(300) + + cy.contains('4').click() + let apiGetCalls = [0, 1, 2, 0, 1, 0, 3, 1, 1, 0, 4, 1, 0, 4, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0] // Quantidade de get's da api por tela + for (let i = 0; i < 25; i++) { + cy.wait(300) + if (i == 10 || i == 19) // Telas que contêm um post. + cy.wait('@postApi', TIMEOUT) + if (apiGetCalls[i] > 0) + cy.wait(Array(apiGetCalls[i]).fill('@getApi'), TIMEOUT) + + cy.contains('Próximo').click() + } + cy.wait(Array(3).fill('@getApi'), TIMEOUT) + cy.get('.block-ui-main', TIMEOUT).should('not.visible').then(() => {return cy.contains('Finalizar').click()} ) + }) +}) + +describe('3 - Fundo de manutenção', function() { + it('successfully loads', function() { + cy.clearLocalStorage() + cy.clearCookies() + + cy.server() + cy.route({url: 'api/v1/enrollment**', method: 'GET'}).as('getEnrollment') + cy.route({url: 'api/v1/classroom_count**', method: 'POST'}).as('postApi') + cy.visit('http://simcaq.c3sl.ufpr.br/', { + auth: { + username: 'simcaq', + password: 'simcaqeducacao' + } + }) + cy.wait(1000) + + cy.get('.financing').contains('Consultar').click() + cy.wait('@postApi', TIMEOUT) + cy.wait(Array(5).fill('@getEnrollment'), TIMEOUT) + cy.wait(10000) + + cy.route({url: 'api/v1/**', method: 'GET'}).as('getApi') + cy.get('.edit-mode').click() + + let apiGetCalls = [1, 1, 0, 1, 0, 3, 1, 1, 0, 4, 1, 0, 4, 0, 1, 0, 0, 7, 3, 0, 0, 0, 0, 0] // Quantidade de get's da api por tela + for (let i = 0; i < 24; i++) { + cy.wait(300) + if (i == 9 || i == 18) // Telas que contêm um post. + cy.wait('@postApi', TIMEOUT) + if (apiGetCalls[i] > 0) + cy.wait(Array(apiGetCalls[i]).fill('@getApi'), TIMEOUT) + + cy.contains('Próximo').click() + } + cy.wait(Array(3).fill('@getApi'), TIMEOUT) + cy.get('.block-ui-main', TIMEOUT).should('not.visible').then(() => {return cy.contains('Finalizar').click()} ) + }) +}) \ No newline at end of file