多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

QTP的一些小知识-自动化测试

更新时间:2022-05-30 09:21:32 作者:多测师 浏览:179

  1.GetCellData函数

  作用:获取单元格的值

  例:

  rowCount = Browser("xxx ").Page("xxx ").Frame("xxx").WebTable("xxx").RowCount

  For counter = 1 To rowCount

  text = Browser("xxx").Page("xxx").Frame("xxx").WebTable("xxx").GetCellData(counter,1)

  If (text = "xxx") Then

  counter = counter - 1

  selectNO = "#" & counter

  Browser("xxx").Page("xxx").Frame("xxx").WebRadioGroup("xxx").Select selectNO

  Exit For

  End If

  Next

QTP的一些小知识-自动化测试

  2.把值插入datatable里

  例:

  datatable.setcurrentrow(i)

  datatable.value("name","Global")="name"

  datatable.value("passwd","Global")="passwd"

  3.用代码来启动浏览器

  Browser1 = "IE"

  StartURL = "www.duoceshi.com"

  IF Browser1 = "IE" THEN

  set IE = CreateObject("InternetExplorer.Application")

  IE.Visible = true

  IE.Navigate StartURL

  END IF

  4.ExecuteFile函数

  作用:ExecuteFile 可以直接执行vbs文件,而不需要将其导入resource中

  ExecuteFile FileName

  说明:where FileName is the absolute or relative path of your VBscrīpt file.

  例:ExecuteFile("F: est.vbs")

  5.Strcomp函数

  作用:比较文本

  例:

  dim strtext1,strtext2,str ,str1,comp1

  strtext1 = "xxx"

  strtext2 = "xxx"

  str = VbWindow("xxx").VbWindow("xxx").VbLabe1("xxx").GetTOProperty("text")

  str1= VbWindow("xxx").VbWindow("xxx").VbLabel("xxx").GetTOProperty("text")

  comp1=strcomp(strtext1,str,0)

  If comp=0 Then

  msgbox “这两个串相等”

  else

  msgbox str

  End If

  6.CaptureBitmap

  作用:捕获屏幕

  7. GetROProperty

  作用:取对象属性值

  例:VbWindow("xxx").VbWindow("xxx").VbWindow("xxx").ActiveX("xxx").GetROProperty("TextMatrix(1,0)")

  8.ExitAction - 退出当前操作,无论其循环属性如何。

  ExitActionIteration - 退出操作的当前循环。

  ExitRun - 退出测试,无论其循环属性如何。

  ExitGlobalIteration - 退出当前全局循环。

  9.如何使用Excel对象处理数据?

  Dim xl

  打开excel文件

  Function OpenExcelFile(strFilePath)

  Set xl = CreateObject("Excel.Application")

  xl.Workbooks.Open strFilePath

  End Function

  获得指定单元格数据

  Function GetCellData(strSheet,rwIndex,colIndex)

  GetCellData = xl.WorkSheets(strSheet).Cells(rwIndex,colIndex)

  End Function

  填充单元格数据

  Function PutCellData(strSheet,rwIndex,colIndex,varData)

  xl.WorkSheets(strSheet).Cells(rwIndex,colIndex) = varData

  End Function

  保存并推出

  Function SaveAndQuit()

  xl.Activeworkbook.save

  xl.Quit

  Set xl = nothing

  End Function

  10.连接sql数据库

  例:

  Dim res,cmd,sql

  Set Res=createobject("adodb.recordset")

  Set Cmd=createobject("adodb.command")

  Cmd.activeconnection="Provider=SQLOLEDB.1;Password=111111;Persist Security Info=True;User ID=sa;Initial Catalog=xhq;Data Source=192.168.191.142"  '这句话是连接数据库的数据源,要做修改

  Cmd.CommandType = 1

  sql="selec t * from 表 where name=username"

  Cmd.CommandText = sql

  Set res = Cmd.Execute()

  Set res = nothing

  Set cmd.ActiveConnection = nothing

  Set Cmd= nothing

  以上内容为大家介绍了自动化测试中的QTP的一些小知识,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部