Test Listeners not Working in CMD mode

Hey there,
I sadly cant get my Test Listeners working if I am in CMD mode.
To be more specific its the After test Listener that I really need.
I take a screenshot of the whole page with Ashot, in UI mode it works fine and flawlessly but unfortinatly not in CMD mode.

OS: Windows 7 64bit Pro Edition
Katalon Version: 6.0.6

CMD Code

Summary

katalon -noSplash -runMode=console -consoleLog -noExit -projectPath=“C:\Pls Funktion\AutomatisierteTests\Automatisierte_Tests_Katalon.prj” -retry=0 -testSuiteCollectionPath=“Test Suites/Alle Tests Browser”

After Test.groovy

Summary

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.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.text.SimpleDateFormat

import javax.imageio.ImageIO

import org.apache.commons.lang.RandomStringUtils
import org.apache.xmlbeans.impl.tool.XSTCTester.TestCaseResult
import org.openqa.selenium.WebDriver

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.configuration.RunConfiguration
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.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

import ru.yandex.qatools.ashot.AShot
import ru.yandex.qatools.ashot.Screenshot
import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider
import ru.yandex.qatools.ashot.shooting.ShootingStrategies

public class AfterTest
{
/**
* Executes after every test case ends.
* @param context related information of the executed test case.
*/
TestRailApiIntegration testRailIntegration = new TestRailApiIntegration()
TestRailHelperMethods testRailHelperMethods = new TestRailHelperMethods(testRailIntegration)

void takeEntirePage  (WebDriver webDriver, File file, Integer timeout = 300){

Screenshot screenshot = new AShot().
coordsProvider(new WebDriverCoordsProvider()).
shootingStrategy(ShootingStrategies.viewportPasting(timeout)).
takeScreenshot(webDriver)
ImageIO.write(screenshot.getImage(), "PNG", file)
}
@AfterTestCase
def executeAfterTestCase(TestCaseContext context)
{
	
	
	Date data = new Date(System.currentTimeMillis())

	SimpleDateFormat formateDate = new SimpleDateFormat ('dd.MM.yyyy HH.mm')
	try {
		
		String testCaseName = context.testCaseId.substring(context.testCaseId.lastIndexOf('/'))
		Path reportDir = Paths.get((GlobalVariable.screenshotpath) + context.testCaseStatus)
		Files.createDirectories(reportDir)
		File pngFile = new File(reportDir.toString(), testCaseName + '_' + formateDate.format(data) + 'Uhr' + '.png')
		WebDriver driver = DriverFactory.getWebDriver()
		
		takeEntirePage(driver, pngFile, 500)
		//WebUI.takeScreenshot((GlobalVariable.screenshotpath) + context.testCaseStatus + '_' + context.testCaseId + '_' + formateDate.format(data) + 'Uhr' + '.png')
	} 
	catch (Exception e) {
		e.printStackTrace()
}
	WebUI.closeBrowser()
}

}

If you need more Information please tell me.

Thanks in Advance

Do you run the cmd version in headless mode? I had some issues with Ashot in headless. I wrote about it on SO:

Apparently, System.getProperty("user.dir") changes when in headless.

If this doesn’t help, please provide more details, as noted here:

2 Likes

I dont think it has anything to do with the Headless mode.
I can run it in Chrome or Headless Chrome just fine, when working in the UI and I even get screenshots

Picture

When I run it in CMD mode, it doesnt matter if I run it in Headless mode or normal mode, it doesnt take picture, it doesnt even say that its executing anything after the test, like the UI does

UI/CMD Comparison

Ok, I am so sorry ^^
Your solution is correct, my path was wrong for Headleasmode you need to specify the Directory
And Thank you so much :slight_smile: