0
我在我的自定义函数文件中使用Selenium IDE调用jQuery库(Selenium使用我相信的原型),之前没有问题,但最近更新firefox似乎导致了问题。我发现这个问题,当我想用jQuerys在下面的函数修剪方法它的茎此功能jQuery没有与原型Selenium冲突
/* allow use of jQuerys global variable $ */
function _getGlobalVar(varName) {
var win = selenium.browserbot.getUserWindow();
if (win[varName]) {
return win[varName];
} else {
throw undefined;
}
}
/* allows use of Jquery selectors in pages where jQuery is loaded*/
function jQuery(selector) {
var jq = _getGlobalVar('jQuery');
if (typeof jq != 'undefined') {
return jq(selector);
} else {
throw new SeleniumError('jQuery is not defined in the current window');
}
}
。我已阅读的文档,我知道我可以使用jQuery.noConflict();
,但UT不似乎是帮助
Selenium.prototype.doClickSearchTemplate = function (locator, action) {
$ = _getGlobalVar('jQuery');
profileToggleButton = null;
profileName = '';
var locator = locator || 'id=content';
var reportBlockContainer = this.page().findElement(locator);
jQuery(reportBlockContainer).find('.reportBlockHeader h2 strong').each(function(index, elem) {
profileName = $.trim(jQuery(elem).text());
if (profileName == action)
profileToggleButton = elem.parentNode.previousElementSibling; // previousSibling = jQuery(elem).parent().prev().get(0);
});
if (profileToggleButton === null)
throw new SeleniumError("Invalid Search Template Name: " +action);
this.browserbot.clickElement(profileToggleButton);
};
,这导致的是,当我点击“玩现在的考验”,它会运行正常第一次问题,调用此函数,执行该功能,我的测试会通过,但是当我尝试再次按'播放当前测试用例'时,它就像按钮被禁用,它不会触发。
如果我不调用这个函数,那么一切正常,我不知道它是否与$
变量的赋值有关。
https://github.com/Nthalk/SeleniumJQuery解决了这个 – epascarello