tosca

How do I capture program output in Tosca?


We want to test the output from a command line program that is started by Tosca.

For instance, we're expecting

java -jar myprogram.jar

to stream the following output to System.out:

2016-10-12 09:00:00 INFO [thread-name] MYPROGRAM started
2016-10-12 09:00:01 INFO [thread-name] MYPROGRAM initialisation successful
2016-10-12 09:00:02 INFO [thread-name] MYPROGRAM completed successfully

How can Tosca capture this information? Can it attach to the program's output stream? Or should we push the information to a file and have Tosca look at the file? If so, how do we redirect the output?


Solution

  • Here are two options for you:


    No interaction with the application needed

    If you do not need to interact with the java application (because it just starts, does its thing and closes again; e.g. a little tool or something like that) you can start the application directly with the Tosca Module TBox Start Program, wait for it to exit and stream the output to a file. Here is how your test step would look like:

    wait for exit and capture standard output in a file


    Interaction with the application needed

    If you do need to interact with the application (e.g. because it is the application under test and you want to run automated test steps on it), you obviously can't wait for it to exit. In this case you can create a start.bat file with the following content:

    javaw -jar "C:\path\to\yourjar.jar" > "C:\temp\log.txt"
    

    Then you can also easily use the TBox Start Program module to start the batch file and capture the standard output in the file.

    start batch file


    Hope this helps!