Forum Discussion

Red's avatar
Red
Occasional Contributor
4 years ago

SOAPUI Groovy to run .exe files

Hi Team,

I wanted to run exe file as part of my SOAPUI test case execution. And i'm trying to figure out a way to run exe file and capture response in the groovy script from SOAPUI.
Can someone provide a lead to do this? 

  • krogold's avatar
    krogold
    Regular Contributor

    Hello,

    I did something like this through the use of batch files (as they are launched on a remote simulator PC), though I did not launched the .exe directly.

    I describe it below, hoping it can help :

     

    For instance, I have a .bat file that launches simulator exe as follows:

     

    start %2\\WaterMeter -KNXAddressIndex 2/0/22 -KNXAddressFlow 2/0/23 -IPserver %1 -DeviceName \"Water1\" -RefresRate 10 -PulseMode 4
    ping 1.1.1.1 -n 1 -w 10 > nul

     

    in that line the exe name is WaterMeter.exe, the rest concerns launching parameters. the %1 and %2 data are batch parameters that are set in the command line launched in the groovy step.

    The groovy step is the following (the interesting part is at the end) :

     

    // launch the required simulators for non reg execution 
    
    // use domo-simu server
    def simulator_ip = context.expand( '${#Project#DOMO-SIMU_address}' )
    def simulator_path = context.expand( '${#Project#simu_tools_path}' )
    def simulator_name = context.expand( '${#TestCase#simulator_name}' )
    
    
    switch(simulator_name)
    {
        case "generic":
            file = "launch_generic_simu.bat"
            break;
        case "hot_water":
            file = "launch_hot_water_simu.bat"
            break;
        case "electricity":
            file = "launch_electric_meters_simu.bat"
            break;    
        case "gas":
            file = "launch_gas_meters_simu.bat"
            break;    
        case "water":
            file = "launch_water_meters_simu.bat"
            break;    
        case "ventilation":
            file = "launch_ventilation_simu.bat"
            break;    
        case "close":
        		file = "closeAll.bat"
        		break;
        case "All" :
        default :
            file = "launch_simulators.bat" // launch all available simulators
            break;
         
    }
    
    
    cmd = simulator_path + "\\$file " + simulator_ip + " " + simulator_path
    log.info "cmd = $cmd"
    process = Runtime.runtime.exec(cmd)
    
    Thread.sleep(2000)

     

     

    This process allows me to send my simulator interfaces.

    command parameters :

    - Simulator_path+file is the path where the batch file is.

    - simulator_ip is specific to my case as the server that pilots the simulator interface is on a remote PC

    - the last simulator_path data is, if I remember well, the location from where you launch the .exe

     

    You will probably not need to proceed this way. Setting your paht/appli.exe in cmd then launch the process will be sufficient.

    I don't deal with return data, though the 'process' variable should help you to get some information.

    • Red's avatar
      Red
      Occasional Contributor

      Thanks krogold for your response. For now I'm using below to run the .exe with the help of .bat file. It is successfully launching the .exe file. But, the issue here is I'm not getting complete response in the groovy. receiving only a part of response (even after changing no.of characters in the char buffer) .
      Is it possible to get complete response? (I'm not sure it is possible or not but, I'm looking response something like which we get in any of the IDE)


      import java.io.InputStreamReader

      ProcessBuilder pb = new ProcessBuilder("cmd","/c","C:\\dummy.bat")
      pb.redirectErrorStream(true)
      Process p = pb.start()
      InputStreamReader isr = new InputStreamReader(p.inputStream)
      char[] cbuf = new char[1024]; //read 1024 characters, increse to higher amount if necessary
      isr.read(cbuf);
      log.info(new String(cbuf))

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        Have you tried the name of exe file in place of 3rd argument? If not try it out.