繁体   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