' QF-Test test case [QF-Test Template]
' Created by Quality First Software GmbH, www.qfs.de
' For questions, please contact support@qftest.com
' ====================================================

' ----------------------------------------------------
' Main Test Function
' Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Quality Center
' CurrentTestSet - [OTA COM Library].TestSet.
' CurrentTest - [OTA COM Library].TSTest.
' CurrentRun - [OTA COM Library].Run.
' ----------------------------------------------------
Sub Test_Main(Debug, CurrentTestSet, CurrentTest, CurrentRun)
  ' *** VBScript Limitation ! ***
  ' "On Error Resume Next" statement suppresses run-time script errors.
  ' To handle run-time error in a right way, you need to put "If Err.Number <> 0 Then"
  ' after each line of code that can cause such a run-time error.
  On Error Resume Next

  ' clear output window
  TDOutput.Clear

  ' Test case specific variables.
  ' NOTE: Project specific variables should be defined in the external module.

  ' The path to the project specific VBS module. Please copy the template
  ' from the QF-Test directory to a project specific location.
  pathToModule = "<LOCATION>\\qualitycenter\\qcModule.vbs"

  ' Another way could be to fetch the path from an environment variable, like:
  ' var WshShell = WScript.CreateObject("WScript.Shell");
  ' var WshSysEnv = WshShell.Environment("USER");
  ' pathToModule = WshSysEnv(QFTESTPATH);

  ' The path to single test-case, if this variable is set to
  ' empty the whole test-suite will be executed.
  ' testCase = "CarConfigurator Demo.Options.Modify vehicle"
  testCase = ""

  ' The path of the test-suite.
  ' If you run the test remotely, the file must be accessible on the test-system.
  testSuiteFile = "c:\\Program Files\\qfs\\qftest\\qftest-10.0.2-mobile\\demo\\carconfigSwing\\carconfigSwing_en.qft"

  ' The path to store the run-log after the test-run.
  ' If you run the test remotely, that file can be found on the test-system.
  pathToRunLog = "c:\\TEMP\\carconfigSwing.qrz"

  ' Specify, whether the run-log should be uploaded to the result of the
  ' test-run. Default is 1, which stands for uploading. 0 stands for don't upload.
  'uploadResult = 0

  ' The run-mode of QF-Test "-batch" or "-batch -calldaemon". The default is set
  ' to "-batch".
  'runMode = "-batch"

  ' The additional options for the test-run, e.g. '-J-mX512m' to increase the memory
  ' or '-variable varName=varValue' to set variabes. The default is set to none.
  'runOptions = ""

  ' The timeout in milliseconds, default is infinite.
  'timeout = 10 * 60 * 1000

  ' The path to QF-Test executable, default is the installed qftest.exe.
  ' If you run the test remotely, that file must be accessible on the test-system.
  'pathToQftest = "qftest.exe"

   ' Load external function for launching QF-Test.
   ExecuteGlobal CreateObject("Scripting.FileSystemObject"). _
       OpenTextFile(pathToModule).ReadAll

   ' Function call of external QF-Test module.
   status = executeQFTest (CurrentRun, CStr(testCase), CStr(testSuiteFile), _
      CStr(pathToRunLog), CStr(timeout), CStr(uploadResult), _
        CStr(pathToQftest), CStr(runOptions), cStr(runMode))

   TDOutput.Print "Status of the test: " & CStr(status)

   ' Set the result.
   ' status = 0 stands for successfull run.
   ' status = 1 stands for run with warnings.
   ' status = 2 stands for run with errors.
   ' status = 3 stands for run with exceptions.
   ' All other values stand for errors launching QF-Test.
   If status = 0 or status = 1 Then
      CurrentRun.Status = "Passed"
      CurrentTest.Status = "Passed"
   Else
      CurrentRun.Status = "Failed"
      CurrentTest.Status = "Failed"
   End If

  ' handle run-time errors, standard handling of VAPI-XP scripts.
  If Err.Number <> 0 Then
    TDOutput.Print "Run-time error [" & Err.Number & "] : " & Err.Description
    ' update execution status in "Test" mode
    If Not Debug Then
      CurrentRun.Status = "Failed"
      CurrentTest.Status = "Failed"
    End If
  End If
End Sub
