Want to refer to the date and time when a TestSuite was invoked in order to organize Screenshots

**OS : **Windows 7

Katalon Studio Version : 5.5.0.1

## Katalon Studio logs:

I don’t think log is necessary for this case.

## Environment (for Web testing)

Browser : Firefox 52

## Environment (for Mobile testing)

N/A

## Problem to solve

I want take screenshots of every pages of my Web site regularly (3 times a day for example) and store the images into a well-organized file tree. I would invoke a Katalon TestSuite from commandline driven by Jenkins. There could be hundres or thousands of image files, I want to make sub directory named yyyyMMdd_hhmmss format.

Katalon Studio creates Report for TestSuites, and the directory name of Report is exactly in the format of yyyyMMdd_hhmmss format.

## Actual Behavior -

Katalon Studio’s WebUI.takeScreenshot enables me to specify the path of image just as I want.

https://docs.katalon.com/display/KD/[WebUI]+Take+Screenshot

However there seems to be no way to refer to the date and time when TestSuite (or TestCase) was stated.

**## Expected Behavior -
**
I want to refer to the date and time when a TestSuite was started. Provided with them, I would make sub-directories in the yyyyMMdd_hhmmdd format.

## Screenshots / Videos

see the attached image. I tried to give you an idea what i want to accomplish.

want_to_refer_to_date_and_time_when_TestSuite_envoked.PNG

1 Like

Hi there,

You can actually use Test Listeners or Setup/Teardown in Test Suite to help you with this. Just utilize BeforeTestSuite or BeforeTestCase trigger, and you can achieve this easier

Setup/Teardown in Test Suite – https://docs.katalon.com/pages/viewpage.action?pageId=12419091 – Ah, I see. I will try.

1 Like

I added @SetUp like this. This worked fine. I could make a directory such as C:\Users\username\Katakon_Screenshots\testsuite_name\20170302_132032
This is exactly what I wanted. Thank you very much.

/**
 * Setup test suite environment.
 */
@SetUp(skipped = false) 
def setUp() {
  // record the DataTime when the TestSuite started
  LocalDateTime now = LocalDateTime.now()
  GlobalVariable.G_TestSuite_started_at = 
      DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss").format(now)
  // create a directory where we store screenshots
  if (GlobalVariable.G_Screenshots_baseDir != null &&
      GlobalVariable.G_Screenshots_baseDir.length() > 0) {
    String path = GlobalVariable.G_Screenshots_baseDir + 
    File.separator + 
    "36Tokushima" + File.separator + 
    GlobalVariable.G_TestSuite_started_at ;
  Path outputDir = Paths.get(path)
  try {
    Files.createDirectories(outputDir)
  } catch (IOException e) {
    System.err.println(e)
  }

1 Like

Hi Kazurayam

Could you please post the import statements so I can learn about the libs and APIs you are using?

Thanks!

Russ

This is what I have done:

...
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.annotation.SetUp
import com.kms.katalon.core.annotation.SetupTestCase
import com.kms.katalon.core.annotation.TearDown
import com.kms.katalon.core.annotation.TearDownTestCase
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
/**
 * Setup test suite environment.
 */
@SetUp(skipped = false) // Please change skipped to be false to activate this method.
def setUp() {
  // record the DataTime when TestSuite started
  LocalDateTime now = LocalDateTime.now()
  GlobalVariable.G_TestSuite_started_at = 
    DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss").format(now)
  // create a directory to store screenshots
  if (GlobalVariable.G_Screenshots_baseDir != null &&
    GlobalVariable.G_Screenshots_baseDir.length() > 0) {
    String dirStr = GlobalVariable.G_Screenshots_baseDir + File.separator + 
      "36Tokushima" + File.separator + 
      GlobalVariable.G_TestSuite_started_at ;
    Path outputDir = Paths.get(dirStr)
    try {
      Files.createDirectories(outputDir)
      GlobalVariable.G_Screenshots_outputDir = dirStr
    } catch (IOException e) {
      System.err.println(e)
    }
  }
}

In other portions of my TestCases, I will refer to GlobalVariable.G_Screenshots_outputDir and resolve paths of the files into which WebUI.takeScreenshot() saves images.

1 Like

Many thanks, Kazurayam!