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

addCommand

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

情報

カスタムコマンドの追加に関する詳細は、カスタムコマンドガイドで確認できます。

使用方法
browser.addCommand(name, callback, elementScope)
パラメーター
名前タイプ詳細
namestringカスタムコマンドの名前
callbackFunction呼び出される関数
elementScope
オプション
BooleanBrowserオブジェクトではなくElementオブジェクトを拡張する
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://webdriverio.dokyumento.jp')
const result = await browser.getUrlAndTitle('foobar')

assert.strictEqual(result.url, 'https://webdriverio.dokyumento.jp')
assert.strictEqual(result.title, 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')
assert.strictEqual(result.customParam, 'foobar')
})

ようこそ!どのようなご用件ですか?

WebdriverIO AI Copilot