मुख्य सामग्री पर जाएं

परीक्षण लिखना

टेस्टरनर फ्रेमवर्क समर्थन

@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)
})
})
महत्वपूर्ण

यह सेवा save और check मेथड्स प्रदान करती है। अगर आप अपने टेस्ट पहली बार चलाते हैं तो आपको save और compare मेथड्स को एक साथ नहीं मिलाना चाहिए, check-मेथड्स स्वचालित रूप से आपके लिए बेसलाइन इमेज बना देंगे

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

जब आप बेसलाइन इमेज को स्वचालित रूप से सेव करना अक्षम कर देते हैं, तो प्रॉमिस निम्न चेतावनी के साथ अस्वीकृत हो जाएगी।

#####################################################################################
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-service को autoSaveBaseline: true के साथ इंस्टेंशिएट करते हैं तो इमेज स्वचालित रूप से बेसलाइन फोल्डर में सेव हो जाएगी।

Welcome! How can I help?

WebdriverIO AI Copilot