Forum Discussion

AndrewGeorgiou's avatar
AndrewGeorgiou
Occasional Visitor
10 months ago
Solved

How to save to a file

I am using SoapUO 5.7.0 and i have a Execute query to get data.

 

I get the data but i need to automate this through a windows schedule and have it run to create a file for me on a daily basis.

 

Have any one done that where you can run it and create a file?

 

Any advice it would be greatly apprecited.

 

Thank you,

Andrew

  • SoapUI installation also provides command line tools(%SOAPUI_HOME%/bin/testrunner.bat) to execute the SoapUI project / test suite / test case. Please check here

     

    And windows scheduler task allows to run the commands. So you are good.

     

    Coming to the actual problem, i think, saving the response xml of jdbc test step is easily possible with below script.

     

    Add this script as Script Assertion to the JDBC Request step itself: And provide the directory for path variable in the script.

    //Check if there is response
    assert context.request, "Request is empty or null"
    
    //Update the below value
    def path = '/directory/path/to/store/responses'
    def name_prefix = java.time.LocalDate.now().toString()
    
    //Save the contents to a file
    def saveToFile(file, content) {
        if (!file.parentFile.exists()) {
             file.parentFile.mkdirs()
             log.info "Directory did not exist, created"
        }
        file.write(content) 
        assert file.exists(), "${file.name} not created"
    }
    
    def f = new File("${path}/${name_prefix}_Response.xml")
    saveToFile(f, context.response)

     

    Try to execute the SoapUI project using command line and ensure response is saved before putting that into windows scheduler.

    NOTE: the above script saves the response with today's date as prefix in its file name.

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    SoapUI installation also provides command line tools(%SOAPUI_HOME%/bin/testrunner.bat) to execute the SoapUI project / test suite / test case. Please check here

     

    And windows scheduler task allows to run the commands. So you are good.

     

    Coming to the actual problem, i think, saving the response xml of jdbc test step is easily possible with below script.

     

    Add this script as Script Assertion to the JDBC Request step itself: And provide the directory for path variable in the script.

    //Check if there is response
    assert context.request, "Request is empty or null"
    
    //Update the below value
    def path = '/directory/path/to/store/responses'
    def name_prefix = java.time.LocalDate.now().toString()
    
    //Save the contents to a file
    def saveToFile(file, content) {
        if (!file.parentFile.exists()) {
             file.parentFile.mkdirs()
             log.info "Directory did not exist, created"
        }
        file.write(content) 
        assert file.exists(), "${file.name} not created"
    }
    
    def f = new File("${path}/${name_prefix}_Response.xml")
    saveToFile(f, context.response)

     

    Try to execute the SoapUI project using command line and ensure response is saved before putting that into windows scheduler.

    NOTE: the above script saves the response with today's date as prefix in its file name.