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)?;胤乓稽c反應都沒有。不行,時間緊迫,我得另外想辦法搞定這個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
總結
以上是生活随笔為你收集整理的vbs 连oracle 负载均衡,(原)QTP中用VBS调用PLSQL并执行相关语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第4章 Python 数字图像处理(DI
- 下一篇: opengauss数据库常用SQL语句