saffron框架学习和扩展笔记一

上一篇 / 下一篇  2011-07-21 15:50:39 / 个人分类:自动化

以前只是使用了qtp录制的功能,做了一个项目,感觉可维护性比较差,报错的概率也比较大,而且对对象库的依赖也比较大,就一直在思索,怎么能把不同的功能封装起来,然后直接调用不同功能的函数,来实现自动化测试,幸好网上找了一个哥们共享的saffron框架源码,发现很是不错,就研究了一下,也做了一些扩展,来实现符合自己公司的一些功能,下面说下自己的学习切入点,也是很多初学者可能遇到的,不知道如何下手:

我用了比较笨的方式,把自己不知道输出内容的变量全都打印出来,弄清楚源码中各变量的含义以及函数调用关系

下面把我做的函数扩展贡献出来,希望对能用到的人员有用,直接调用即可,封装成单独的VBS或者放到一个vbs都可以:

关于对话框的处理
分析:录制时其他web对象的脚本格式为:Browser(“xxx”).Page(“xxx”)
                 Dialog的脚本格式为:Browser(“xxx”).Dialog(“xxx”)
现在saffron基础框架里面没有dialog描述性对象,故需要新增一套处理dialog的函数,
1、用来判断dialog是否存在
2、用来点击dialog上面的“确定”和“取消”按钮(winbutton)
3、用来动态获取dialog提示信息

首先进行定义对象数组和描述性对象数组,如下所示:
'对dialog的扩展--任全德-20110712
dialogLevel = ""
dialogLevelDesc = ""
'对dialog的扩展--任全德-20110712
dialogLeveldelimiter = "|"
dialogLevelDesclimiter = "|"

' 扩展对WinButton(--任全德-20110712)对象的支持
objects = "Link|WebButton|WebList|WebEdit|Image|WinButton"
objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image|micclass:=WinButton"
'对dialog分层的扩展--任全德-20110712
dialogLevels = "Browser|Dialog"
dialogLevelsDesc = "micclass:=Browser|micclass:=Dialog"

1、打开浏览器函数中对定义数组的分解处理(修改)
Public Function Launch (apptype, val)
If "website" = apptype Then
  thirdlevel = ""
  Report micPass, "Initialize", "Initializing Framework"
  level = split(webLevels, leveldelimiter, -1, 1)
  desc = split(webLevelsDesc, leveldescdelimiter, -1, 1)
  bject = split(objects, objectdelimiter, -1, 1)
  bjectDescription = split(objectsDescription, objectsDescriptiondelimiter, -1, 1)
  '新增dialog分层分解处理--任全德-20110712
  dialogLevel = split(dialogLevels, dialogLeveldelimiter, -1, 1)
  dialogLevelDesc = split(dialogLevelsDesc, dialogLevelDesclimiter, -1, 1)

  CloseBrowsers
  Set IE = CreateObject("InternetExplorer.Application")
  IE.visible = true
  IE.Navigate val
  While IE.Busy
   wait 1
  Wend
End If
initialized = true
Launch = true
End Function

2、新增判断dialog(及dialog上面winbutton按钮)是否存在的函数
'增加dialog是否存在的判断扩展--任全德-20110712
Public Function Verifydialog (objtype, text)
   rval = false
localDesc = ""
estr = ""
If thirdlevel <> "" Then
  localDesc = GenerateDescriptiondialog(dialogLevel(2))
 
Else
  localDesc = GenerateDescriptiondialog(dialogLevel(1))
End If
   AutoSync()
Select Case objtype
'renquande增加扩展Dialog的支持-任全德-20110712
Case "Dialog"
  estr = "rval = " & localDesc & GenerateObjectDescription("Dialog", "text:=" & text)
'扩展没有value的WinButton的使用
Case "WinButton"
  estr = "rval = " & localDesc & GenerateObjectDescription("WinButton", "text:=" & text)
End Select
If estr <> "" Then
  Execute estr + "Exist (0)"
End If

If rval Then
  Report micPass, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was verified to exist"
Else
  Report micFail, objtype & "  Verification", "The " & objtype & " " & Quote(text) & " was not found"
End If

If "True" = rval Then
  rval = True
Else
  rval = False
End If
   Verifydialog = rval'需要特别注意,别忘了进行修改
End Function

3、新增处理返回描述性对象GenerateDescriptiondialog(x)的函数处理,入参为分解后的数组,返回内容为Browser(“micclass:=Browser”).Dialog(“micclass:=Dialog”)-任全德-20110712
Public Function GenerateDescriptiondialog (levelstr)
l = IndexOf(dialogLevel, levelstr)
If l >=0 Then
  fdesc = dialogLevel(0) & "(" & Quote(dialogLevelDesc(0)) & ")."
  If l >= 1 Then
   fdesc = fdesc + dialogLevel(1) & "(" & Quote(dialogLevelDesc(1)) & ")."
   If 2 >= l Then
    If thirdlevel <> "" Then
     fdesc = fdesc + dialogLevel(2) & "(" & Quote(dialogLevelDesc(2)) & "," & Quote("name:=" & thirdlevel) & ")."
    End If
   End If
  End If
End If
   GenerateDescriptiondialog = fdesc   
End Function

4、新增对dialog上面winbutton的处理函数-任全德-20110712
'扩展dialog上确定按钮(winbutton)的使用,Activatedialog
Public Function Activatedialog (objtype, text)
localDesc = ""
If thirdlevel <> "" Then
  localDesc = GenerateDescriptiondialog(dialogLevel(2))
Else
  localDesc = GenerateDescriptiondialog(dialogLevel(1))
End If

AutoSync()
If  bjtype = "WinButton" Then
  Execute localDesc & GenerateObjectDescription("WinButton", "regexpwndtitle:=" & text) & "Click"
  Report micPass, "WinButton Activation", "The WinButton " & Quote(text) & " was clicked."
End If
End Function


5、获取dialog上面的提示信息并写入datatable中-任全德-20110713
'objtype---对象类型,一般是winbutton
'text----对象的属性值,winbutton的属性是regexpwndtitle的值
'sheet_name---要写入datatable的sheet页的名字
'column_name----指定sheet页的列名
Public Function GetdialogProperty (objtype, text,sheet_name,column_name)
localDesc = ""
If thirdlevel <> "" Then
  localDesc = GenerateDescriptiondialog(dialogLevel(2))
Else
  localDesc = GenerateDescriptiondialog(dialogLevel(1))
  msgbox "Activatedialog====="&localDesc
End If

AutoSync()
If  bjtype = "WinButton" Then
        Execute  "getdialogproperty = "& localDesc & GenerateObjectDescription("WinButton", "regexpwndtitle:=" & text) &"GetROProperty("& Quote("attached text") & ")"
        H=DataTable.GetSheet(sheet_name).GetRowCount
        DataTable.SetCurrentRow(H+1)
        DataTable(column_name,sheet_name)= getdialogproperty

End If

End Function

这一套增加后就可以实现dialog的处理啦


TAG: QTP qtp saffron

fisherlala的个人空间 引用 删除 fisherlala   /   2011-10-10 15:49:56
5
fisherlala的个人空间 引用 删除 fisherlala   /   2011-10-10 15:49:50
谢谢博主
我最近也是刚接触SAFFRON框架,正考虑扩展框架的,你的文章对我帮助很大
 

评分:0

我来说两句

我的栏目

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 4522
  • 日志数: 6
  • 建立时间: 2011-04-25
  • 更新时间: 2011-08-05

RSS订阅

Open Toolbar