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

ब्राउज़र लॉग

परीक्षण चलाते समय ब्राउज़र महत्वपूर्ण जानकारी लॉग कर सकता है जिसमें आप रुचि रखते हैं या जिसके खिलाफ आप जांच करना चाहते हैं।

WebDriver Bidi का उपयोग करते समय, जो WebdriverIO द्वारा ब्राउज़र को स्वचालित करने का डिफ़ॉल्ट तरीका है, आप ब्राउज़र से आने वाली घटनाओं को सब्सक्राइब कर सकते हैं। लॉग इवेंट्स के लिए आप log.entryAdded' पर सुनना चाहेंगे, उदाहरण के लिए:

await browser.sessionSubscribe({ events: ['log.entryAdded'] })

/**
* returns: {"type":"console","method":"log","realm":null,"args":[{"type":"string","value":"Hello Bidi"}],"level":"info","text":"Hello Bidi","timestamp":1657282076037}
*/
browser.on('log.entryAdded', (entryAdded) => console.log('received %s', entryAdded))

एक परीक्षण में आप बस लॉग इवेंट्स को एक एरे में पुश कर सकते हैं और जब आपका कार्य पूरा हो जाए तो उस एरे की जांच कर सकते हैं, उदाहरण के लिए:

import type { local } from 'webdriver'

describe('should log when doing a certain action', () => {
const logs: string[] = []

function logEvents (event: local.LogEntry) {
logs.push(event.text) // add log message to the array
}

before(async () => {
await browser.sessionSubscribe({ events: ['log.entryAdded'] })
browser.on('log.entryAdded', logEvents)
})

it('should trigger the console event', () => {
// trigger the browser send a message to the console
...

// assert if log was captured
expect(logs).toContain('Hello Bidi')
})

// clean up listener afterwards
after(() => {
browser.off('log.entryAdded', logEvents)
})
})

कृपया ध्यान दें कि आप इस विधि का उपयोग त्रुटि संदेशों को प्राप्त करने और यह सत्यापित करने के लिए कर सकते हैं कि क्या आपके एप्लिकेशन में कोई त्रुटियां आई हैं।

Welcome! How can I help?

WebdriverIO AI Copilot