在格式化程序中支持自定义Selenium IDE命令
我已经成功地在Selenium IDE中添加了自定义命令,但在支持这些命令的格式上遇到了困难,具体来说,是一种扩展版的Python WebDriver格式。当我导出到我的自定义格式时,生成的脚本中对于我添加的命令显示如下:
# 错误:捕获到异常 [未知命令 [finalPrice]]
我已经在 user-extensions.js
中添加了这个命令,具体如下:
Selenium.prototype.doFinalPrice = function (locator) { return ''; }
CommandBuilders.add('action', function (window) {
var result = {
command: 'finalPrice',
target: this.getRecorder(window).clickedElementLocators,
execute: function () { return; },
getDefinition: function () { return true; }
};
return result;
})
并且用以下内容扩展了标准的Python WebDriver format.js
:
WDAPI.Driver.prototype.finalPrice = function (locatorType, locator) {
return ["#PRICE", locatorType, locator].join('|');
};
SeleniumWebDriverAdaptor.prototype.finalPrice = function () {
var locator = this._elementLocator(this.rawArgs[0]);
var driver = new WDAPI.Driver();
return driver.finalPrice(locator.type, locator.string);
}
有没有人成功做到这一点?如果有的话,能告诉我哪里出错了吗?正如我所说,在Selenium IDE中这个命令本身运行得很好,只有导出到我的自定义格式时出现问题。任何帮助都将非常感谢。
1 个回答
0
你可以使用 user-extensions.js 来同时开发 JavaScript 函数。这样一来,你在 webdriver 和 selenium-ide 中都能使用这些命令。最简单的方法是先在 user-extensions.js 中创建这些函数,然后在 webdriver 中引用它们。
你可以看看 这个链接 和 这个链接,了解如何将你的自定义 JavaScript 与 user-extensions 连接起来。
什么是 user-extensions?它们是用户可以创建和使用的 JavaScript 函数或库,用来扩展 Selenium 的功能。
为什么我们需要使用 user-extensions?很简单。如果你想添加自己的操作、断言和定位策略,这就需要用到它们。这意味着目前没有现成的命令可以满足你想要进行的测试类型。这也意味着在 Selenium 的 API 中还没有可以执行你想添加的操作、断言或定位策略的方法。