QTP tips【转】

上一篇 / 下一篇  2013-11-14 09:30:28 / 个人分类:QTP备忘

1、Object Spy的Tips

  Hold the CTRL key to change the window focus or perform. other mouse operations

  2、QTP为什么无法单步调试?

  安装Microsoft Script. Debuger即可

  3、QTP如何访问Oracle数据库?

  Dim rs,sq,pkey

  set conn=createobject("adodb.connection")

  set rs=createobject("adodb.recordset")

  ' 需要安装Oracle客户端

  conn.open "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=scott;Data Source=orcl;Password=orcl;Extended Properties=;Host=192.168.1.188;Port=1521;Service Name=orcl;"

  sql="SELECT * FROM TAB"

  rs.open sql,conn

  rs.MoveFirst

  Do While rs.Eof<>true

  Msgbox rs.Fields(0)

  rs.MoveNext

  Loop

  rs.close

  set rs=nothing

  conn.close

  set conn=nothing

  4、如何全选所有webCheckBox对象?

  Dim oWebChkDesc

  Set WebChkDesc = Description.Create

  oWebChkDesc("micclass").value = "WebCheckBox"

  oWebChkDesc("html tag").Value = "INPUT"

  ' 获取所有匹配描述的对象

  Dim allCheck, oCheckBox

  Set allCheck = Browser("Web Tours").Page("Web Tours").ChildObjects(oWebChkDesc)

  For i = 0 to allCheck.Count - 1

  Set CheckBox = allCheck(i)

  oCheckBox.Set "ON"

  Next

  5、QTP9.2录制脚本问题:运行QTP,点击录制钮进行脚本录制,但是IE浏览器打开后几秒钟,又自动关闭了,不知道为什么?

  QTP9.2支持的IE浏览器版本:

  Microsoft Internet Explorer 6.0 Service Pack 1

  Microsoft Internet Explorer 7.0

  6、Action之间无法传递数组

  用全局的Dictionary对象来存储数据,这样可以在多个Action之间共用数据

  参考:

  http://blog.csdn.net/Testing_is_believing/archive/2010/01/08/5161955.aspx

  http://blog.csdn.net/Testing_is_believing/archive/2008/06/09/2528094.aspx

  也可以这样:

  建一个vbs文件,定义变量,在Setting—>Resources导入这个VBS文件

  在主Action里面 给变量赋值

  在子Action中调用这个变量

  这个变量的内存相当于共享

  7、QTP脚本编辑器中可以修改Tab键跳转的格数吗?

  编辑脚本时,总感觉Tab一次,移动的格数太少

  Tools -> View Options

  8、如何在VBScript中调用QTP脚本

  现在有一个用QTP录制好的脚本,但是想用VBS来调用,如何调用?

  Dim qtApp 'As QuickTest.Application ' Declare the Application object variable

  Dim qtTest 'As QuickTest.Test ' Declare a Test object variable

  Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable

  Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

  qtApp.Launch ' Start QuickTest

  qtApp.Visible = True ' Make the QuickTest application visible

  ' Set QuickTest run options

  qtApp.Options.Run.ImageCaptureForTestResults = "OnError"

  qtApp.Options.Run.RunMode = "Fast"

  qtApp.Options.Run.ViewResults = False

  qtApp.Open "C:TestsTest1", True ' Open the test in read-only mode

  ' set run settings for the test

  Set qtTest = qtApp.Test

  qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4

  qtTest.Settings.Run.StartIteration = 2

  qtTest.Settings.Run.EndIteration = 4

  qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform. next step when error occurs

  Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object

  qtResultsOpt.ResultsLocation = "C:TestsTest1Res1" ' Set the results location

  qtTest.Run qtResultsOpt ' Run the test

  MsgBox qtTest.LastRunResults.Status ' Check the results of the test run

  qtTest.Close ' Close the test

  Set qtResultsOpt = Nothing ' Release the Run Results Options object

  Set qtTest = Nothing ' Release the Test object

  Set qtApp = Nothing ' Release the Application object

  9、没安装QTP打开QTP脚本的方法

  QTP的脚本在每个action的根目录下的Script.mts文件,用UltraEdit或记事本等工具打开就可以看到。

  10、QTP支持的正则表达式

  使用反斜杠字符 ( )

  匹配任意单个字符 ( . )

  匹配列表中的任意单个字符 ( [xy] )

  匹配不在列表中的任意单个字符 ( [^xy] )

  匹配某个范围内的任意单个字符 ( [x-y] )


TAG:

 

评分:0

我来说两句

Open Toolbar