saffron框架学习和扩展笔记二

上一篇 / 下一篇  2011-07-21 16:00:17 / 个人分类:自动化

对对象WebRadioGroup(name属性)(Select方法)、WebElement(innertext属性)(click方法)、WebCheckBox(index属性)(Set 方法)的扩展
首先在变量中定义三个对象,如下:
' 扩展对Image、WinButton、WebRadioGroup、WebElement、WebCheckBox(--任全德-20110712)对象的支持
objects = "Link|WebButton|WebList|WebEdit|Image|WinButton|WebRadioGroup|WebElement|WebCheckBox"
objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image|micclass:=WinButton|micclass:      =WebRadioGroup|micclass:=WebElement|micclass:=WebCheckBox"


1、在Activate函数中增加WebElement的点击操作,如下:
 Activates an object based upon its object type
' objtype - the type of object should be limited to values in the object array
' text    - identifying text for the control - for a link, it's the text of the link
Public Function Activate (objtype, text)
localDesc = ""
If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
Else
  localDesc = GenerateDescription(level(1))
End If
AutoSync()
Select Case objtype
Case  "Link"
  Execute localDesc & GenerateObjectDescription("Link","innertext:=" & text) & "Click"
  Report micPass, "Link Activation", "The Link " & Quote(text) & " was clicked."
Case "WebButton"
  Execute localDesc & GenerateObjectDescription("WebButton", "value:=" & text) & "Click"
  Report micPass, "WebButton Activation", "The WebButton " & Quote(text) & " was clicked."
' 扩展对Image类型的按钮的支持
Case "Image"
  Execute localDesc & GenerateObjectDescription("Image", "alt:=" & text) & "Click"
  Report micPass, "ImageButton Activation", "The ImageButton " & Quote(text) & " was clicked."
' 扩展对WebElement类型的标签的支持-任全德--20110713
Case "WebElement"
  Execute localDesc & GenerateObjectDescription("WebElement", "innertext:=" & text) & "Click"
  Report micPass, "WebElement Activation", "The WebElement " & Quote(text) & " was clicked."
End Select
End Function


2、在SelectFromList函数中增加WebRadioGroup的选择操作,如下:
' Selects a specific value from a listbox, or combobox
' objproperty - name of the control -- use Object Spy if you don't know the name property
' text    - the item in the combobox to select
'objtype --new add  parameter(新增一个参数)  用来判断对象的类型--renquande 110713
Public Function SelectFromList (objtype,objproperty, text)
localDesc = ""
rv = ""
rval = false
If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
Else
  localDesc = GenerateDescription(level(1))
End If
AutoSync()
Select Case objtype
Case "WebList"
localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objproperty)
Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
For i = 1 to cnt
  Execute "rv = " & localDesc & "GetItem (" & i & ")"
  If rv = text Then
   rval = true
  End If
Next
If rval Then
  Execute localDesc & "Select " & Quote(text)
End If
If rval Then
  Report micPass, "WebList Selection", "The WebList item " & Quote(text) & " was selected."
Else
  Report micFail, "WebList Selection", "The WebList item " & Quote(text) & " was NOT found."
End If
'扩展对WebRadioGroup对象的支持---任全德--20110713
Case "WebRadioGroup"
    localDesc = localdesc & GenerateObjectDescription("WebRadioGroup", "name:=" & objproperty)

Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
For i = 1 to cnt
  Execute "rv = " & localDesc & "GetItem (" & i & ")"
  If rv = text Then
   rval = true
  End If
Next
If rval Then
  Execute localDesc & "Select " & Quote(text)
End If
If rval Then
  Report micPass, "WebRadioGroup Selection", "The WebRadioGroup item " & Quote(text) & " was selected."
Else
  Report micFail, "WebRadioGroup Selection", "The WebRadioGroup item " & Quote(text) & " was NOT found."
End If
End Select
SelectFromList = rval
End Function

3、在EnterTextIn函数中增加WebCheckBox对象的set操作
' Enters text into an edit field
' objproperty - name of the control -- use Object Spy if you don't know what it is
' text    - the text to enter into the control
'objtype --new add  parameter(新增一个参数)  用来判断对象的类型--renquande 110713
Public Function EnterTextIn ( objtype,objproperty, text)
localDesc = ""
rval = true
If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
Else
  localDesc = GenerateDescription(level(1))
End If

AutoSync()
Select Case objtype
Case "WebEdit"
localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objproperty)
Execute localDesc & "Set (" & Quote(text) & ")"
Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objproperty)
'扩展对WebCheckBox对象的支持-任全德--20110713
Case "WebCheckBox"
localDesc = localdesc & GenerateObjectDescription("WebCheckBox", "index:=" & objproperty)
Execute localDesc & "Set (" & Quote(text) & ")"
Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objproperty)
End Select
EnterTextIn = rval
End Function


TAG: QTP qtp saffron

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-05  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

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

RSS订阅

Open Toolbar