zoukankan      html  css  js  c++  java
  • 利用FSO生成QTP测试报告

    上一篇文章里只是简单谈了些FSO文本文件系统对象的几个常用的方法。本文将主要介绍FSO怎样生成测试报告。

    下面列举了web测试里常见的Edit控件跟button控件的操作。

    Function WebEdit_SetValue(obj,val)
        obj.Set val
        Const ForAppending = 8
        Const ForWriting = 2
        Const ForReading = 1
        Set fso = CreateObject("Scripting.FileSystemObject")
        logFileName = cstr(Year(now) & Month(now) & Day(now)) + ".txt"
        logFilePath = Environment.Value("ResultDir") + "\" + logFileName
        print logFilePath
        If not fso.FileExists(logFilePath) Then
            Set resFile = fso.CreateTextFile (logFilePath,False)
        Else
            Set resFile = fso.OpenTextFile(logFilePath,ForAppending,True)
        End If
        strLog = cstr(Time) + " Object: [" + obj.getToProperty("micClass") + _
        "-" + obj.getToProperty("TestObjName") + "] - Description:" + _
        "Set value is: <" + val + ">"
        resFile.WriteLine strLog
        Set resFile = Nothing
        Set fso = Nothing
    End Function
    
    Function WebButton_Click(obj)
       obj.Click
       Const ForAppending = 8
       Const ForWriting = 2
       Const ForReading = 1
       Set fso = CreateObject("Scripting.FileSystemObject")
       logFileName = cstr(Year(now) & Month(now) & Day(now)) + ".txt"
       logFilePath = Environment.Value("ResultDir") + "\" + logFileName    
       If not fso.FileExists(logFilePath) Then
           Set resFile = fso.CreateTextFile (logFilePath,False)
       Else
           Set resFile = fso.OpenTextFile(logFilePath,ForAppending,True)
       End If
       strLog = cstr(Time) +  " Object: [" + obj.getToProperty("micClass") + _
        "-" + obj.getToProperty("TestObjName") + "] - Description:" + _
        "Click object success" 
        resFile.WriteLine strLog
        Set resFile = Nothing
        Set fso = Nothing
    End Function
    
    
    RegisterUserFunc "WebEdit","Set","WebEdit_SetValue"
    RegisterUserFunc "WebButton","Click","WebButton_Click"
    With Browser("百度一下,你就知道").Page("百度一下,你就知道")
        .WebEdit("wd").Set("Hello Mr Sun")
        .WebButton("百度一下").Click
    End With

    两个Function里其实有很多地方是重复的,可以将他们合并,也可以用到我之前讲过的相对路径的技术。有兴趣的可以试着实现。我会在之后自己写框架时再次具体呈现。

    下面的是生成的txt格式的测试报告,看起来也蛮清楚的~txt格式的比较简单,当然也可以是xml格式的或者html格式的,怎样方便怎么写吧,你可以随心所欲地设计你想要的测试报告,我只是抛砖引玉。

  • 相关阅读:
    波形相加
    2003-2011电赛题目
    个人课程总结
    程序员的修炼之道:从小工到专家阅读笔记03
    程序员修炼之道:从小工到专家阅读笔记02
    计算最长英语单词链
    学习进度十五
    程序员修炼之道:从小工到专家阅读笔记01
    学习进度十四
    用户体验评价
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/2708706.html
Copyright © 2011-2022 走看看