vbs 连oracle 负载均衡,(原)QTP中用VBS调用PLSQL并执行相关语句

今天工作的需求是要在录制一段web程序之前要调用plsql并执行一段数据库代码清空相关数据才能做web录制测试,

本来是想用QTP直接录制plsql的,但是后来发现自己对qtp录制window application并不是很了解,选定了 Automation菜单下的Record and Run Settings中的制定plsql程序的路径,一录制竟然也代开了web的初始页面,后来发现是要把web的Record and Run Settings中设置成第一个选项 Record and run on any browser才不弹出来了。

后来发现,竟然qtp录制plsql的脚本就像低级录制的脚本一样,是用坐标表示的(Window("Oracle Logon").WinObject("test").Click 44,8)。回放一点反应都没有。不行,时间紧迫,我得另外想办法搞定这个plsql。

直接用vbs代码写了段调用调用PLSQL并执行相关语句的片段。运行成功,搞定!!。。

代码中对plsql的路径和用于运行的语句(从doc中复制的呵呵)DOC文件路径进行了判断,如果不正确将提示修改路径,一直到路径核对正确为止,如果两个路径都正确,则直接call dosub().

本来想通过字段赋值再sendkeys到plsql中指定的语句,但是后来发现语句中有特殊字符,读到plsql中的时候很慢而且有乱码,所以后来想用vbs操作了下word,直接从word中复制语句再在plsql中粘贴了.(从plsql中打开我试过了,没有句柄不行,ctrl+o不执行。)

VBS代码:

'----------------------------定义变量-------------------------------------------

Dim oApp,oDoc,fso,exepath,docpath,inputexestr,inputdocstr,inputexestr2,inputdocstr2,confirmexepath,confirmdocpath,exefile,docfile

exepath = "C:\Worksoft\plsql\PlSqlDev.exe"

docpath = "C:\StudyInfo\Study\VBS\ReadyData.doc"

'----------------------------创建系统对象------------------------------------

Set Wshell=CreateObject("Wscript.Shell")

set fso=CreateObject("Scripting.FileSystemObject")

'----------------------------判断plsql路径和doc文件路径是否存在----------------------

Call maincheck()

Sub   checkexeway()

inputexestr = InputBox("请确认或输入您的plsql程序路径:"&vbnewline&"如果此路径正确请点击OK!","PLSQL路径确认",exepath)

inputexestr2=  fso.FileExists(inputexestr)

If  inputexestr2<>"" and  inputexestr2 = True Then

confirmexepath = inputexestr

call checkdocway()

else

call  checkexeway()

End If

End Sub

Sub   checkdocway()

inputdocstr = InputBox("请确认或输入您的DOC文件路径:","DOC文件路径确认",docpath)

inputdocstr2=  fso.FileExists(inputdocstr)

If  inputdocstr2<>"" and  inputdocstr2 = True  Then

confirmdocpath = inputdocstr

call  Dosub()

else

call  checkdocway()

End If

End Sub

Sub maincheck()

exefile = fso.FileExists(exepath)

docfile = fso.FileExists(docpath)

If  exefile =true and  docfile =true Then

confirmexepath = exepath

confirmdocpath = docpath

call Dosub()

else

call checkexeway()

End If

end sub

'-------------------------------------------调用plsql并运行语句过程--------------------------------------------

Sub Dosub()

'msgbox confirmexepath

'msgbox confirmdocpath

Set App = CreateObject("Word.Application")

oApp.visible = true

Set Doc = oApp.Documents.Open (confirmdocpath)

Wshell.AppActivate "ReadyData.doc - Microsoft Word"

oApp.selection.WholeStory

oApp.selection.copy

oDoc.close

oApp.quit

Wshell.SendKeys "{Left}"

Wshell.SendKeys "{Enter}"

wait 5

wait 2

set exec=Wshell.Exec(confirmexepath)

wait 2

'这里直接输入密码test,因为plsql默认了用户名不用输入,没有默认就需要前面再加   个sendkeys了

Wshell.SendKeys "test"

wait 1

Wshell.SendKeys "{TAB}"

'这里输入服务器名称.要确保你的oracal的tnsname里面有这个服务器名.

Wshell.SendKeys "cis170"

wait 2

Wshell.SendKeys "{ENTER}"

wait 4

'把刚才从word复制的内容粘贴到plsql

Wshell.SendKeys "^v"

wait 2

'运行语句快捷键f8

Wshell.SendKeys "{F8}"

wait 5

'提交语句commit快捷键f8

Wshell.SendKeys "{F10}"

wait 2

Wshell.SendKeys "%{F4}"

wait 2

Wshell.SendKeys "{Right}"

Wshell.SendKeys "{Enter}"

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值