3

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?

Phil Cairns
  • 758
  • 4
  • 15

1 Answers1

6

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!

antipodos
  • 316
  • 1
  • 4
  • While this doesn't allow us to capture the information coming from the program's standard output as it's being emitted by the program, the WaitForExit/StandardOutputFile does allow us to look at what is produced, eventually. So I think we'll go with the first solution, since it looks like Tosca doesn't allow us to do what we want. Thanks very much. – Phil Cairns Oct 18 '16 at 23:57
  • There might be a third option: using the Console Engine. But, honestly speaking, I do not think that would be the most stable solution in your situation. If you are interested, though, here are the details: [Console Engine Docu](https://support.tricentis.com/community/manuals_detail.do?lang=en&version=9.3.0&url=console_engine/installation.htm) – antipodos Oct 19 '16 at 06:34
  • 1
    We did look at that to start with, but we're checking a lot of data being produced by loggers, so it's not at all a fixed position sort of a thing. Getting the log file at the end of the run is sufficient. – Phil Cairns Oct 19 '16 at 21:45