When you take a screenshot using WebUI.takeScreenshot(filepath), you need to specify where to save the image. How do you resolve the location of the screenshot files? Katalon Studio provides a way to take screenshot but it does not support locating the files created during a test case run. Here I find a feature to be developed.
My idea is to save an image in the following location:
<project>/Materials/TestSuiteName/yyyyMMdd_hhmmss/TestCaseName/encodedURIstring.png
This location should be resolved by algorithm because I can not hard-code the path manually everytime I run test cases. Therefore I have developed a Groovy Library which resolves the file path to save screenshots.
Just to give you an idea, here I copy&pasted an example test case which makes use of my new magic:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObjectimport java.nio.file.Pathimport com.kazurayam.material.MaterialRepositoryimport com.kms.katalon.core.model.FailureHandling as FailureHandlingimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIimport internal.GlobalVariable as GlobalVariable/** * Take a screenshot of a Web page, save PNG file to make it a Material */WebUI.openBrowser('')WebUI.navigateToUrl('http://demoaut.katalon.com/')WebUI.maximizeWindow()WebUI.verifyElementPresent(findTestObject('Page_CURA Healthcare Service/a_Make Appointment'), 10, FailureHandling.STOP_ON_FAILURE)MaterialRepository mr = (MaterialRepository)GlobalVariable.MATERIAL_REPOSITORYassert mr != nullPath pngFile = mr.resolveScreenshotMaterialPath(GlobalVariable.CURRENT_TESTCASE_ID, WebUI.getUrl())WebUI.takeScreenshot(pngFile.toString())WebUI.comment("saved a screenshot into ${pngFile.toString()}")Path pngFileOnceMore = mr.resolveScreenshotMaterialPath(GlobalVariable.CURRENT_TESTCASE_ID, WebUI.getUrl())WebUI.takeScreenshot(pngFileOnceMore.toString())WebUI.comment("saved a screenshot into ${pngFileOnceMore.toString()}")WebUI.closeBrowser()
Provided with the instance of com.kazurayam.material.MaterialRepository, all of the PNG files are stored in a pre-designed location. The class implements a set of methods to traverse the contents. Using the traversal methods, an Indexer class generates the index.html.
---------------------------------------
Concerning your question
how to make the index.html file which will link to … test summary?
I know that the test result info is stored here:
/Reports/TestSuiteName/yyyyMMdd_hhmmss/JUnit_Report.xml
I know where I can find the information, so my index.html can easily refer to the test summary.