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
- Host: GitHub
- URL: https://github.com/dl0312/cypress-tutorial
- Owner: dl0312
- Created: 2019-08-12T07:17:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T01:47:45.000Z (over 2 years ago)
- Last Synced: 2024-10-11T21:12:47.918Z (9 months ago)
- Language: CSS
- Homepage:
- Size: 3.3 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
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`์์๋ง ์ฐ์ด๋ ์์ฑ์ด ๋ ๊ฒ ์ด๋ค.
```htmlEssential 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)