QTP小知识

低级录制
在无法识别对象时使用

利用Vbs运行外部程序

WSH也就是用来解析Vbs的宿主,本身包含了几个个常用对象:

1、scrīpting.FileSystemObject  —>  提供一整套文件系统操作函数

2、scrīpting.Dictionary  —>  用来返回存放键值对的字典对象

3、Wscrīpt.Shell  —>  提供一套读取系统信息的函数,如读写注册表、查找指定文件的路径、读取DOS环境变量,读取链接中的设置

4、
Wscrīpt.NetWork  —>
提供网络连接和远程打印机管理的函数。(其中,所有scrīpting对象都存放在SCRRUN.DLL文件中,所有的Wscrīpt对象都存放在WSHOM.ocx文件中。)

现在我们需要的是第三个对象,好了,让我们先连接一下对象看看,在记事本的编辑窗口中输入:

Set ōbjShell = CreateObject(“Wscrīpt.Shell”)
objShell.Run “notepad”
Objshell.run “calc”
自建日志

Public Sub logfile(message)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime
currentDate = Date
currentTime = Time
testName = "log"
Set fileSystemObj = CreateObject("scrīpting.FileSystemObject")
fileSpec ="f:\log.txt"
If Not (fileSystemObj.FileExists(filespec)) Then
Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)
logFile.WriteLine("###############################################")
logFile.WriteLine (currentDate & currentTime & " Test: " & environment.Value("TestName") )
logFile.WriteLin("######################################")
logFile.Close
Set logFile = Nothing
End If
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForAppending, False, True)
logFile.WriteLine (currentDate & " "& currentTime & " " & message)
logFile.Close
Set logFile = Nothing
Set fileSystemObj = Nothing
End Sub
logfile(“ok")
Vb6生成
dll
Environment对象

检查页面文字显示颜色

Set Elements = Browser(“WisdomCRM客户关系管理系统”).Object.Document.all.tags(“div”)’tags(“td”)为在td中检查

For each Element in Elements
  If Element.InnerText="执行团队
" Then
    strhtml=Element.Innerhtml
    n=instr(strhtml,"color=red")
    If n=0 Then
      msgbox "Text color is red!"
   exit for
    End If
  End If
Next
关闭重复的页面

Dim loginwin
Set loginwin = descrīption.Create()                                                  '创建对象名为loginwin的对象

loginwin( "name").value="WisdomCRM客户关系管理系统"   ',对象属性及值



Set child=desktop.ChildObjects (loginwin)
cout=child.count
msgbox cout
For i=1 to cout
   child(i-1).close  '循环寻找这个对象

Next
获取当前测试的路径

Path = environment("TestDir")'获取当前测试的路径

msgbox path
获取本机
ip
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
Msgbox IPConfig.IPAddress(i)
next
end if
next
点亮对象

highlight
fireEvent用法

针对Link对象,onmouseover时间, 还有onchange, onclick, ondblclick, onblur, onfocus, onmousedown, onmouseup, onmouseout, onsubmit, onreset, onpropertychange事件可以使用

sendkeys实例

Set wshshell=createobject(“wscrīpt.shell”)
其使用格式为:object.SendKeys string “object”:表示WshShell对象 “string”:表示要发送的按键指令字符串,需要放在英文双引号中。 1.基本键   一般来说,要发送的按键指令都可以直接用该按键字符本身来表示,例如要发送字母“x”,使用“WshShell.SendKeys "x"”即可。当然,也可直接发送多个按键指令,只需要将按键字符按顺序排列在一起即可,例如,要发送按键“happy”,可以使用“WshShell.SendKeys "happy"”。

sendkeys实例

2.特殊功能键 对于需要与Shift、Ctrl、Alt三个控制键组合的按键,SendKeys使用特殊字符来表示: Shift---------WshShell.SendKeys "+" Ctrl---------WshShell.SendKeys "^" Alt---------WshShell.SendKeys "%" 由于“+”、“^”这些字符用来表示特殊的控制按键了,如何表示这些按键呢?只要用大括号括住这些字符即可。例如: 要发送加号“+”,可使用“WshShell.SendKeys "{+}"” 另外对于一些不会生成字符的控制功能按键,也同样需要使用大括号括起来按键的名称,例如要发送回车键,需要用“WshShell.SendKeys "{ENTER}"”表示,发送向下的方向键用“WshShell.SendKeys "{DOWN}"”表示。 Space---------WshShell.SendKeys " " Enter---------WshShell.SendKeys "{ENTER}" ←---------WshShell.SendKeys "{RIGHT}" ↑---------WshShell.SendKeys "{UP}" F1---------WshShell.SendKeys "{F1}" Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys允许使用简化格式进行描述,使用格式为“{按键 数字}”。例如要发送10个字母“x”,则输入“WshShell.SendKeys "{x 10}"”即可。


先录制取得初始脚本,再做简单的修改和参数化,再进行封装形成可重用的函数,最后回放调试,形成了最终的脚本。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值