开始使用插件
插件可以通过添加其他命令和定位器、在测试运行前后引导设置以及影响记录过程来扩展 Selenium IDE 的默认行为。
Selenium IDE 使用 WebExtension 标准在现代浏览器中工作(要了解更多信息,可以查看 Mozilla 的 第一个扩展 文章)。扩展之间的通信通过 外部消息传递协议 处理,你可以 在此处 查看示例。
本文假设你了解 WebExtension 开发,并且只会讨论 Selenium IDE 特定的功能。
调用 API
可以使用 browser.runtime.sendMessage 调用 Selenium IDE API。
示例签名为 browser.runtime.sendMessage(SIDE_ID, request),其中 SIDE_ID 指的是 IDE 的官方扩展 ID,可以 在此处 查看。
请求
请求是 browser.runtime.sendMessage 的第二个参数,并且在理念上类似于 HTTP。
{
uri: "/register",
verb: "post",
payload: {
name: "Selenium IDE plugin",
version: "1.0.0"
}
}
uri- IDE 功能的资源定位器(例如,记录命令、解析定位器)verb- 一个修饰函数(例如,get获取内容,post添加新内容,就像在 http 中一样)
IDE 将回复一个有效响应,或者在发生错误的情况下,可以通过打开 IDE 窗口的 DevTools 查看此响应。
browser.runtime.sendMessage(SIDE_ID, request).then(response => {
console.log("it worked!");
});
清单
插件为 IDE 提供清单,声明其对 IDE 功能的更改和添加。
{
name: "New Plugin",
version: "1.0.0",
commands: [
{
id: "newCommand",
name: "new command",
type: "locator",
docs: {
description: "command description",
target: { name: "command target", value: "command target description" },
value: { name: "command value", value: "command value description" }
}
},
{
id: "anotherCommand",
name: "another command",
type: "locator",
docs: {
description: "another command description",
target: "locator",
value: "pattern"
}
}
],
locators: [
{
id: "locator"
}
],
dependencies: {
"selenium-webdriver": "3.6.0"
}
}
常规信息
name- 必填,插件名称。version- 必填,插件版本。
命令
要添加到 IDE 中的新命令列表,每个命令都采用几个参数
id- 必填,命令的 camelCase 唯一标识符。name- 必填,命令的自然语言名称,用户将看到此名称。type- 可选,可以是locator或region,用于启用find和select按钮。(注意:type仍处于测试阶段,将来可能会更改)。docs- 可选,命令描述、目标和值的元数据集合。或者,你可以通过指定其名称(而不是子集合)作为字符串来使用现有的命令目标或值(又名 ArgTypes)。有关完整列表,请参阅ArgTypes.js中的ArgTypes。
定位器
注意:定位器仍处于开发中,并将很快添加
要添加到 IDE 中的新定位器列表,每个定位器只需使用 id。
id- 必需,定位器的唯一标识符,将显示给用户(例如name、css)。
依赖项
使用 命令行运行器 运行时要下载和使用的其他 Node.js 依赖项。
依赖项是 key:value 形式的字典,例如 name:version,其中 name 是 npm 上发布的名称,version 是发布到 npm 的有效的 semver。
注册插件
要使用 Selenium IDE 注册插件,请确保 IDE 窗口已打开,并且您使用的是正确的 Selenium IDE 扩展 ID。
发送以下消息
browser.runtime.sendMessage(process.env.SIDE_ID, {
uri: "/register",
verb: "post",
payload: {
name: "Selenium IDE plugin",
version: "1.0.0",
commands: [
{
id: "successfulCommand",
name: "successful command"
},
{
id: "failCommand",
name: "failed command"
}
]
}
}).catch(console.error);
其中 payload 是清单。
