QTP的一些小知识

发表于:2008-10-12 15:21

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:网络转载

  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

  2.把值插入datatable里

  例:   

datatable.setcurrentrow(i) 

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

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

  3.用代码来启动浏览器

Browser1 = "IE"

  StartURL = "www.51testing.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:\test.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

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号