An open API service indexing awesome lists of open source software.

https://github.com/dl0312/cypress-tutorial

๐Ÿ‘ถ It's time to study cypress
https://github.com/dl0312/cypress-tutorial

Last synced: 3 months ago
JSON representation

๐Ÿ‘ถ It's time to study cypress

Awesome Lists containing this project

README

        

# Cypress Tutorial

[cypress](https://github.com/cypress-io/cypress) - Fast, easy and reliable testing for anything that runs in a browser.
* OpenSource Project(MIT License)
* Browser Support: `Electron`, `Chrome`
* Element ์ ‘๊ทผ: `Iframe`์— `Target Web`์„ ์˜ฌ๋ฆฐ ๋’ค `Browser` ๋‚ด๋ถ€์—์„œ ์ ‘๊ทผํ•จ.
* Headless Support: ์ง€์›
* CLI Support: ์ง€์›
* ScreenShot: ์ง€์›
* Video Record: `Electron`๋งŒ ์ง€์›
* ์‹ฌํ”Œํ•œ API ์ œ๊ณต
* `Mocha` ๊ธฐ๋ฐ˜์ด๊ธฐ ๋•Œ๋ฌธ์— `Nodejs` ๊ฐœ๋ฐœ์ž๋“ค์—๊ฒŒ ์ต์ˆ™ํ•ฉ๋‹ˆ๋‹ค.
* ๋‚ด๋ถ€์ ์œผ๋กœ `queue`๋ฅผ ์จ์„œ `sync`์ธ๊ฒƒ ์ฒ˜๋Ÿผ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.

## Cypress๋Š” ๋ฌด์—‡์ธ๊ฐ€?
`cypress`๋Š” e2eEnd to End testing framework์ด๋‹ค. ๊ฐœ๋ฐœ์ž ์ž…์žฅ์—์„œ ํ”„๋กœ๊ทธ๋žจ์˜ ๋ชจ๋“ˆ์„ ๊ฒ€์ฆํ•˜๋Š” ์œ ๋‹› ํ…Œ์ŠคํŠธ์™€ ๋‹ฌ๋ฆฌ e2e test๋Š” ์‚ฌ์šฉ์ž ์ž…์žฅ์—์„œ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ์„ ๋œปํ•œ๋‹ค. e2e ํ…Œ์ŠคํŠธ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ "[E2E Test ์•Œ์•„๋ณด๊ธฐ](https://medium.com/hbsmith/e2e-test-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0-3c524862469d)"๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

`cypress`๋Š” ๊ฐ ํ…Œ์ŠคํŠธ์˜ ๊ณผ์ •์„ ์›นํŽ˜์ด์ง€๋ฅผ ํ†ตํ•ด ๋ณด์—ฌ์ฃผ๋Š” ๋งค์šฐ ์‹œ๊ฐ์  ๋„๊ตฌ์ด๋‹ค. ๋˜ํ•œ, ๊ฐ ํ…Œ์ŠคํŠธ ์‹œํ–‰์„ ์Šค๋ƒ…์ƒท์ฒ˜๋Ÿผ ์ฐ์–ด ํ•ด๋‹น ํ…Œ์ŠคํŠธํ™˜๊ฒฝ์œผ๋กœ๋„ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

## ์™œ ๋˜ ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•œ๊ฐ€?
๊ธฐ์กด์˜ ํ…Œ์ŠคํŠธ๋Š” ๋„ˆ๋ฌด ์–ด๋ ต๋‹ค.

๊ธฐ์กด ๊ฐœ๋ฐœ์ž๋“ค์ด ํ…Œ์ŠคํŠธ ๋„๊ตฌ์— ๊ฐ€์ง€๋Š” ๋ถˆ๋งŒ์ด ๋ฌด์—‡์ธ๊ฐ€?
* ๊ธฐ๋ณธ ์„ค์ •์ด ์–ด๋ ต๋‹ค - ์ง„์ž…์žฅ๋ฒฝ์ด ๋†’๋‹ค.
* ์ž‘์„ฑ - ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์–ด๋ ต๋‹ค.
* ๊ด€๋ฆฌ - ํ•ด๋‹น ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ต๊ณ  ๋‹ค๋ฃจ๊ธฐ ์–ด๋ ต๋‹ค.

๋Œ€๋ถ€๋ถ„์€ Selenium์„ ์‚ฌ์šฉํ•œ e2e ํ…Œ์ŠคํŠธ ๋„๊ตฌ๋“ค์˜ ๋ฌธ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์•˜๋‹ค.
* ์›น์˜ ๋ฐœ์ „Evolution - AJAX์˜ ๋“ฑ์žฅ์œผ๋กœ ์›น์˜ ๊ตฌ์กฐ๊ฐ€ ์ ์  ๋” ๋ณต์žกํ•ด์กŒ๋‹ค.
* ๋น„๋™๊ธฐ ์ฝ”๋“œAsync Code
* ๊ตฌ์กฐArchitecture
* ์ œ์–ดControl - ๊ฐœ๋ฐœ์ž๊ฐ€ ์™„์ „ํ•œ ํ†ต์ œ๊ถŒ์„ ๊ฐ€์ง€์ง€ ๋ชปํ•œ๋‹ค.
* ์†๋„Speed - ๋„ˆ๋ฌด๋„ˆ๋ฌด ๋А๋ ธ๋‹ค.

# Cypress with Vue.js
์šฐ์„  `vue-cli`@3.x ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ , ์ถ”๊ฐ€ ์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•ด์ค€๋‹ค.
```shell
$ vue create cypress-tutorial
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Linter, E2E
? Pick a linter / formatter config: Basic
? Pick additional lint features: (Press to select, to toggle all, to invert selection)Lint on save
? Pick a E2E testing solution: Cypress
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
```

์„ค์น˜๊ฐ€ ๋งˆ๋ฌด๋ฆฌ๋˜๋ฉด, `tests/e2e`๋ผ๋Š” e2e ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํด๋”๊ฐ€ ์ƒ๊ธด๋‹ค.
๊ทธ๋ฆฌ๊ณ , `tests/e2e/specs` ํด๋”์— ์žˆ๋Š” `test.js`๊ฐ€ ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•  e2e ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์ด๋‹ค.
```js
// test.js
// https://docs.cypress.io/api/introduction/api.html
describe('My First Test', () => {
it('Visits the app root url', () => {
cy.visit('/')
cy.contains('h1', 'Welcome to Your Vue.js App')
})
})
```
์ด ์ฝ”๋“œ๋ฅผ ํ™”๋ฉด ์ค‘๊ฐ„์— ๋‚˜์˜ค๋Š” ๋งํฌ์˜ ๊ฐฏ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋Š” ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟ”๋ณด์ž ์šฐ์„  `HelloWorld.vue` ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์•ผํ•œ๋‹ค.
Essential Links ์•„๋ž˜ ์žˆ๋Š” ul tag์— `data-cy="links"`๋ผ๋Š” ์†์„ฑ์„ ์ฃผ์ž…ํ•œ๋‹ค. ์ด ์†์„ฑ์€ `cypress`์—์„œ๋งŒ ์“ฐ์ด๋Š” ์†์„ฑ์ด ๋  ๊ฒƒ ์ด๋‹ค.
```html

Essential Links



```
๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๋งํฌ์˜ ๊ฐฏ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.
```js
// test.js
// https://docs.cypress.io/api/introduction/api.html
describe('Test main page', () => {
beforeEach(() => {
cy.visit('http://localhost:8080')
})
it('check links', () => {
cy.get('[data-cy=links]')
.children()
.should('have.length', 5)
})
})
```
์ด์ œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๊ฐ€ ์ž˜ ๋™์ž‘ํ•˜๋Š” ์ง€ ํ™•์ธํ•˜๋Š” ์ผ๋งŒ ๋‚จ์•˜๋‹ค. ๋ช…๋ น์–ด๋Š” `vue-cli`๋กœ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ `yarn test:e2e`๋ฅผ ์ด์šฉํ•œ๋‹ค.
```shell
$ yarn test:e2e
```
๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์‹œ๊ฐ„์ด ์ข€ ์ง€๋‚˜๋ฉด ๋ธŒ๋ผ์šฐ์ € ํ˜•ํƒœ์˜ `cypress` ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๋ฉด์„œ ํ…Œ์ŠคํŠธ๊ฐ€ ์ง„ํ–‰๋  ๊ฒƒ์ด๋‹ค.

## References
* ๐Ÿ“น[Testing The Way It Should Be (aka Intro Into Cypress)](https://youtu.be/pJ349YntoIs)
* ๐Ÿ“น[Cypress Official Tutorial Videos](https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices)