2015-01-12 56 views
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); 
}; 

,這導致的是,當我點擊「玩現在的考驗」,它會運行正常第一次問題,調用此函數,執行該功能,我的測試會通過,但是當我嘗試再次按'播放當前測試用例'時,它就像按鈕被禁用,它不會觸發。

如果我不調用這個函數,那麼一切正常,我不知道它是否與$變量的賦值有關。

+0

https://github.com/Nthalk/SeleniumJQuery解決了這個 – epascarello

回答

0

僅通過訴諸回的JavaScript

profileName = jQuery(elem).text(); 
profileName = profileName.trim(); 

一切都很好,現在