zzqt_7 发表于 2009-10-9 16:23:40

讨论一下 QTP的几个问题

请教坛子里的各种牛~ 学习贴~

1.QTP的能为我们做什么?除了代替部分人工测试用例
2.框架的目的?
3.渴求牛B框架代码~
鄙人不才 也搞了一阵子QTP了 通过把各种已有材料汇总也有了自己的一套路子 但是总觉得还很不够用 所以发个贴子引人拍砖~

注:渴望各种牛B源代码的出现

lantianwei 发表于 2009-10-9 16:57:34

牛人出现在楼下 :lol

ChanJian910 发表于 2009-10-9 17:04:04

保持队形,后面的牛人同学继续

bichenlu 发表于 2009-10-9 17:42:10

期待

期待牛人出现,我也是同楼主相似,搞了一段时间的QTP,基本操作算是了解操作,但是实际运用中没没有预料中的效果好,希望高人能够指点迷津

hsjzfling 发表于 2009-10-9 20:10:46

框架的目的就是要提高开发和维护脚本的效率,节省成本。主要表现在提高脚本的重用性,制定脚本的开发、管理、维护规范,制定统一的开发流程。

至于框架代码倒是其次了,没有万能的代码能适合所有的产品和项目。框架的设计与很多因素相关,比如产品开发周期,测试周期,预计投入成本,计划自动化测试覆盖率等等,还有就是脚本管理,用正版QC还是其它方案,框架设计都会有较大的差别。

实际的运用和预期差别很大,主要还是在于前期投入上,一般项目往往不会提供那么多的资源在前期的框架设计上,而是希望迅速看到自动化的成果,这是需要在开始自动化之前就要确定好的,期望QTP做到什么程度,计划投入多少成本,然后才能根据拥有的人力、时间、技术、软硬件设备等资源制定出自动化脚本开发的计划。

dabeixiong 发表于 2009-10-9 20:47:18

我很幼稚的说...两句:L
1. 除了代替部分人工测试用例,那就是代替人做不了的事,或者做不好的事,比如重复性的工作。外加一句,你想干嘛?你想干嘛就拿他干嘛~你管他能干嘛呢...你都没想你干嘛~你能拿他干嘛呢?
2.框架的目的LS已经说的很在理了...
3.再牛B的框架不适用有啥用-.-!你能做个适合你的框架,那就是牛B...

zzqt_7 发表于 2009-10-10 09:53:51

回复 6# 的帖子

我靠~ 你一点都不幼稚 固定的~
dabeixiong兄 有点激动了吧
你有没有牛B的代码拿出来让大家看看?别说这些没用的~ 跟这泄愤 有劲吗?哈哈~
你若牛B 请出招~
装B 请闪~
这帖子的主要目的是希望可以把牛人的代码贴出来 然后多学习交流 泄愤者请自觉闪开

kevin_swpi 发表于 2009-10-10 10:00:07

呵呵
楼主先抛砖引玉吧

wuyuzimu 发表于 2009-10-10 10:06:53

迷惑中............

sluly 发表于 2009-10-10 10:10:28

在数据量大的时候,手工处理也是千篇一律,而且麻烦的要死,这个时候自动化就派上用场了。

wugecat 发表于 2009-10-10 10:22:06

期待牛B

lantianwei 发表于 2009-10-10 10:58:15

SAFFRON FRAME WORK

首先申明这是别人写的东西
我也没用过 大家可以看看怎么样
************************************************************
' S.A.F.F.R.O.N. Prototype 1.1'
' Simple Automation Framework For Remarkably Obvious Notes
' Copyright ? 2006 Mercury Interactive Corporation
'
' Notes:
'
' Requires QuickTest Professional 9.1
'
' Author       : Adam Gensler
' Created      : July 12, 2006
' Last Updated : September 11, 2006
'
' This prototype framework is provided AS IS, and is meant
' to be used for instructional purposes.
'
' This framework is a prototype, and is not supported
' by Mercury Interactive.
'
'************************************************************
initialized = false
thirdlevel = ""
level = ""
desc = ""
object = ""
objectDescription = ""

levelsubdescriptiondelimiter = ","
leveldescdelimiter = "|"
objectdelimiter = "|"
leveldelimiter = "|"
objectsDescriptiondelimiter = "|"

