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

newWindow

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

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

使い方
browser.newWindow(url, { type, windowName, windowFeatures })
パラメータ
名前詳細
urlstring開くウェブサイトのURL
options
optional
NewWindowOptionsnewWindowコマンドのオプション
options.type
optional
string新しいウィンドウのタイプ: 'tab' または 'window'
options.windowName
optional
String新しいウィンドウの名前
options.windowFeatures
optional
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://webdriverio.dokyumento.jp', {
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://webdriverio.dokyumento.jp', {
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"
});
スロー
  • スロー: url が無効な場合、コマンドがモバイルで使用された場合、または type が 'tab' または 'window' でない場合。

ようこそ!何かお手伝いできることはありますか?

WebdriverIO AI Copilot