addCommand
ブラウザメソッドaddCommand
は、独自のコマンドセットを作成するのに役立ちます。
情報
カスタムコマンドの追加に関する詳細は、カスタムコマンドガイドで確認できます。
使用方法
browser.addCommand(name, callback, elementScope)
パラメーター
名前 | タイプ | 詳細 |
---|---|---|
name | string | カスタムコマンドの名前 |
callback | Function | 呼び出される関数 |
elementScope オプション | Boolean | Browserオブジェクトではなく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')
})