支持格式化程序中的自定义Selenium IDE命令

时间:2014-07-30 12:28:29

标签: javascript python selenium selenium-ide

我已经设法将自定义命令添加到Selenium IDE,但是在格式上支持这些命令时遇到了困难,即Python WebDriver格式的扩展版本。在导出到我的自定义格式时生成的脚本中,对于我添加的命令,我得到以下内容:

# ERROR: Caught exception [unknown command [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 :(得分:0)

您应该能够使用user-extensions.js并行开发javascript函数。这样命令就会在webdriver和selenium-ide中同时存在。最干净的方法是在user-extensions.js中创建一次,然后在webdriver中引用它们。

请查看https://groups.google.com/d/msg/selenium-users/6Sfa1-bLKUQ/1fnoL4ZW3WoJhttps://bernardlago.wordpress.com/2011/03/02/user-extensions-with-selenium-rc-using-ruby-client-driver-selenium-client/,了解如何在用户扩展程序中弥补与自定义JavaScript的差距。

  

什么是用户扩展?这些是JavaScript函数/库   用户可以创建和使用以扩展Selenium。

     

为什么我们必须使用用户扩展?简单。如果你想添加你的   自己的行为,断言和定位策略。这意味着那里   目前没有可用于您的测试类型的命令   我想完成。这也意味着没有方法   但在Selenium API中将会这样做   您想要添加的action / assertion / locator-strategy。