Forum Discussion

fidzah's avatar
fidzah
Occasional Contributor
6 years ago

Is it possible to pass custom properties value to command prompt?

1) I have a TestCaseA that store some value :

Name: ID

Value: 10

2) I need one batch file able to pick up the ID that has been store to SOAPUI Custom Properties.

3) Run the batch file

 

Reason: The batch file will run the TestCaseA multiple times and in the batch file, there will be some action where the command will store file into C and transfer file.

 

Question: Is it possible groovy script able to do the same?

 

 

  • I finally made a decision to store the value to a file on C:\temp and batch file picks up the value and run the batch based on that ID

     

    import groovy.io.FileType
    project = testRunner.testCase.testSuite.project ;
    tcase = project.testSuites["TSuiteName"].testCases["TCaseName"] ;
    def idValue

    // Get a project property
    def projectProperty = tcase.getPropertyValue( "ID" )
    log.info(projectProperty)

    def fileName = "test.txt"

    // Defining a file handler/pointer to handle the file.
    def inputFile = new File("C:\\Temp\\"+fileName)

    inputFile.write(projectProperty)

    //this will solve your issue if the folder name has space
    //on command prompt, use this command to check
    //dir /X ~1 c:\
    Process proc=Runtime.getRuntime().exec("cmd /c start c:\\PROGRA~2\\test.bat");
    proc.waitFor()

    NOTE: for the batch to picks up the value from text, add this to batch file
    Echo OFF

    set /p Id=<"C:\\Temp\\test.txt"
    echo %Id%
    echo "This is ID" %Id%

  • fidzah's avatar
    fidzah
    Occasional Contributor

    I finally made a decision to store the value to a file on C:\temp and batch file picks up the value and run the batch based on that ID

     

    import groovy.io.FileType
    project = testRunner.testCase.testSuite.project ;
    tcase = project.testSuites["TSuiteName"].testCases["TCaseName"] ;
    def idValue

    // Get a project property
    def projectProperty = tcase.getPropertyValue( "ID" )
    log.info(projectProperty)

    def fileName = "test.txt"

    // Defining a file handler/pointer to handle the file.
    def inputFile = new File("C:\\Temp\\"+fileName)

    inputFile.write(projectProperty)

    //this will solve your issue if the folder name has space
    //on command prompt, use this command to check
    //dir /X ~1 c:\
    Process proc=Runtime.getRuntime().exec("cmd /c start c:\\PROGRA~2\\test.bat");
    proc.waitFor()

    NOTE: for the batch to picks up the value from text, add this to batch file
    Echo OFF

    set /p Id=<"C:\\Temp\\test.txt"
    echo %Id%
    echo "This is ID" %Id%