Screenshot of entire web page with Ashot. Is it possible to store it in its own Test Case folder?

Hi,

Since using the inbuild key Take Screenshot is not taking the screenshot of the entire web page but mostly the viewport or portion of the web page without scrolling I am looking a way to do a custom-built key. Thanks to this wonderful forum I found a way creating a custom keyword which uses Ashot and look like this:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import java.awt.image.BufferedImage
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
import internal.GlobalVariable
import java.text.SimpleDateFormat
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import ru.yandex.qatools.ashot.AShot
import ru.yandex.qatools.ashot.Screenshot
import ru.yandex.qatools.ashot.shooting.ShootingStrategies
import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory
import javax.imageio.ImageIO as ImageIO
import org.apache.commons.io.FileUtils
import com.kms.katalon.core.configuration.RunConfiguration
public class ScreenshotHelper {
	@Keyword
	public void takeWebElementScreenshot() {
		WebDriver driver = DriverFactory.getWebDriver();
		String title = 'Screenshot'
		String Folder = 'Fullscreenshot'
		Path tmpDir = Paths.get(RunConfiguration.getProjectDir()).resolve("tmp/${Folder}")
		if (Files.exists(tmpDir)) {
			FileUtils.cleanDirectory(tmpDir.toFile())
		}
		Files.createDirectories(tmpDir)
		Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
		Path out = tmpDir.resolve("${title}.png")
		ImageIO.write(screenshot.getImage(), "PNG", out.toFile())
	}
}

As you can see, from where I marked in Bold, the file will be added to The project directory, and 2 sub folders. As you will notice, then everytime I use the custom key in a test case, the new screenshot will overwritte the previous one.

Is there a way that this could be added to the TestCase folder for which I am running the test case instead?

This is being done already by the inbuild key “Take Screenshot” which is saving the screenshots in a Test case folder:

C:\Users\usename\AppData\Local\Temp\Katalon\Test Cases*TestCasename* \Screenshot\YYMMDD_xxxx

_I would like to save the full page screenshot done by Ashot in the same place as Take Screenshot or at least under the TestCasename folder. _

Could someone give me some hint? I am a beginner about coding.

Thanks in advance!

Alexander,

Please find my comment at

I believe my Materials-x.x.x.jar library can solve your problem.