模块
WebdriverIO 在 NPM 和其他注册表上发布了各种模块,您可以使用这些模块构建自己的自动化框架。在这里查看有关 WebdriverIO 设置类型的更多文档。
webdriver 和 devtools
协议包(webdriver 和 devtools)暴露了一个类,并附加了以下静态函数,允许您启动会话:
newSession(options, modifier, userPrototype, customCommandWrapper)
使用特定功能启动新会话。基于会话响应,将提供来自不同协议的命令。
参数
- options: WebDriver 选项
- modifier: 允许在返回客户端实例之前修改它的函数
- userPrototype: 允许扩展实例原型的属性对象
- customCommandWrapper: 允许在函数调用周围包装功能的函数
返回
- Browser 对象
示例
const client = await WebDriver.newSession({
    capabilities: { browserName: 'chrome' }
})
attachToSession(attachInstance, modifier, userPrototype, customCommandWrapper)
连接到正在运行的 WebDriver 或 DevTools 会话。
参数
- attachInstance: 要连接会话的实例,或至少是具有- sessionId属性的对象(例如- { sessionId: 'xxx' })
- modifier: 允许在返回客户端实例之前修改它的函数
- userPrototype: 允许扩展实例原型的属性对象
- customCommandWrapper: 允许在函数调用周围包装功能的函数
返回
- Browser 对象
示例
const client = await WebDriver.newSession({...})
const clonedClient = await WebDriver.attachToSession(client)
reloadSession(instance)
重新加载给定实例的会话。
参数
- instance: 要重新加载的包实例
示例
const client = await WebDriver.newSession({...})
await WebDriver.reloadSession(client)
webdriverio
与协议包(webdriver 和 devtools)类似,您也可以使用 WebdriverIO 包 API 来管理会话。这些 API 可以通过 import { remote, attach, multiremote } from 'webdriverio' 导入,并包含以下功能: