QuickTest底层VB脚本驱动

news/2024/7/7 9:38:01

sample Codes:


'****  Author: Wally Yu (俞戴龙)
'***   Import common functions into report function   ****
Dim fso : set fso = createobject("scripting.filesystemobject")
executeglobal fso.opentextfile("C:\Framework\FrameworkCore\Common\common.vbs", 1).ReadAll
executeglobal fso.opentextfile("C:\Framework\FrameworkCore\Common\report.vbs", 1).ReadAll
set fso = Nothing
'***   End of importing     ******************************


'On Error Resume Next

'###  Report dim area  ####
'On Error Resume Next
Dim StartTime, EndTime, stTime, enTime, ServerName
Dim testWorkBook, testCaseSheet, startSheet

'***************INITIALISATION***************************
testWorkBook = "c:\framework\testcase.xls"
testCaseSheet = "testcase"
startSheet = "start"
'**************************************************************



ServerName = "."  '****** Confirm Server Name before run test ********
runtime = Date & "-"& Hour(Now) & Minute(Now)& Second(Now)
runtime = changeString(runtime, "/", "-")
folderPath="c:\Framework\Report\"&runtime
emailAddress = ReadExcelCell(testWorkBook, startSheet, 1,1)
StartTime = Timer
stTime = Time
LogReportFlag = True
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

