Hello Katalon Users, Experts and Automation-Friends
I try to give you short frame which i´m currently working on.
In one of our test cases we have manual interactions between two steps. You need to remember the ID from the UI, open an XML-Template, add the ID to the “place holder”, save it with a new name and copy it to a specific folder.
For this test case my idea was to handover the ID as an variable to an Windows-Batch File, which can replace the value from the XML-Template, create an new file and move/copy it to the specific folder.
The Batch file (call, parameter and move):
call TransformContentviaBatch.bat VAR1 VAR3
move Output.xml "C:\Users\Demo\Export.xml"
The Batch file (for transforming):
@echo off
setlocal enabledelayedexpansion
set INTEXTFILE=Input.xml
set OUTTEXTFILE=Output.xml
set SEARCHTEXT=%1
set REPLACETEXT=%2
for /f "tokens=1,* delims=¶" %%A in ( '"findstr /n ^^ %INTEXTFILE%"') do (
SET string=%%A
for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
if "!string!" == "" (
echo.>>%OUTTEXTFILE%
) else (
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified! >> %OUTTEXTFILE%
)
)
I really try everything to execute these batch files or any batch file:
(https://docs.katalon.com/katalon-studio/docs/execute-windows-commands.html)
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
import org.codehaus.groovy.runtime.StringGroovyMethods
import com.kms.katalon.core.configuration.RunConfiguration
/**
* Execute a batch file situated in the KS project directory.
* @param batchFile (String) e.g. "myfile.bat"
*/
static void runBatchFile(String batchFile) {
String bf = RunConfiguration.getProjectDir() + '/' + batchFile
WebUI.comment("Running batch file: " + bf)
Runtime.runtime.exec(bf)
}
runBatchFile "test.bat"
Katalon result:
11-27-2018 10:56:36 PM - [START] - Start Test Case : Test Cases/PTS_INST/General/CopyJob2_test
11-27-2018 10:56:36 PM - [INFO] - Evaluating variables for test case
11-27-2018 10:56:36 PM - [START] - Start action : Statement - Script1543355783544.runBatchFile(test.bat)
11-27-2018 10:56:36 PM - [END] - End action : Statement - Script1543355783544.runBatchFile(test.bat)
11-27-2018 10:56:36 PM - [START] - Start action : Statement - bf = com.kms.katalon.core.configuration.RunConfiguration.getProjectDir() + "/" + batchFile
11-27-2018 10:56:36 PM - [END] - End action : Statement - bf = com.kms.katalon.core.configuration.RunConfiguration.getProjectDir() + "/" + batchFile
11-27-2018 10:56:36 PM - [START] - Start action : comment
11-27-2018 10:56:36 PM - [INFO] - Running batch file: C:/Users/Demo Laptop/Katalon Studio/DemoLaptop/test.bat
11-27-2018 10:56:36 PM - [END] - End action : comment
11-27-2018 10:56:36 PM - [START] - Start action : Statement - runtime.exec(bf)
11-27-2018 10:56:36 PM - [END] - End action : Statement - runtime.exec(bf)
11-27-2018 10:56:36 PM - [PASSED] - Test Cases/PTS_INST/General/CopyJob2_test
11-27-2018 10:56:36 PM - [END] - End Test Case : Test Cases/PTS_INST/General/CopyJob2_test
No error or something happens. This test.bat is stored directly inside the project directory and got the following content:
echo off
cls
echo.
echo ERFOLG !!!!
echo.
pause
I open to any solution, inside the code, working batch file etc.
Thanks for reading my long story & Thanks for support
Christian