メインコンテンツにスキップ

addCommand

ブラウザメソッド addCommand は、独自のコマンドセットを作成するのに役立ちます。

情報

カスタムコマンドの追加についての詳細情報は、カスタムコマンドガイドで見つけることができます。

使用法
browser.addCommand(name, callback, elementScope)
パラメータ
名前詳細
namestringカスタムコマンドの名前
callbackFunction呼び出される関数
elementScope
オプション
BooleanBrowserオブジェクトではなくElementオブジェクトを拡張する
execute.js
await browser.addCommand('getUrlAndTitle', async function (customParam) {
// `this` は `browser` スコープを参照します
return {
url: await this.getUrl(),
title: await this.getTitle(),
customParam: customParam
}
})
//使用例
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')
})

Welcome! How can I help?

WebdriverIO AI Copilot