Skip to content

dl0312/cypress-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cypress Tutorial

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 ์•Œ์•„๋ณด๊ธฐ"๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

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

์™œ ๋˜ ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•œ๊ฐ€?

๊ธฐ์กด์˜ ํ…Œ์ŠคํŠธ๋Š” ๋„ˆ๋ฌด ์–ด๋ ต๋‹ค.

๊ธฐ์กด ๊ฐœ๋ฐœ์ž๋“ค์ด ํ…Œ์ŠคํŠธ ๋„๊ตฌ์— ๊ฐ€์ง€๋Š” ๋ถˆ๋งŒ์ด ๋ฌด์—‡์ธ๊ฐ€?

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

๋Œ€๋ถ€๋ถ„์€ Selenium์„ ์‚ฌ์šฉํ•œ e2e ํ…Œ์ŠคํŠธ ๋„๊ตฌ๋“ค์˜ ๋ฌธ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์•˜๋‹ค.

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

Cypress with Vue.js

์šฐ์„  vue-cli@3.x ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ , ์ถ”๊ฐ€ ์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•ด์ค€๋‹ค.

$ 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 <space> to select, <a> to toggle all, <i> 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 ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์ด๋‹ค.

// 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์—์„œ๋งŒ ์“ฐ์ด๋Š” ์†์„ฑ์ด ๋  ๊ฒƒ ์ด๋‹ค.

<h3>Essential Links</h3>
<ul data-cy="links">
    <li>
    <a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
    </li>
    <li>
    <a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a>
    </li>
    <li>
    <a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a>
    </li>
    <li>
    <a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a>
    </li>
    <li>
    <a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
    </li>
</ul>

๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๋งํฌ์˜ ๊ฐฏ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

// 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๋ฅผ ์ด์šฉํ•œ๋‹ค.

$ yarn test:e2e

๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์‹œ๊ฐ„์ด ์ข€ ์ง€๋‚˜๋ฉด ๋ธŒ๋ผ์šฐ์ € ํ˜•ํƒœ์˜ cypress ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋˜๋ฉด์„œ ํ…Œ์ŠคํŠธ๊ฐ€ ์ง„ํ–‰๋  ๊ฒƒ์ด๋‹ค.

References

About

๐Ÿ‘ถ It's time to study cypress

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published