1 of 16

INTRODUCCIÓN A TEST FUNCIONALES CON CYPRESSIO

ZARAGOZA 3-5 JUNIO

DRUPALCAMP SPAIN 2022

2 of 16

INFORMACIÓN DEL PONENTE

1

Desarrollador Drupal desde 2011. �Actualmente colaborando con Drupal Association.

DRUPALCAMP Zaragoza 2022

BIOGRAFÍA

NOMBRE Y APELLIDOS

CONTACTO

Fran García-Linares

3 of 16

AGENDA

2

DRUPALCAMP Zaragoza 2022

OBJETIVO: añadir test funcionales a un proyecto (Drupal).

Lo haremos en formato taller.

Primera parte (Fran):

  • Sitio desde cero + primeros tests
  • Integración con sitio externo!!
  • Integración con Drupal 7
  • Integración con Drupal 8/9/10 + tests
  • ¿Y ahora qué?

Segunda parte (Oskar)

4 of 16

NECESITAMOS

3

DRUPALCAMP Zaragoza 2022

Terminal con:

  • npm
  • php
    • O cualquier servidor php que tenga npm.

No hace falta para el taller, pero todo lo que vamos a ver está aquí:

https://github.com/fjgarlin/drupal-and-cypressio

5 of 16

Sitio en blanco: primeros pasitos

4

DRUPALCAMP Zaragoza 2022

mkdir blank-site

cd blank-site

echo "<a href=about.html'>About</a>" > index.html

echo "About" > about.html

php -S localhost:2020

… add small details

 

Crea el sitio

6 of 16

Sitio en blanco: primeros pasitos

4

DRUPALCAMP Zaragoza 2022

npm install cypress --save-dev

touch cypress/e2e/first_test.cy.js

...añade test (código en la siguiente)

./node_modules/.bin/cypress open (or npx cypress open)

...click en “first_test.cy.js”

 

Añadir CypressIO

7 of 16

Sitio en blanco: primeros pasitos

4

DRUPALCAMP Zaragoza 2022

describe('Seccion About', () => {

it('Va a about', () => {

cy.visit('http://localhost:2020')

cy.contains('About').click()

cy.url().should('include', '/about')

})

})

Todo este ejemplo: https://github.com/fjgarlin/drupal-and-cypressio/blob/main/blank-site.sh

 

Test: código

8 of 16

¿Sitio externo? ¿Y por qué no?

5

DRUPALCAMP Zaragoza 2022

describe('Programa', () => {

it('Va al programa', () => {

cy.visit('https://2022.drupalcamp.es')

cy.contains('Programa').click()

cy.url().should('include', '/programa')

cy.contains('Testing con Cypress')

})

})

 

Crea carpeta para el proyecto, añade cypress:

https://github.com/fjgarlin/drupal-and-cypressio/blob/main/drupalcamp.sh

Y escribe el siguiente test:

9 of 16

Integración Drupal 7

6

DRUPALCAMP Zaragoza 2022

...

cy.visit('http://locahost:7777')

cy.contains('Create new account').click()

cy.url().should('include', '/register')

...

cy.get('input[name=name]').type('Fran Garcia') cy.get('input[name=mail]').type(fjgarlin@gmail.com{enter}')

cy.contains('Thank you').should('be.visible')

 

Test para el registro de usuarios:

Crea un proyecto Drupal 7 y añade CypressIO:

https://github.com/fjgarlin/drupal-and-cypressio/blob/main/d7-site.sh

10 of 16

Integración Drupal 8/9/10…

7

DRUPALCAMP Zaragoza 2022

Crea un proyecto Drupal 9 y añade CypressIO:

https://github.com/fjgarlin/drupal-and-cypressio/blob/main/d8-site.sh

Añade baseUrl para todos los test:

..."baseUrl": "http://localhost:8888"... > cypress.config.js

Tests:

  • Comprobar que la página existe
  • Comprobar idiomas
  • Comprobar login

11 of 16

Integración Drupal 8/9/10…

7

DRUPALCAMP Zaragoza 2022

Comprobar página:

cy.visit('/')

cy.contains('Recipes').click()

cy.url().should('include', '/recipes')

12 of 16

Integración Drupal 8/9/10…

7

DRUPALCAMP Zaragoza 2022

Comprobar idiomas:

cy.visit('/')

cy.contains('Español').click()

cy.url().should('include', '/es')

cy.contains('Recetas').click()

cy.contains('Crema catalana').should('be.visible')

13 of 16

Integración Drupal 8/9/10…

7

DRUPALCAMP Zaragoza 2022

Comprobar login:

cy.visit('/user/login')

cy.get('input[name=name]').type('admin')

cy.get('input[name=pass]').type('admin{enter}')

cy.url().should('include', '/user/1')

cy.get('h1').should('contain', 'admin')

14 of 16

¿Y ahora qué?

8

DRUPALCAMP Zaragoza 2022

Empezar es más fácil de lo que pensabas.

Ahora seguimos con Oskar :-)

Documentación adicional:

https://docs.cypress.io/guides/overview/why-cypress.html

  • Integración con CI
  • Test en distintos navegadores
  • Tests visuales

15 of 16

AGRADECIMIENTOS

5

DRUPALCAMP Zaragoza 2022

PLATINUM

GOLD

SILVER

BRONZE

COLABORADORES

16 of 16

ZARAGOZA 3-5 JUNIO

DRUPALCAMP SPAIN 2022