webLevels = "Browser|Page|Frame"
webLevelsDesc = "micclass:=Browser|micclass:=Page|micclass:=Frame|"
' 扩展对Image对象的支持
objects = "Link|WebButton|WebList|WebEdit|Image"
objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image"

' Generates a generic description based up on the "level" viarable
' levelstr - will be one of the values that is in the level array
' returns - string representative of the object hierarchy
Public Function GenerateDescription (levelstr)
l = IndexOf(level, levelstr)
If l >=0 Then
fdesc = level(0) & "(" & Quote(desc(0)) & ")."
If l >= 1 Then
   fdesc = fdesc + level(1) & "(" & Quote(desc(1)) & ")."
   If 2 >= l Then
    If thirdlevel <> "" Then
   fdesc = fdesc + level(2) & "(" & Quote(desc(2)) & "," & Quote("name:=" & thirdlevel) & ")."
    End If
   End If
End If
End If
   GenerateDescription = fdesc
End Function

' Generates an object description based upon the object, and objectDescription arrays
' obj - name of the object in the object array
' prop - additional property to help uniquely identify the object
' returns - a string representative of the object description
Public Function GenerateObjectDescription (obj, prop)
i = IndexOf(object, obj)
ndesc = ""
   If i <> -1 Then
ndesc = obj & "(" & Quote(objectDescription(i)) & "," & Quote(prop) & ")."
End If
GenerateobjectDescription = ndesc
End Function

' given an array, returns the index of the value to search for
' ary - an array
' str - value to search for in an array
' returns - index in array
Public Function IndexOf (ary, str)
val = -1
For i = 0 to UBound(ary)
If ary(i) = str Then
   val = i
End If
Next
IndexOf = val
End Function

' configures framework to work within the context of a specific frame
' val - the Name of the frame to work within -- use Object Spy if you don't
'       already know the frame name
Public Function WorkInFrame (val)
Report micPass, "Enter Frame", "Entered scope of frame " & Quote(val)
thirdlevel = val
End Function

' configures the framework to work outside the context of a specific frame
Public Function StopWorkingInFrame
Report micPass, "Exit Frame", "Exited scope of frame " & Quote(thirdlevel)
thirdlevel = ""
End Function

' generates a string with embedded/surrounding quotes
Public Function Quote (txt)
Quote = chr(34) & txt & chr(34)
End Function

' navigate to a site if the browser is already opened, otherwise run initialization
Public Function BrowseTo (url)
thirdlevel = ""
Report micPass, "Navigate to URL", "Navigating to URL: " & Quote(url)
If initialized Then
Execute GenerateDescription("Browser") & "Navigate " & Quote(url)
Else
Launch "website", url
End If
Reporter.Filter = rfDisableAll
End Function

' waits for the web page to finish loading
Public Function AutoSync
    Execute GenerateDescription("Browser") & "Sync"
End Function

' close all opened browsers
Public Function CloseBrowsers
If Browser("micclass:=Browser").Exist (0) Then
Browser("micclass:=Browser").Close
End If
While Browser("micclass:=Browser", "index:=1").Exist (0)
Browser("index:=1").Close
Wend
If Browser("micclass:=Browser").Exist (0) Then
Browser("micclass:=Browser").Close
End If
End Function

' prepares the framework for usage, and configures all internal framework
' variables and structures
' apptype - used to launch different types of applications based
'         upon different technologies -- currently there is only web
' val   - string that represents what to launch
' returns - always returns true
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)
object = split(objects, objectdelimiter, -1, 1)
objectDescription = split(objectsDescription, objectsDescriptiondelimiter, -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

' Verify the Existence of an object
' objtype - values should be limited to values in the object array
' text    - multi-purpose argument that indicates what to verify
'         - for a link, or button, it's the text of the control
'         - for a list, it's the name of the control
'         - for a frame, it's the name of the frame
Public Function Verify (objtype, text)
   rval = false
localDesc = ""
estr = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

   AutoSync()

Select Case objtype
Case "Page"
Execute "rval = " & GenerateDescription(level(1)) & "Exist (0)"
If rval Then
   Execute "title = " & GenerateDescription(level(1)) & "GetROProperty(" & Quote("title") & ")"
   If title = text Then
    rval = true
   Else
    rval = false
   End If
End If
Case "CurrentFrame"
If thirdlevel <> "" Then
   estr = "rval = " & localDesc
End If
Case "Link"
estr ="rval = " & localDesc & GenerateObjectDescription("Link", "innertext:=" & text)
Case "WebButton"
estr = "rval = " & localDesc & GenerateObjectDescription("WebButton", "value:=" & text)
Case "WebList"
estr = "rval = " & localDesc & GenerateObjectDescription("WebList", "name:=" & text)
Case "WebEdit"
estr = "rval = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & 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

   Verify = rval
End Function

' 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."
End Select
End Function

' Selects a specific value from a listbox, or combobox
' objname - name of the control -- use Object Spy if you don't know the name property
' text    - the item in the combobox to select
Public Function SelectFromList (objname, text)
localDesc = ""
rv = ""
rval = false
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objname)

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

