一些QTP的实践及技巧

来源:互联网 发布:2016淘宝返利网排名 编辑:程序博客网 时间:2024/06/10 19:39

一些QTP的实践及技巧

1.区分不同browser. 在执行测试的时候,QC page 和 项目 wen page 是同时打开的, 有时候QTP识别的object会找不到,因为QTP会到QC页面上找,就需要把项目的 web Browser独一无二的property找出来;如果没有的话,试着用Ordinal identifier 来区别, 比如Creation Time.如果你的browser超过2个的话,请参考文章:

QTP - 10. DP (Descriptive Programming) 描述性编程. 的主题3.


2.为什么“WshShell.Echo”在QTP中失败,提示Object required?

If you write a vbScript script and execute it in Windows it is interpreted by the Windows Scripting Host (WSH) runtime interpreter. Execute that same script within QTP and it is interpreted by the QTP runtime interpreter. 

The WSH environment has a single built-in object name Wscript and that object is not supported nor available in any way, shape or form in QTP. And there is NO way to instantiate that object. So statements like wscript.echo fail under QTP but work just fine under WSH.

解决方案:

Set WshShell = CreateObject("wscript.Shell") 

WshShell.Echo

From : http://www.sqaforums.com/showflat.php?Number=506268


3. 为什么 Edit Box 填完之后,一按键就消失了,或者没填成功?

Tools--Options --Windows Application --Advanced --Run setting Edit Box --Check <Use keyboardevents to perform Set operations>

Here is the reason: Because the application have different event model. We can choose keyboard eventmodel, then we can achieve it.


4. remote 其他机器跑脚本, 如果最小化后台运行, QTP 会报错: object not visible.

    对于remote 界面, 不能最小化, 点击restore就好了。然后窗口放在最后面。(就是最小化,关闭窗口,中间那个按钮)


5. 网页点击link, 下载excel, qtp点击之后, 没有下载pop up,但是手工就有

设置IE: IE->Internet Options->Security-->Custom level-->Downloads->enable File download


6. ExecuteFile 和 LoadFunctionLibrary 的区别:

  ExecuteFile 是执行文件, 不能是只有function的文件, 负责报错.

   LoadFunctionLibrary 相反, 只加载source file文件.


7. 怎样使不同的datatable的行数一致:

DataTable.GetSheet("1").SetCurrentRow  CInt(DataTable.GetSheet(dtGlobalSheet).GetCurrentRow)

    怎样使vbs文件中参数的取值是基于setting 中的datatable iteration: 

先使不同的datatable的行数一致(如上), 再动态加载vbs文件:

LoadFunctionLibrary  "..\..\..\Test File\vbsFunctions.vbs"


8. 怎样使QTP report更有层次感?

如果使用Reporter.ReportEvent 方式, 那么所有的report是同一级别的. 如果要report在context(上下文)有关系, 就使用Reporter.LogEvent 方法.

e.g. LogEvent 三个参数:

第一个参数: report的大体样式模板, 值为:可以从QTP 的Results.xml 文件中找.

第二个参数: report的具体内容和样式.

第三个参数: 上下文关系. 这个决定着report是哪个层次.

Set objDict = CreateObject("Scripting.Dictionary")

objDict("Status") =micDone

objDict("PlainTextNodeName") = "Custom Report Example"

objDict("StepHtmlInfo") = "<DIV align=left>This is a <b>custom</b> report entry!</DIV>"

objDict("DllIconIndex") = 206
objDict("DllIconSelIndex") = 206
objDict("DllPAth") = "C:\Program Files (x86)\HP\QuickTest Professional\bin\ContextManager.dll"

Reporter.LogEvent "User", objDict, Reporter.GetContext


9.如果web page是xml, 怎样得到view source里面的text/string.

 方法: 把xml的内容保存为本地的文件(如txt), 然后熟悉的对象再找特定的string.

TempFileLocal="C:\Desktop\getxml.txt"
ttlstring = "<ttl>10</ttl>"
URL = "http://wetftg.com/1.xml" 

Set xPost=CreateObject("Microsoft.XMLHTTP") 
xPost.Open "GET",URL,0 
xPost.Send()

set sGet=CreateObject("ADODB.Stream") 
sGet.Mode=3 
sGet.Type=1 
sGet.Open() 
sGet.Write xPost.ResponseBody
sGet.SaveToFile TempFileLocal,2


10.如果是Input box怎样实现加密的输入?

Set loginForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form” , “System.Windows.Forms“)

loginForm.Text = title

loginForm.Name = “LoginForm”

loginForm.MaximizeBox = False

loginForm.MinimizeBox = False

loginForm.ShowInTaskbar = False

 

Set textPass = DotNetFactory.CreateInstance(“System.Windows.Forms.TextBox“, “System.Windows.Forms“)

textPass.Left = 90

textPass.Top = 35

textPass.Height = 25

textPass.Width = 135

textPass.UseSystemPasswordChar = True

 

loginForm.Controls.Add textPass

loginForm.ShowDialog

 

password = textPass.Text

Set textPass = Nothing

Set loginForm = Nothing


原创粉丝点击