반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- https
- e2e
- caching
- csr
- http3
- vue3
- 비동기
- vue
- custom command
- ViTE
- QUIC
- aws
- CloudFlare
- CSS
- devtools
- 선택자
- msw
- api test
- TLS
- Cypress
- rendering
- Testing
- web vital
- SSR
- JavaScript
- import.meta.env
- typeScript
- vue-cli
- ts error
- svelte
Archives
- Today
- Total
Develop Note by J.S.
[Cypress] 선택자 & Custom Command 본문
반응형
Cypress의 선택자의 경우 아래 이미지와 같은 방법이 있으며, Cypress 공식 문서에 따르면 변화의 가능성이 낮은 방법이 안전하다고 명시되어 있습니다 .
Cypress 테스팅 코드 작성 시 자주 사용되는 기능을 Custome Command로 설정하여 코드를 효율적으로 작성 할 수 있습니다. Command 사용법에 대한 간단한 예제입니다.
1. cypress/support/command.ts
// cy.get() Command등록
Cypress.Commands.add('dataCy', (selector) => {
return cy.get(`[data-cy=${selector}]`)
})
2. cypress/support/e2e.ts
import './commands'
3. cypress/support/index.d.ts
// typescript 사용 시 global.d.ts 파일 추가
declare namespace Cypress {
interface Chainable {
dataCy(dataTestAttribute: string): Chainable<JQuery<HTMLElement>> // 사용 command정의
}
}
4. Command 사용
describe('Login page', () => {
it('URL 접근 시 로그인 페이지를 확인한다.', () => {
cy.visit('/')
cy.dataCy('header').contain('h1', 'You did it!')
})
})
참고사이트
https://www.programsbuzz.com/article/cypress-typescript-custom-commands
반응형
'FrontEnd > Cypress' 카테고리의 다른 글
[Cypress] Custom Command Test (0) | 2023.07.18 |
---|---|
[Cypress] Cypress + MSW (0) | 2023.07.17 |
[Cypress] Api Test (0) | 2023.07.12 |
[Cypress] Cypress Methods & Assertions정리 (0) | 2023.07.12 |
[Cypress] Vite + Cypress (0) | 2023.07.10 |