Cannot take Screenshot

Good Morning,

I want to take a screenshot at the end of my script, but I got a error when running the test suite. I will post my code and error.

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.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

WebUI.openBrowser('')

WebUI.navigateToUrl('google.com')

WebUI.setText(findTestObject('Navigate/Page /input_Version814_username'), 
'6135276')

WebUI.setEncryptedText(findTestObject('Navigate/Page/input_Version814_password'), 
'vNYlHdvI1qFMHJetop0h1Q==')

WebUI.click(findTestObject('Navigate/Page/button_Version814_btnsubmit'))

WebUI.setText(findTestObject('Navigate/Page/Quick Find_searchQuery'), 
'*45506')

WebUI.click(findTestObject('Navigate/Page/button_Find_quickfindsearch_btn'))

WebUI.waitForElementPresent(findTestObject('Navigate/Page/Woo Yeon'), 
5)

WebUI.click(findTestObject('Navigate/Page/Woo Yeon'))

WebUI.click(findTestObject('Navigate/Page/_icon-k-goto button-highlight'))

WebUI.click(findTestObject('Navigate/Page/a_Timecards'))

WebUI.takeScreenshot('C:\\Users\\61352\\Pictures\\ExpectedBehavior')

Error Message
Elapsed time: 18.033s

Test Cases/Navigate FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Cannot take screenshot
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.TakeScreenshotKeyword.takeScreenshot(TakeScreenshotKeyword.groovy:88)
at com.kms.katalon.core.webui.keyword.builtin.TakeScreenshotKeyword.execute(TakeScreenshotKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.takeScreenshot(WebUiBuiltInKeywords.groovy:2881)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$takeScreenshot$5.call(Unknown Source)
at NavigateToTimecard.run(NavigateToTimecard:42)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1565099938296.run(TempTestCase1565099938296.groovy:21)
Caused by: java.io.IOException: Destination ‘C:\Users\6135276\Pictures\ExpectedBehavior’ exists but is a directory
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1130)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1091)
at com.kms.katalon.core.webui.util.FileUtil.takesScreenshot(FileUtil.java:27)
at com.kms.katalon.core.webui.keyword.builtin.TakeScreenshotKeyword$_takeScreenshot_closure1.doCall(TakeScreenshotKeyword.groovy:89)
at com.kms.katalon.core.webui.keyword.builtin.TakeScreenshotKeyword$_takeScreenshot_closure1.call(TakeScreenshotKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more

Update
Thank you to @HeleneB for helping me find the solution. For my script I got it to fully work with
WebUI.takeScreenshot('C:\\Users\\61352\\Pictures\\ExpectedBehavior\\screenshot.png')

Make sure you add the “Screenshot.png” to give the file a name.

Hi


The parameter have to be a file name

Is this not the correct format? Am I missing something on this line?

Check the doc link, one example is :

WebUI.takeScreenshot('E:\\screenshot.png')

one other

WebUI.takeScreenshot('Test/Demo.png')

File names, not directory

1 Like

I added the
WebUI.takeScreenshot() code to my script, and it on the Screenshot page it mentioned it was going to the temp folder. Do you know where that lives? I’ve been searching through the Katalon folder for it.

So, use example #3 from the doc

  1. You want to take a screenshot of the current browser after logging in and store it current project by using relative paths.

But Temp folder is C:\Users\username\AppData\Local\Temp on Windows

Nevermind I got it! So in order to save a screenshot in a certain directory

Example:
C:\\User\\61352\\Pictures\\ExpectedBehavior\\screenshot.png