From 14f068e0f61d801e434719f5191fb03d7a5d234d Mon Sep 17 00:00:00 2001 From: Helen Lazarotti Date: Fri, 4 Aug 2023 17:46:37 -0300 Subject: [PATCH] Adicionando testes cypress --- .gitignore | 1 + cypress.json | 1 + cypress/fixtures/example.json | 5 + cypress/integration/weather.spec.js | 19 + cypress/plugins/index.js | 22 + cypress/support/commands.js | 25 + cypress/support/index.js | 20 + index.html | 6 +- package-lock.json | 3417 +++++++++++++++++++++++++++ package.json | 9 + 10 files changed, 3522 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 cypress.json create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/integration/weather.spec.js create mode 100644 cypress/plugins/index.js create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/cypress.json b/cypress.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/cypress.json @@ -0,0 +1 @@ +{} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /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" +} diff --git a/cypress/integration/weather.spec.js b/cypress/integration/weather.spec.js new file mode 100644 index 0000000..5918449 --- /dev/null +++ b/cypress/integration/weather.spec.js @@ -0,0 +1,19 @@ +describe("Weather", () => { + const url = "http://127.0.0.1:5500/index.html"; + + before(() => { + cy.visit({url}) + }); + + it("Deve escrever nome da cidade no campo de input", () => { + cy.wait(1000); + cy.get('[data-test="city-field"]').type('Arroio do Sal'); + cy.get('[data-test="search-button"]').should('exist'); + cy.get('[data-test="search-button"]').click(); + }); + + + it("Deve aparecer no título, a palavra digitada", () => { + cy.get('[data-test="city-span-field"]').should('have.text', 'Arroio do Sal') + }); +}) \ No newline at end of file diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js new file mode 100644 index 0000000..59b2bab --- /dev/null +++ b/cypress/plugins/index.js @@ -0,0 +1,22 @@ +/// +// *********************************************************** +// 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) + +/** + * @type {Cypress.PluginConfig} + */ +// eslint-disable-next-line no-unused-vars +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 0000000..119ab03 --- /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 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 0000000..d68db96 --- /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/index.html b/index.html index ec8349f..8c654d1 100644 --- a/index.html +++ b/index.html @@ -15,8 +15,8 @@

Confira o clima de uma cidade:

- -