51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2581|回复: 7
打印 上一主题 下一主题

使用selenium回放时报错,请各位大神帮忙看看

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2014-2-20 11:58:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

如图,执行        selenium.click("id=ext-gen49");后就报错了(点击添加按钮),报错后手动点击“确定”或“取消”代码都无法继续执行下去。我已经试过不用selenium回放,直接用IE打开,页面是正常的。
这个问题困扰了我很久了,麻烦大家帮帮忙,以下是页面代码:
var dbsx_grid = new Ext.grid.GridPanel({
                store : dbsx_gridstore,
                autoHeight : true,
                stripeRows : true,
                autoExpandColumn : 'DBSX_ID',
                id:'dbsxgrid',
                columnLines : true,
                enableHdMenu  : false ,
                viewConfig : {
                        forceFit : true
                },
                loadMask : {
                        msg : prompts.load
                },
                cls : 'grid',
                columns : [new Ext.ux.RowNumberer(), {
                                        header : "标题",
                                        dataIndex : 'TSBT',renderer:renderToolTip,width:150
                                },{
                                        header : "发布人",
                                        dataIndex : 'DJRMC'
                                },{
                                        header : "接收单位",
                                        dataIndex : 'FKRMC',width:150,renderer:renderToolTip
                                },{
                                        header : "签收人",
                                        dataIndex : 'QSR'
                                },{
                                        header : "发布时间",
                                        dataIndex : 'TSSJ',
                                        renderer:renderRQ
                                }, {
                                        header : "签收状态",
                                        dataIndex : 'FKZTMC'
                                },{
                                        header : "签收状态dm",
                                        dataIndex : 'FKZT',
                                        hidden:true
                                },{
                                        header:'主键',
                                        dataIndex:'DBSX_ID',
                                        hidden:true,
                                        id:'DBSX_ID'
                                },{
                                        header:'主键2',
                                        dataIndex:'SYDBSX_ID',
                                        hidden:true,
                                        id:'SYDBSX_ID'
                                }],
                tbar : [{
                                        text : '添加',
                                        cls : 'btn',
                                        id:'dbsxadd',
                                        iconCls : 'icon-add',
                                        handler : function() {
                                        /*
                                                flag='add';
                                                var date =  GetCurrentTime();
                                                Ext.getCmp('starttssj').setValue(date);
                                                add_form_title = '工作提示发布';
                                                if(zw=='03'){
                                                compleTree1.root.id = '32'
                                                }else{
                                                compleTree1.root.id = dwdm;
                                                }
                                    compleTree1.getLoader().load(compleTree1.root,function(){
                                        compleTree1.getRootNode().expand(false,true);
                                },this);
                                showWindowDbsx(this);
                                */
                                if(Ext.isIE6){
                                        window.showModalDialog("addDbsx.jsp","newWin","dialogWidth:897px;dialogHeight:330px;minimize:yes;maximize:yes;");
                                }else if (Ext.isIE8){
                                        window.showModalDialog("addDbsx.jsp","newWin","dialogWidth:890px;dialogHeight:285px;minimize:yes;maximize:yes;");
                                }else{
                                        window.showModalDialog("addDbsx.jsp","newWin","dialogWidth:890px;dialogHeight:285px;minimize:yes;maximize:yes;");
                                }
                               
                                                ViewDbsxDWR.getTotal(dbsx_entity, function(para) {
                                                        dbsx_pageToolbar.setTotal(para);
                                                });
                                               
                                        }
                                },{
                                        text : '删除',
                                        cls : 'btn',
                                        id:'dbsxdelete',
                                        iconCls : 'icon-delete',
                                        handler : function(){
                                                if (dbsx_grid.getSelectionModel().getSelected()) {
                                                        Ext.Msg.confirm('删除确认提示','是否删除该项记录,删除后不可恢复!',function(btn,text){
                                                                if(btn == 'yes'){
                                                                del_entity = {
                                                                        DBSX_ID : dbsx_grid.getSelectionModel().getSelected().data.DBSX_ID
                                                                };
                                                                        DbsxDWR.deleteDbsx(del_entity,function(para){
                                                                                if(para.state==1){
                                                                                        ViewDbsxDWR.getTotal(dbsx_entity, function(para) {
                                                                                                dbsx_pageToolbar.setTotal(para);
                                                                                        });
                                                              Ext.exception.msg(para.message, true ,0,1,20,10);
                                                        }else if(para.state==0){
                                                                  Ext.exception.msg(para.message, para.exceptionMsg,2,10,20,10);                                                       
                                                        }
                                                                        });               
                                                                        del_entity.DBSX_ID = dbsx_grid.getSelectionModel().getSelected().data.SYDBSX_ID;
                                                                        ShouyDbsxDWR.deleteShouyDbsx(del_entity,function(para){});
                                                                }else{
                                                                }
                                                        });
                                                } else {
                                                        Ext.Msg.alert('提示', '请选择要删除的信息');
                                                }
                                }
                },{
                                        text : '详情',
                                        cls : 'btn',
                                        id:'xiangq',
                                        iconCls : 'icon-view',
                                        handler : function(){
                                                if (dbsx_grid.getSelectionModel().getSelected()) {
                                                        /*
                                                        showWindowDbsxDetail(this);
                                                sp_entity = {
                                                        DBSX_ID : dbsx_grid.getSelectionModel().getSelected().data.SYDBSX_ID
                                                };
                                                sp_entity = {
                                                        DBSX_ID : dbsx_grid.getSelectionModel().getSelected().data.DBSX_ID
                                                };
                                                        ViewDbsxDWR.selectViewDbsx(sp_entity, function(para) {
                                                                for (var k in para) {
                                                                        if (k == "99") {
                                                                                Ext.exception.msg("查询信息时发生异常", para[k], 2,10,20,10);
                                                                        }
                                                                }
                                                                dbsxdetail_form.getForm().setValues(para);
                                                        });
                                                        */
                                                        var dbsxid=dbsx_grid.getSelectionModel().getSelected().data.DBSX_ID;
                                                        window.showModalDialog("DetailDbsx.jsp?DBSX_ID="+dbsxid+"&fkzt=1&title=工作提示发布详情","newWin","dialogWidth:800px;dialogHeight:300px;minimize:yes;maximize:yes;");
                                                } else {
                                                        Ext.Msg.alert('提示', '请选择要查看的信息');
                                                }
                                         }
                                }],
                bbar : dbsx_pageToolbar,               
                listeners : {
                'rowdblclick' :function(btn, e) {
                                                if (dbsx_grid.getSelectionModel().getSelected()) {
                                                /*
                                                        showWindowDbsxDetail(this);
                                                sp_entity = {
                                                        DBSX_ID : dbsx_grid.getSelectionModel().getSelected().data.SYDBSX_ID
                                                };
                                                sp_entity = {
                                                        DBSX_ID : dbsx_grid.getSelectionModel().getSelected().data.DBSX_ID
                                                };
                                                        ViewDbsxDWR.selectViewDbsx(sp_entity, function(para) {
                                                                for (var k in para) {
                                                                        if (k == "99") {
                                                                                Ext.exception.msg("查询信息时发生异常", para[k], 2,10,20,10);
                                                                        }
                                                                }
                                                                dbsxdetail_form.getForm().setValues(para);
                                                        });
                                                        */
                                                        var dbsxid=dbsx_grid.getSelectionModel().getSelected().data.DBSX_ID;
                                                        window.showModalDialog("DetailDbsx.jsp?DBSX_ID="+dbsxid+"&fkzt=1&title=工作提示发布详情","newWin","dialogWidth:800px;dialogHeight:300px;minimize:yes;maximize:yes;");
                                                } else {
                                                        Ext.Msg.alert('提示', '请选择要查看的信息');
                                                }
                                         },
                'click' : function(btn,e){
                        if (dbsx_grid.getSelectionModel().getSelected()) {
                            if(zhangh!=dbsx_grid.getSelectionModel().getSelected().data.DJR){
                                    Ext.getCmp('dbsxdelete').setDisabled(true);
                            }else{
                                    Ext.getCmp('dbsxdelete').setDisabled(false);
                            }
                        }
                }
        }
        });

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    无聊
    2020-12-8 11:20
  • 签到天数: 605 天

    连续签到: 1 天

    [LV.9]测试副司令

    2#
    发表于 2014-2-20 17:39:21 | 只看该作者
    敢问IE 版本如何?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
     楼主| 发表于 2014-2-21 09:29:31 | 只看该作者
    由于还需要做兼容性测试,所以IE6和IE8都使用过,一样的表现形式,单独打开IE操作正常,使用selenium回放时报错
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
    发表于 2014-2-21 13:27:56 | 只看该作者
    本帖最后由 gaha 于 2014-2-21 13:29 编辑

    看代码,应该是用了EXT库了,用selenium回放的时候,会出现权限错误,需要在IDE录制的时候导入两个js库。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
     楼主| 发表于 2014-2-24 09:37:55 | 只看该作者
    回复 4# gaha


       在IDE录制导入两个JS库是什么意思?麻烦大神详细告知,小弟跪谢
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    6#
     楼主| 发表于 2014-2-24 09:50:10 | 只看该作者
    @gaha 麻烦大神告诉一下在IDE录制时导入两个JS库是什么意思。。。我的测试代码都是直接在eclipse手写的
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7#
    发表于 2014-2-25 14:17:55 | 只看该作者
    http://blog.sina.com.cn/s/blog_58e0371601012zl7.html
    在seleium-IDE上,打开options,其中core 和IDE两个文本框中,分别导入两个js文件,重启remote后台即可。

    简单说就是在录制时不会再出现EXT的随机码,就能回放成功了。

    第一个文件:user-extensions.js


    Selenium.prototype.assertExtEqual = function(expression, text) { var result = this.exteval_r(expression) if (result != text) { Assert.fail("the value of [" + result + "] " + expression + " is not equal with " + text); } }; Selenium.prototype.assertExtGreaterThan = function(expression, text) { var result = this.exteval_r(expression) if (result <= text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater than " + text); } } Selenium.prototype.assertExtGreaterEqualThan = function(expression, text) { var result = this.exteval_r(expression) if (result < text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater equal than " + text); } } Selenium.prototype.assertExtLessThan = function(expression, text) { var result = this.exteval_r(expression) if (result >= text) { Assert.fail("the value of [" + result + "] " + expression + " is not less than " + text); } } Selenium.prototype.assertExtLessEqualThan = function(expression, text) { var result = this.exteval_r(expression) if (result > text) { Assert.fail("the value of [" + result + "] " + expression + " is not less equal than " + text); } } Selenium.prototype.doExecuteExtFunction = function(expression, text) { if (expression.lastIndexOf(")") == expression.length - 1) { this.exteval_r(expression); } else { var scopeObj = this.exteval_r(expression.substring(0, expression .lastIndexOf("."))); var func = this.exteval_r(expression); if (typeof(func) != "function") { Assert.fail("the value of [" + func + "] " + expression + " is not a function"); } var params = []; if (text) { params = text.split(","); } try { func.apply(scopeObj, params); } catch (e) { Assert.fail("error execute function [" + func + "] " + expression); } } } Selenium.prototype.assertExtTrue = function(expression) { var result = this.exteval_r(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not true"); } } Selenium.prototype.assertExtFalse = function(expression) { var result = this.exteval_r(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not false"); } } Selenium.prototype.assertExtNull = function(expression, text) { var result = this.exteval_r(expression); if (result !== null) { Assert.fail("the value of [" + result + "] " + expression + " is not null"); } } Selenium.prototype.assertExtNotNull = function(expression, text) { var result = this.exteval_r(expression); if (result === null) { Assert.fail("the value of [" + result + "] " + expression + " is null"); } } Selenium.prototype.assertExtUndefined = function(expression, text) { var result = this.exteval_r(expression); if (result !== undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not undefined"); } } Selenium.prototype.assertExtNotUndefined = function(expression, text) { var result = this.exteval_r(expression); if (result === undefined) { Assert.fail("the value of [" + result + "] " + expression + " is undefined"); } } Selenium.prototype.assertExtPresent = function(expression, text) { var result = this.exteval_r(expression); if (result == null || result == undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not present"); } } Selenium.prototype.assertExtNotPresent = function(expression, text) { var result = this.exteval_r(expression); if (result != null || result != undefined) { Assert.fail("the value of [" + result + "] " + expression + " is present"); } } Selenium.prototype.assertExtMatches = function(expression, text) { var result = this.exteval_r(expression); var reg = new RegExp(text); if (!reg.test(result)) { Assert.fail("the value of [" + result + "] " + expression + " is not match " + text); } } Selenium.prototype.assertExtContains = function(expression, text) { var result = this.exteval_r(expression); if (typeof(result) == "undefined" || result == null) { Assert.fail("the value of " + expression + " dos not contains " + text); } else if (result.indexOf) { if (result.indexOf(text) < 0) { Assert.fail("the value of [" + result + "] " + expression + " dos not contains " + text); } } else { Assert.fail("the value of [" + result + "] " + expression + " is not a String or Array"); } } Selenium.prototype.assertExtTypeof = function(expression, text) { var type = typeof(this.exteval_r(expression)); if (type != text) { Assert.fail("the type of [" + type + "] " + expression + " is not " + text); } } PageBot.prototype.getWrappedWindow = function(extpath) { var win = this.getCurrentWindow() || {}; return win.wrappedJSObject; } Selenium.prototype.getWrappedWindow = function(extpath) { return this.browserbot.getWrappedWindow(); } Selenium.prototype.extEval = function(expression) { var script = expression; if (expression) { var expArr = expression.split("."); expArr[0] = "(window.Ext.getCmp('" + expArr[0] + "')||window.Ext.get('" + expArr[0] + "')||window.Ext.StoreMgr.lookup('" + expArr[0] + "'))"; expression = expArr.join("."); } try { return this.doeval_r(expression); } catch (e) { throw new SeleniumError("the expression " + script + " is not a Ext expression !"); } }; // I have to rewrite the eval function to get the context of window Selenium.prototype.doEval = function(expression) { try { var win = this.getWrappedWindow(); var result = eval_r(expression, win); return result; } catch (e) { throw new SeleniumError("the expression " + expression + " is not a Ext expression !"); } }

    第二个文件:extension-ide.js

    var EXT_PREFIX = "ext-gen"; function findExtLocator(e) { function getElementIndex(el, p) { var childs = p.childNodes; for (var i = 0; i < childs.length; i++) { var curr = childs; if (curr == el) { return "[" + (i + 1) + "]"; } } } if (e.id) { var elId = e.id; if (elId.indexOf(EXT_PREFIX) == 0) { var currNode = e; var locator = ""; while (currNode && currNode.tagName.toLowerCase() != "body") { parentNode = currNode.parentNode; locator = this.relativeXPathFromParent(currNode) + locator;// if (parentNode.id && parentNode.id.length > 0 && parentNode.id.indexOf(EXT_PREFIX) != 0) { locator = "//" + parentNode.tagName + "[@id='" + parentNode.id + "']" + locator; return locator; } currNode = currNode.parentNode; } } } return null; } LocatorBuilders.add('ext', findExtLocator); // You can change the priority of builders by setting LocatorBuilders.order. LocatorBuilders.order = ['ext', 'id', 'link', 'name', 'dom:name', 'xpath:link', 'xpath:img', 'xpath:attributes', 'xpath:href', 'dom:index', 'xpath:position'];
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    8#
     楼主| 发表于 2014-2-26 09:46:38 | 只看该作者
    回复 7# gaha


        感激不尽!!!
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-3 15:01 , Processed in 0.077350 second(s), 28 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表