VBS文件未通过cmd提示符运行 [英] VBS file doesn't run through cmd prompt

查看:153
本文介绍了VBS文件未通过cmd提示符运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim sTestCaseFolder, strScriptPath, sQTPResultsPath, sQTPResultsPathOrig
sBatchSheetPath = "D:\Project\Driver Script\Batch.xls"
    sTestCaseFolder = "D:\Project\"
    sQTPResultsPathOrig = "D:\Project\Result\"

'========== Create an object to access QTP's objects, methods and properties ==========
Set qtpApp = CreateObject("QuickTest.Application")

'Open QTP if it is already not open
If qtpApp.launched <> True Then
 qtpApp.Launch
End If

qtpApp.Visible = True

'========== Set the run options for QTP ==========
qtpApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtpApp.Options.Run.RunMode = "Fast"

'Set ViewResults property to false. This is because if you run many test cases in batch, you would not want QTP to open a separate result window for each of them
qtpApp.Options.Run.ViewResults = False

' ========== Read test cases from batch excel sheet ==========
Set xl_Batch = CreateObject("Excel.Application")
Set wb_Batch = xl_Batch.WorkBooks.Open(sBatchSheetPath)

'Loop through all the Rows
'1st row contains Execute button, 2nd row is header and the test case list starts from 3rd row. So, For loop is started from 3rd row
For iR = 3 to 1000

 'Get the value from the Execute column
 If xl_Batch.Cells(iR, 1).Value = "Yes" Then

 'Get Test Case Name
 sTestCaseName = xl_Batch.Cells(iR, 2).Value

 'Get the location where the test case is stored
 strScriptPath = sTestCaseFolder & sTestCaseName

 'Open the Test Case in Read-Only mode
 qtpApp.Open strScriptPath, True
 WScript.Sleep 2000

 'Create an object of type QTP Test
 Set qtpTest = qtpApp.Test

 'Instruct QTP to perform next step when error occurs
 qtpTest.Settings.Run.OnError = "NextStep"

 'Create the Run Results Options object
 Set qtpResult = CreateObject("QuickTest.RunResultsOptions")

 'Set the results location. This result refers to the QTP result
 sQTPResultsPath = sQTPResultsPathOrig
 sQTPResultsPath = sQTPResultsPath & sTestCaseName
 qtpResult.ResultsLocation = sQTPResultsPath

 'Run the test. The result will automatically be stored in the location set by you
 WScript.Sleep 2000
 qtpTest.Run qtpResult

 ElseIf xl_Batch.Cells(iR, 1).Value = "No" Then
 'Do nothing. You don't have to execute the test cases marked as No

 ElseIf xl_Batch.Cells(iR, 1).Value = "" Then
 'Blank value means that the list of test cases has finished
 'So you can exit the for loop
 Exit For

 End If

Next

我已将以上代码保存在Vbs文件中,并且尝试使用以下代码通过cmd提示符执行该文件

I have the above code saved in a Vbs File and I am trying to execute this file through cmd prompt using the code below

cscript Test.vbs

我收到的错误消息如下

D:\ Project \ Driver Script \ DriverScript.vbs(1,1)Microsoft VBScript编译错误:无效字符

D:\Project\Driver Script\DriverScript.vbs(1, 1) Microsoft VBScript compilation error: Invalid character

我不太确定上面的代码在第一行出现了什么问题,该错误似乎指向了什么地方.感谢您的帮助

I am not quite sure whats wrong with above code with respect to very first line what the error seems to be pointing at. Any help is appreciated

注意:该代码积分来自自动化存储库网站上的Anish.我只是想使用他的教程和代码为我的测试用例构建一个QTP框架

推荐答案

尝试:

cscript.exe /NoLogo "path\cscript Test.vbs"

在命令提示符下运行vbs

to run your vbs in command prompt

这篇关于VBS文件未通过cmd提示符运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