Ask a Question

Best way to handle bat execution within TC

SOLVED
nastester
Regular Contributor

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 the task as completed prompting the first test in the suite to start before the bat is actually done executing. 

Does anyone have any solutions for this? 

Can I pass in some command line parameter in TestedApps to keep the bat open until it finishes? 

7 REPLIES 7
rraghvani
Champion Level 3

Just for clarification, are you running a batch file from TC in TestedApps? What does your batch file do?

nastester
Regular Contributor

That was one method I tried. I also tried running from a script. The script method wasn't very clean and also wasn't working for other coworkers/stopped working for me. I thought maybe the TestedApps approach would be better.

The bat does a bunch of things but namely runs SQL commands and ReadyAPI dataloads into the test env

rraghvani
Champion Level 3

Within your batch file, you need something like,

 

START /B /WAIT

 

Where, /B to stay in the same process and /WAIT to wait until the command has finished.

nastester
Regular Contributor

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);

rraghvani
Champion Level 3

Did you try the solution that I provided?

nastester
Regular Contributor

Couldn't get it to work

rraghvani
Champion Level 3

You should have mentioned it at the time 🙄

cancel
Showing results for 
Search instead for 
Did you mean: