Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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

Last synced: 11 days 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)