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

newWindow

ブラウザで新しいウィンドウまたはタブを開きます(指定がない場合はデフォルトで新しいウィンドウになります)。 このコマンドはwindow.open()関数と同等です。このコマンドはモバイル環境では動作しません。

注意: このコマンドを呼び出すと、自動的に新しいウィンドウまたはタブに切り替わります。

使用法
browser.newWindow(url, { type, windowName, windowFeatures })
パラメータ
名前詳細
urlstring開くウェブサイトのURL
options
オプション
NewWindowOptionsnewWindowコマンドのオプション
options.type
オプション
string新しいウィンドウのタイプ: 'tab'または'window'
options.windowName
オプション
String新しいウィンドウの名前
options.windowFeatures
オプション
String開いたウィンドウの機能(サイズ、位置、スクロールバーなど)
newWindowSync.js
it('should open a new window', async () => {
await browser.url('https://google.com')
console.log(await browser.getTitle()) // outputs: "Google"

const result = await browser.newWindow('https://webdriver.io', {
windowName: 'WebdriverIO window',
windowFeature: 'width=420,height=230,resizable,scrollbars=yes,status=1',
})
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
console.log(result.type) // outputs: "window"
const handles = await browser.getWindowHandles()
await browser.switchToWindow(handles[1])
await browser.closeWindow()
await browser.switchToWindow(handles[0])
console.log(await browser.getTitle()) // outputs: "Google"
});

newTabSync.js
  it('should open a new tab', async () => {
await browser.url('https://google.com')
console.log(await browser.getTitle()) // outputs: "Google"

await browser.newWindow('https://webdriver.io', {
type:'tab',
windowName: 'WebdriverIO window',
windowFeature: 'width=420,height=230,resizable,scrollbars=yes,status=1',
})
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
console.log(result.type) // outputs: "tab"
const handles = await browser.getWindowHandles()
await browser.switchToWindow(handles[1])
await browser.closeWindow()
await browser.switchToWindow(handles[0])
console.log(await browser.getTitle()) // outputs: "Google"
});
戻り値
  • <Object> return: ウィンドウハンドルと新しいウィンドウのタイプを含むオブジェクト {handle: string, type: string} handle - 新しいタブまたはウィンドウのウィンドウハンドルのID、type - 新しいウィンドウのタイプ、'tab'または'window'
例外
  • Error: urlが無効な場合、コマンドがモバイルで使用された場合、またはtypeが'tab'または'window'でない場合。

Welcome! How can I help?

WebdriverIO AI Copilot