簡體   English   中英

使用Selenium Tool時ExtJ的動態ID生成

[英]ExtJs dynamic Id generation when using Selenium Tool

我正在嘗試測試使用EXTJS開發的UI的Web應用程序。 我面臨的問題是,當我嘗試記錄宏並使測試自動化時,我遇到了一個主要問題。

  1. ExtJs ID是動態的(假設我第一次錄制宏時ID是extj-343,下次嘗試播放錄制的宏時ID不會保持不變)

  2. 因此,我遇到了運行時異常,並且宏無法完成執行。

解決方案嘗試:

我嘗試使用iMacro作為Selenium的替代測試工具,但遇到了同樣的問題。

據我所知,應該有某種方法可以使此Ids保持靜態,以便可以解決問題或可以解決一些問題。

我們對Ext(2.2.1版)使用以下替代,以獲取我們指定的ID,而不是Ext生成的ID。 不確定我們在哪里找到它,可能是Ext論壇。

Ext.override(Ext.Button, {
initButtonEl : function(btn, btnEl){
    this.el = btn;
    btn.addClass("x-btn");

    if(this.id){
        //this.el.dom.id = this.el.id = this.id;
        // override
        btnEl.dom.id = btnEl.id = this.id;
        // end override
    }
    if(this.icon){
        btnEl.setStyle('background-image', 'url(' +this.icon +')');
    }
    if(this.iconCls){
        btnEl.addClass(this.iconCls);
        if(!this.cls){
            btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
        }
    }
    if(this.tabIndex !== undefined){
        btnEl.dom.tabIndex = this.tabIndex;
    }
    if(this.tooltip){
        if(typeof this.tooltip == 'object'){
            Ext.QuickTips.register(Ext.apply({
        target: btnEl.id
    }, this.tooltip));
    } else {
    btnEl.dom[this.tooltipType] = this.tooltip;
    }
    }

    if(this.pressed){
    this.el.addClass("x-btn-pressed");
    }

    if(this.handleMouseEvents){
    btn.on("mouseover", this.onMouseOver, this);
    // new functionality for monitoring on the document level
    //btn.on("mouseout", this.onMouseOut, this);
    btn.on("mousedown", this.onMouseDown, this);
    }

    if(this.menu){
    this.menu.on("show", this.onMenuShow, this);
    this.menu.on("hide", this.onMenuHide, this);
    }

    if(this.repeat){
    var repeater = new Ext.util.ClickRepeater(btn,
    typeof this.repeat == "object" ? this.repeat : {}
    );
    repeater.on("click", this.onClick,  this);
    }

    btn.on(this.clickEvent, this.onClick, this);
}
});
Ext.override(Ext.menu.Item, {
onRender : function(container, position){
    var el = document.createElement("a");
    el.hideFocus = true;
    el.unselectable = "on";
    el.href = this.href || "#";
    if(this.hrefTarget){
        el.target = this.hrefTarget;
    }
    el.className = this.itemCls + (this.menu ?  " x-menu-item-arrow" : "") + (this.cls ?  " " + this.cls : "");
    // override
    if (this.id){
        el.id = this.id;
    }
    // end override
    el.innerHTML = String.format(
            '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
            this.icon || Ext.BLANK_IMAGE_URL, this.itemText||this.text, this.iconCls || '');
    this.el = el;
    Ext.menu.Item.superclass.onRender.call(this, container, position);
}    
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM