addCommand
ब्राउज़र मेथड addCommand
आपको अपने खुद के कमांड्स लिखने में मदद करता है।
जानकारी
कस्टम कमांड्स जोड़ने के बारे में अधिक जानकारी आप कस्टम कमांड गाइड में पा सकते हैं।
उपयोग
browser.addCommand(name, callback, elementScope)
पैरामीटर्स
नाम | प्रकार | विवरण |
---|---|---|
name | string | कस्टम कमांड का नाम |
callback | Function | कॉल की जाने वाली फंक्शन |
elementScope वैकल्पिक | Boolean | ब्राउज़र ऑब्जेक्ट के बजाय एलिमेंट ऑब्जेक्ट का विस्तार करें |
उदाहरण
execute.js
await browser.addCommand('getUrlAndTitle', async function (customParam) {
// `this` refers to the `browser` scope
return {
url: await this.getUrl(),
title: await this.getTitle(),
customParam: customParam
}
})
//usage
it('should use my add command', async () => {
await browser.url('https://webdriver.io')
const result = await browser.getUrlAndTitle('foobar')
assert.strictEqual(result.url, 'https://webdriver.io')
assert.strictEqual(result.title, 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')
assert.strictEqual(result.customParam, 'foobar')
})