Forum Discussion

nastester's avatar
nastester
Regular Contributor
2 years ago

Best way to handle bat execution within TC

I have several use cases where executing a batch script before executing TC tests would be very beneficial. This seems simple but the solutions I've tried have started the bat file and then TC marks...
  • nastester's avatar
    2 years ago

    My solution for this was just writing a custom script that runs in the execution plan:

     

    function runBatchFile(batchFilePath) {

    try {

    var process = Sys.OleObject("WScript.Shell");
    process.Run('cmd.exe /C "' + batchFilePath + '"', 1, true);

    while (process.Status == 0) {
    Delay(100);
    }
    Log.Message("Batch file executed")
    }
    catch (e) {
    Log.Error("An error occurred while running the batch file: " + e.message);
    }
    }

    var batchFilePath = "D:\\SmokeTestCleanup.bat";
    runBatchFile(batchFilePath);