0
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

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

The error message I receive is as follow

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

Note: The Code credits goes to Anish from automationrepository website. I am just trying to build a QTP framework for my test cases using his tutorials and codes

  • Does the VBScript run outside of the batch file, i.e. if you just run the file? – unclemeat Jan 12 '14 at 23:06
  • I get an error about `Set qtpApp = CreateObject("QuickTest.Application")` in VBSEdit, could be the runtime is having trouble getting the error back to you. – Pete Garafano Jan 12 '14 at 23:09
  • @unclemeat Below is the error I get when I run the file Windows Script Host Script: D:\Project\driverScript.vbs Line: 1 Char: 1 Error: Invalid character Code: 800A0408 Source: Microsoft VBScript compilation error – Enthusiastic Learner Jan 12 '14 at 23:20
  • @TheGreatCO Is it trying to location QTP in your machine and failing?If not, Do you have any any idea on how I could go about debugging it? – Enthusiastic Learner Jan 12 '14 at 23:25
  • @EnthusiasticLearner have you tried using something like VBSEdit to see if you get a different (maybe better) error? – Pete Garafano Jan 12 '14 at 23:27
  • 5
    @EnthusiasticLearner Given that the error says there is an `Invalid character code`, There's a chance that the file is using the wrong character encoding. Edit the document in Notepad - click `file > save as` - then make sure the character encoding is set to ANSI. – unclemeat Jan 13 '14 at 00:40
  • Thanks a lot. This worked. Never knew that the encoding was the issue. have some issue with the script itself. Says the file is not found though it is seen in the location. Will look at that. Thanks for your help. Note: I dont find a correct answer notification in your answer so unable to mark that – Enthusiastic Learner Jan 13 '14 at 06:13
  • @TheGreatCO Didn't notice your message until now. I dont have Admin access on the machine where QTP is installed so I wouldn't be able to install it. – Enthusiastic Learner Jan 13 '14 at 20:36

1 Answers1

0

try:

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

to run your vbs in command prompt

bellere
  • 175
  • 1
  • 2
  • 8