메인 컨텐츠로 건너뛰기

테스트 작성하기

테스트러너 프레임워크 지원

@wdio/visual-service는 테스트 러너 프레임워크에 구애받지 않습니다. 즉, WebdriverIO가 지원하는 모든 프레임워크에서 사용할 수 있습니다:

테스트 내에서 스크린샷을 _저장_하거나 테스트 중인 어플리케이션의 현재 시각적 상태를 기준 이미지와 비교할 수 있습니다. 이를 위해 서비스는 커스텀 매처확인 메서드를 제공합니다:

describe('Mocha Example', () => {
beforeEach(async () => {
await browser.url('https://webdriver.io')
})

it('using visual matchers to assert against baseline', async () => {
// Check screen to exactly match with baseline
await expect(browser).toMatchScreenSnapshot('partialPage')
// check an element to have a mismatch percentage of 5% with the baseline
await expect(browser).toMatchScreenSnapshot('partialPage', 5)
// check an element with options for `saveScreen` command
await expect(browser).toMatchScreenSnapshot('partialPage', {
/* some options */
})

// Check an element to exactly match with baseline
await expect($('#element-id')).toMatchElementSnapshot('firstButtonElement')
// check an element to have a mismatch percentage of 5% with the baseline
await expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', 5)
// check an element with options for `saveElement` command
await expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', {
/* some options */
})

// Check a full page screenshot match with baseline
await expect(browser).toMatchFullPageSnapshot('fullPage')
// Check a full page screenshot to have a mismatch percentage of 5% with the baseline
await expect(browser).toMatchFullPageSnapshot('fullPage', 5)
// Check a full page screenshot with options for `checkFullPageScreen` command
await expect(browser).toMatchFullPageSnapshot('fullPage', {
/* some options */
})

// Check a full page screenshot with all tab executions
await expect(browser).toMatchTabbablePageSnapshot('check-tabbable')
// Check a full page screenshot to have a mismatch percentage of 5% with the baseline
await expect(browser).toMatchTabbablePageSnapshot('check-tabbable', 5)
// Check a full page screenshot with options for `checkTabbablePage` command
await expect(browser).toMatchTabbablePageSnapshot('check-tabbable', {
/* some options */
})
})

it('should save some screenshots', async () => {
// Save a screen
await browser.saveScreen('examplePage', {
/* some options */
})

// Save an element
await browser.saveElement(
await $('#element-id'),
'firstButtonElement',
{
/* some options */
}
)

// Save a full page screenshot
await browser.saveFullPageScreen('fullPage', {
/* some options */
})

// Save a full page screenshot with all tab executions
await browser.saveTabbablePage('save-tabbable', {
/* some options, use the same options as for saveFullPageScreen */
})
})

it('should compare successful with a baseline', async () => {
// Check a screen
await expect(
await browser.checkScreen('examplePage', {
/* some options */
})
).toEqual(0)

// Check an element
await expect(
await browser.checkElement(
await $('#element-id'),
'firstButtonElement',
{
/* some options */
}
)
).toEqual(0)

// Check a full page screenshot
await expect(
await browser.checkFullPageScreen('fullPage', {
/* some options */
})
).toEqual(0)

// Check a full page screenshot with all tab executions
await expect(
await browser.checkTabbablePage('check-tabbable', {
/* some options, use the same options as for checkFullPageScreen */
})
).toEqual(0)
})
})
중요

이 서비스는 savecheck 메서드를 제공합니다. 처음으로 테스트를 실행할 때는 savecompare 메서드를 함께 사용하지 않아야 합니다. check 메서드는 자동으로 기준 이미지를 생성합니다.

#####################################################################################
INFO:
Autosaved the image to
/Users/wswebcreation/sample/baselineFolder/desktop_chrome/examplePage-chrome-latest-1366x768.png
#####################################################################################

기준 이미지 자동 저장을 비활성화했을 경우, Promise는 다음 경고와 함께 거부됩니다.

#####################################################################################
Baseline image not found, save the actual image manually to the baseline.
The image can be found here:
/Users/wswebcreation/sample/.tmp/actual/desktop_chrome/examplePage-chrome-latest-1366x768.png
#####################################################################################

이는 현재 스크린샷이 actual 폴더에 저장되었으며 직접 기준 폴더에 복사해야 함을 의미합니다. @wdio/visual-serviceautoSaveBaseline: true 옵션으로 초기화하면 이미지가 자동으로 기준 폴더에 저장됩니다.

Welcome! How can I help?

WebdriverIO AI Copilot