Capture console output in TestNG?

I use TestNG + ReportNG for the wiki instructions in gradle (I fixed it in the cookbook since the default example did not work out of me).

I would like to somehow capture console output in TestNG. Is it possible?

Thank. Misha

+3
source share
1 answer

Ok, I still don't know how to do this, but I just redirected the standard output and the error:

/**
 * Redirect standard output and error to appropriate files
 */
public void redirectStandardOutputAndErrorToFiles(className) {
  def outFile=new   File(System.getProperty("java.io.tmpdir")+File.separator+className+".out.log")
  if (outFile.exists()) {
    outFile.delete()
  }
  def errFile=new File(System.getProperty("java.io.tmpdir")+File.separator+className+".err.log")
  if (errFile.exists()) {
    errFile.delete()
  }
  def out=new PrintStream(new FileOutputStream(outFile))
  def err=new PrintStream(new FileOutputStream(errFile))
  System.setOut(out)
  System.setErr(err)
}
+3
source

Source: https://habr.com/ru/post/1749699/


All Articles