'#####    initReport    #####
Call CreatFolderIfNotExist("c:\Framework")
Call CreatFolderIfNotExist("c:\Framework\report")
Call initReport("c:\Framework\Report", "c:\Framework\Report\"&runtime)

Set obj = CreateObject("QuickTest.Application") 'Creates an instance of the QTP
call Mbox("Invoking QTP...",2,msgbox2)    
'WScript.Echo "Invoking QTP..."

obj.Launch
obj.Visible = true
obj.WindowState = "Maximized" 'Maximizes the application window of the QTP


folderfile="C:\Framework\FrameworkCore\Common\FoldersFile.vbs"

   If fso.FileExists(folderfile) Then
        Set f = fso.OpenTextFile(folderfile)
        s = f.ReadAll
        f.Close
        ExecuteGlobal s
   End If    

   
obj.open "c:\framework\frameworkcore\core data\test"

call Mbox("Loading library files into QTP scripts...",2,msgbox3)    
'WScript.Echo "Loading library files into QTP scripts..."

Set oExcel = CreateObject("Excel.Application") 'open Excel Application
Set oWorkbook = oExcel.Workbooks.Open(testWorkBook)
Set oWorksheet1 = oWorkbook.Worksheets.Item(startSheet) 'Set up the worksheet
'Set url = oWorksheet1.cells

obj.Test.Environment.Value("gbl_emailAddress") = oworksheet1.textbox1.text
obj.Test.Environment.Value("folderPath")=folderPath
obj.Test.Environment.Value("TransactionCode")=""
obj.Test.Environment.Value("BatchID")=""
obj.Test.Environment.Value("ExecutionFlag")=""
obj.Test.Environment.Value("ClaimsReimbursement")=""
obj.Test.Environment.Value("con")=""

'obj.Test.Environment.Value("gbl_app") = oWorksheet1.ComboBox1.text
'obj.Test.Environment.Value("gbl_app_url") = oworksheet1.range("G21").text

gbl_emailAddress = oworksheet1.textbox1.text
'gbl_app = oWorksheet1.ComboBox1.text

'gbl_emailAddress=url(1,1)
'gbl_app=oWorksheet1.ComboBox1.text
'gbl_app_url=url(21,7)

oWorkbook.close FALSE
oExcel.quit
set oExcel = Nothing

Set qtLibraries = obj.Test.Settings.Resources.Libraries ' Get the libraries collection object

If qtLibraries.Find("c:\framework\frameworkcore\Common\main.vbs") = -1 Then
    qtLibraries.Add "c:\framework\frameworkcore\Common\main.vbs", 1
End If
'If qtLibraries.Find("c:\framework\frameworkcore\Common\core data\action.vbs") = -1 Then
'    qtLibraries.Add "c:\framework\frameworkcore\Common\core data\action.vbs", 1
'End If
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Globalvariable.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Globalvariable.vbs", 1
End If    
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Report.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Report.vbs", 1
End If
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Common.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Common.vbs", 1
End If

'Set qtTestRecovery = obj.Test.Settings.Recovery

'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE1", 1
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE2", 2
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE3", 3
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE4", 4

'' Enable all scenarios
'For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
' qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
'Next
'
'' Enable the recovery mechanism (with default, on errors, setting)
'qtTestRecovery.Enabled = True
'
''Ensure that the recovery mechanism is set to be activated only after errors
'qtTestRecovery.SetActivationMode "OnError"
'OnError is the default, the other option is "OnEveryStep".

call Mbox("Running Qtp in Silent Mode...",2,msgbox4)
'WScript.Echo "Running Qtp in Silent Mode..."

obj.Test.Run 'Runs the script

'wscript.sleep(7000)

call Mbox("QTP script execution completed...",2,msgbox5)
'WScript.Echo "QTP script execution completed..."


obj.Test.Close ' Close the test
call Mbox("Closing Qtp....",2,msgbox6)
'WScript.Echo "Closing Qtp...."
obj.quit 'Close QTP
'Call CloseIE() 'close IE


'#####    endReport    #####
Call EndReport("c:\Framework\Report")
'####     emailReport    #####

WScript.Sleep (9000)
Call CloseIE() 'close IE
'Call CloseExcels()

Set oautoIt = Nothing

http://www.niftyadmin.cn/n/3649281.html

相关文章

[收藏]使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing

使用 WSE 2.0 从 WS-Routing 转移到 WS-Addressing发布日期: 5/202004| 更新日期: 5/20/2004Aaron SkonnardNorthface University适用于:Web Services Enhancements 2.0 for Microsoft.NETWS-Routing 规范WS-Addressing 规范摘要:…

android studio下的sha1值获取

一、首先在app下定义一个文件夹:keystore Build->Generate Signed APK->Create New key store->选择自己项目的keystore下,名字写build->输入密码和其他信息,Alias我写的是build->选择build 二、完成后重复上步骤 Build-&g…

[原创文章] 比较Excel的VBS函数

QTP中Excel的比较 作者:Wally Yu (微博:http://weibo.com/quicktest)最近在SQAForum经常有人提出关于比较两个Excel的值的问题的帖子 例如: http://www.sqaforums.com/showflat.php?Cat0&Number549014&an0&page0#Post549014 htt…

Flutter的HTTP请求

It’s hard to do any sort of development without having to make some form of HTTP request, therefore, we’ll be looking at how to use the http plugin within Flutter. 无需进行某种形式的HTTP请求就很难进行任何类型的开发,因此,我们将研究如…

android上的JAVA8:使用retrolambda

Java8引入了lambda表达式,让许多开发者激动不已,本文介绍如何在Android上使用lambda。 首先下载 java8 sdk ,并且配置完成在 build.gradle 中加入编译的依赖,这会使用retrolambda来编译Java代码 buildscript { //开始加入depend…

react 生命挂钩_简而言之,React useContext挂钩

react 生命挂钩Early February 2019, React introduced Hooks as a way to rewrite your components as simple, more manageable, and classless. useContext is one of the built-in Hooks, giving functional components easy access to your context. But before we dive i…

OkHttp3的使用

一、首先需要Gradle,GitHub的链接:http://square.github.io/okhttp/ compile com.squareup.okhttp3:okhttp:3.9.0 二、测试get方法 /*** 测试get方法*/ Test public void testGet() {//创建OKHttpClient对象OkHttpClient okHttpClient new OkHttpClient();//创建request对象Re…

Android 使用Fragment,ViewPagerIndicator 开发APP项目的主框架

本来准备下载个CSDN的客户端放手机上,没事可以浏览浏览资讯,下载了官方的之后,发现并不能很好的使用。恰好搜到一个大神自己写的csdn的app,下载安装了一下,感觉很不错,也很流畅,基本满足了我们 …