How to take a full-page screenshot of mobile & pc

same as title

1 Like

Hi

I have googled around and finally could take a fullpage screenshot for my project.
You need to create a custom keyword “ScreenshotHelper” under the project.
After that copy and paste below code.

Change the file path to a folder path you want to save the screenshot.

===================================================================

package screen

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 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

public class ScreenshotHelper {

@Keyword

public void takeWebElementScreenshot() {

WebDriver driver = DriverFactory.getWebDriver();

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);

ImageIO.write(screenshot.getImage(), “PNG”, new File(“C:\\\Users\\\UserName\\\Downloads\\\test.png”))

}

}

2 Likes

I happened to post a similar theme:

-----

update at 2018/11/10

The following post proposes extended version of my custom keyword com.kazurayam.ksbackyard.ScreenshotDriver

Hi, I have tested this solution and it worked. Thanks!

A question to someone good coding.

Related to the storage:
ImageIO.write(screenshot.getImage(), “PNG”, new File(“C:\\\Users\\\UserName\\\Downloads\\\test.png”))

Can someone update it so that the file will be saved in the screenshot folder of each test case, like it is being done with the built-in keyword TakeScreenshot?

As it is now no matter in which test case you use the custom define ScreenshotHelper with Ashot, it will always create the same file name in the same folder, so by running this several times in different test cases it will overwrite the file…

Does someone accept the coding challenge? :slight_smile:

Thanks in advance!

Alexander,

Please have a look at the following post and try my Materials library.

An introduction to the library is here:

together with my custom keyword com.kazurayam.ksbackyard.ScreenshotDriver which wraps the aShot library

The Materials library enables you to save screenshots in the following folder structure.

${projectDir}/Materials/${testSuiteName}/${testSuiteTimestamp}/${testCaseName}/${subdirs}/${fileName}

The following picture shows an example.

I believe the Materials will solve your problem.

TS07_tree.png

I want to save screen shot on log folder,
can you tell me how to do it ?

What is “log folder”?

Yeah, I mean when I take a full screen short,
I want to save to folder test suite reports.

" The report will be named with following the naming convention: YYYYMMDD_HHmmss , which is the datetime when the test suite starts its execution."
link: https://docs.katalon.com/katalon-studio/tutorials/viewing_test_suite_reports.html#report-overview

I want to save in that folder :slight_smile:

Please refer below tutorial

You can find the folder path using Runconfiguration.getReportFolder().
See