newWindow
ブラウザで新しいウィンドウまたはタブを開きます(指定がない場合は新しいウィンドウがデフォルト)。このコマンドは window.open() と同等の関数です。このコマンドはモバイル環境では動作しません。
注意: このコマンドを呼び出すと、自動的に新しいウィンドウまたはタブに切り替わります。
使い方
browser.newWindow(url, { type, windowName, windowFeatures })
パラメータ
| 名前 | 型 | 詳細 | 
|---|---|---|
| url | string | 開くウェブサイトのURL | 
| optionsoptional | NewWindowOptions | newWindowコマンドのオプション | 
| options.typeoptional | string | 新しいウィンドウのタイプ: 'tab' または 'window' | 
| options.windowNameoptional | String | 新しいウィンドウの名前 | 
| options.windowFeaturesoptional | 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' でない場合。