SelectFromList = rval
End Function

' Enters text into an edit field
' objname - name of the control -- use Object Spy if you don't know what it is
' text    - the text to enter into the control
Public Function EnterTextIn (objname, text)
localDesc = ""
rval = true
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objname)
Execute localDesc & "Set (" & Quote(text) & ")"
Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objname)
EnterTextIn = rval
End Function

' Obtains text from a control
' objtype - is the type of control the get the text from
' objname - is the name of the control -- use Object Spy if you don't know the name
' returns - the text of the control
Public Function GetTextFrom (objtype, objname)
text = ""
localDesc = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

Select Case objtype
Case "WebEdit"
   Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
Case "WebList"
   Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
End Select
Report micPass, "Capture Text", "Text: " & Quote(text) & " was captured from the control " & Quote(objname)
GetTextFrom = text
End Function

' Wrapper for the Reporter.Report Event method
' - could be used to create custom reports more easily
' See Reporter.ReportEvent documentation for usage
Public Function Report (status, objtype, text)
Reporter.Filter = rtEnableAll
Reporter.ReportEvent status, objtype, text
Reporter.Filter = rfDisableAll
End Function

zzqt_7 发表于 2009-10-10 15:41:59

回复 12# 的帖子

顶起~~别让这帖子沉了 以后大家可以从这里的代码里面找灵感~
我正在整理一些代码 回来传上来~

zzqt_7 发表于 2009-10-10 15:43:26

回复 5# 的帖子

来点实际的~

zzqt_7 发表于 2009-10-12 11:36:16

我现在的对QTP的理解

1.我不喜欢用对象库这东西 修改起来很麻烦 所以都是描述性编程 便于修改 所以也不录制什么脚本
2.基本上的思路
创建:结果收集文件夹
调用:Excel表中的参数化测试数据
结果:收集到对应的表格,然后来个信息汇总
3.对应的动作都写成Function,用Function的组合完成测试用例。
4.基本上就是这样吧 别的更高深我还真不知道了 请高人指教~

mklodoss 发表于 2009-10-12 20:12:23

顶,别沉了。。。

zzqt_7 发表于 2009-10-14 16:40:16

请教一个问题

我怎么用QTP从远程主机上返回值呢?

例子:
我在远程主机上Ping一个IP地址 我想把它Ping通或者Ping不通的返回值 返回到运行QTP的本机 有什么招?

lantianwei 发表于 2009-10-14 16:55:45

1. 不知道QTP有没有执行这些命令化的函数 ST中SYS_EXECUTE()是直接可以获得这些信息的 查吓帮助看看有没有吧
2 借用外部执行文件 如VBS WMI BAT等获取信息, 比如BAT 可以先把命令写在BAT中 然后把结果重定向到输出文件 再进行解析
3. 自己写扩展插件 用。NET搞这个应该还挺方便的 对QTP的支持也不错

zzqt_7 发表于 2009-10-16 11:04:46

回复 18# 的帖子

Bat文件都是调用远程主机的文件到本机运行。

我的想法是调用这个Bat文件 在远程主机运行 然后把运行结果 返回到本机~

你觉得从逻辑上能实现吗?

lantianwei 发表于 2009-10-16 11:34:54

回复 19# 的帖子

用WMI应该没啥问题
页: [1] 2
查看完整版本: 讨论一下 QTP的几个问题