IBM Functional Functional Test 的异常处理

  在基于JAVA界面的测试过程中,经常出现对象找不到或者对象被对话框遮挡的情况,如果不使用异常处理,测试脚本就会异常退出,笔者经过研究,发现在脚本对应的Helper类中加入对应的处理异常的代码可以解决该问题。
代码如下:
 
 public void onObjectNotFound(ITestObjectMethodState testObjectMethodState)
 {
    DomainTestObject domains[] = getDomains();
    for (int i = 0; i < domains.length; ++i) {
        if (domains[i].getName().equals("Html"))
        {
            TestObject[] topObjects = domains[i].getTopObjects();
            if (topObjects != null){
                try{
                    for (int j = 0; j < topObjects.length; ++j){
                        if (topObjects[j].getProperty(".class").equals("Html.JDialog")){
                            logWarning("HtmlScript.onObjectNotFound - dismissing dialog.",getRootTestObject().getScreenSnapshot());
                            VP.recordException(this.getScriptName(), new Exception("object not found exception occur!"));
                            try{
                                ((TopLevelTestObject)topObjects[j]).inputKeys("{enter}");
                               }catch(RuntimeException e) {
                                   
                               }
                        }
                    }
                }
                finally{
                    unregister(topObjects);
                }
            }
        }
    }
    logWarning("objectNotFound Exception occured on line "+this.getLineNumber()+" of "+this.getScriptName(), getRootTestObject().getScreenSnapshot());
    VP.recordException(this.getScriptName(), new Exception("objectNotFound Exception occured on line "+this.getLineNumber()+" of "+this.getScriptName()));
    ObjectNotFoundExceptionHandler objNotFound = new ObjectNotFoundExceptionHandler(this,testObjectMethodState);
    objNotFound.skipCurrentStatement();
 } 
 
 public void onTestObjectMethodException(ITestObjectMethodState testObjectMethodState, TestObject foundObject) {
        System.out.println("windowActiveeFailed");
     if (testObjectMethodState.getThrowableClassName().equals(
                "com.rational.test.ft.WindowActivateFailedException")) {
             logWarning("an unexpted dialog is appeared on line "+this.getLineNumber()+" of "+this.getScriptName(),getRootTestObject().getScreenSnapshot());
            VP.recordException(this.getScriptName(), new Exception("an unexpted dialog is appeared on line "+this.getLineNumber()+" of "+this.getScriptName()));
            IWindow activeWindow = RationalTestScript.getScreen().getActiveWindow();
            if (activeWindow != null) {
                activeWindow.inputKeys("Enter{Enter}");
                if(activeWindow.isShowing()){
                    activeWindow.close();
                }
            }
            testObjectMethodState.findObjectAgain();
        }
    }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值