Neste artigo, você aprenderá:
O que é Cypress e quando usá-lo
Noções básicas de teste usando Cypress
Comandos Cypress avançados
Interagindo com os elementos da interface do usuário
Melhores práticas usando Cypress
Introdução
Para testar seus aplicativos, você precisa realizar as seguintes etapas:
Inicie o aplicativo
Espere o servidor iniciar
( , )
, ( , ..)
. , .
Cypress. Cypress , , :
( , ..)
! Cypress . , , , .
, — , . Cypress .
, Cypress, .
Cypress
, :
, Cypress:
. Linux, , Cypress NPM.
, Cypress , :
(Test Runner):
.
Cypress
Cypress , cypress/integration
. :
JavaScript basicTest.js
:
Cypress, Test Runner :
.
/cypress/integration/basicTest.js
:
1:
describe
Cypress .
2:
it
, .
3: . , 2 + 2 4.
false
, .
, basicTest.js
Cypress.
:
! , .
, ? /cypress/integration/basicTest.js
describe
:
2: 4 5 10, . , .
. :
, . , .
. basicTest.js
:
2: 5 5 100, .
:
! . expect
BDD (behavior-driven) . , (test-driven assertions).
/cypress/integration/basicTest.js
:
(test-driven assertions) assert
TDD assert
.
basicTest.js
:
2:
name
age
.
6:
isObject
,person
.true
,value is object
. , .
10: ,
name
.
14: ,
name
.
. :
! . Cypress.
basicTest.js
:
-
Demoblaze , , .
/cypress/integration/
basicCommandsTest.js
. :
3:
visit
, Cypress - Demoblaze.
basicCommandsTest.js
Test Runner:
:
! . Cypress.
basicCommandsTest.js
:
Cypress:
. , , HTML Cypress.
Cypress JQuery -.
, myButton
id
, :
, myButton
, :
.
The-Internet . - / .
« ».
DevTools, , button
onclick
, addElement()
.
/cypress/integration
runningClickCommand.js
. :
2: -.
6:
button
.
. :
, ! , , Add Element
.
.
username
id
username
, password
id
password
. , Login
type
submit
. , username
password
, JQuery id
:
/cypress/integration
runningTypeCommand.js
. :
3: .
6:
username
type
,tomsmith
.
7:
password
SuperSecretPassword
.
10: «».
. :
! .
DevTools:
type
checkbox
. , form
id
checkboxes
. JQuery -:
/cypress/integration/
runningCheckCommand.js
:
4: ,
check
, .
7: Cypress .
8: .
uncheck
, .
. :
! . Cypress.
. , HTML, , ul
li
.
should
. — The-Internet’s Add Element
Delete
added-manually
. button
:
:
, :
:
/cypress/integration/runningClickCommand.js
:
1:
added-manually
. , (have.length)
.
3:
Add Element
, , (have.text)
Add Element
.
. :
! . each
.
cypress/integration/runningClickCommand.js
:
each
The-Internet’s Add Elements page:
, Delete
. ; , Delete
. , .
- each
. , . Delete
click
.
Developer Tools:
Delete
class
added-manually
. each
, :
/cypress/integration/runningClickCommand.js
:
2: ,
.added-manually
.$el
.
3: , Cypress. .
:
! , .
:
:
2: , Cypress,
Add Element
20 .
. :
, - . !
, Cypress.
cypress/integration/runningClickCommand.js
:
, . :
Test Runner :
Cypress , . , :
, :
:
, get
type
. , .
cypress/support/commands.js
:
1: ,
identifier
data
.
2: , .
. /cypress/support/commands.js
.
:
, .
«»
:
HTML id
first
.
Cypress . , , :
and
should
.
Cypress
localhost
, , Cypress.
GitHub
GitHub
O teste é uma etapa importante no processo de desenvolvimento porque garante que seu aplicativo funcione corretamente. Alguns programadores preferem testar manualmente seus programas porque escrever testes exige uma quantidade significativa de tempo e energia. Felizmente, o Cypress resolveu esse problema permitindo que o desenvolvedor escrevesse testes em um curto espaço de tempo.
Obrigado por chegar ao fim! Se você sentir alguma confusão, eu aconselho você a brincar com o código e passar pelos exemplos.