Forum Discussion

Sirisha2020's avatar
Sirisha2020
Contributor
4 years ago
Solved

i want to save REST Response on test case level to a notepad or to any other file using soap ui

  • Sirisha2020 :

     

    Hope below code will help you out in saving response to txt file, it will work in tear down script of test case:

     

    import groovy.json.JsonOutput;
    
    testCase.testStepList.each{
    	type = it.config.type
    	name = it.name
    	response = it.getPropertyValue("Response")
    	if(type == "restrequest"){
    		def pretty = JsonOutput.prettyPrint(response);
    		def responseFile="F://testing//"+name.toString()+"__response.txt";
    		def rsfile = new File(responseFile);
    		rsfile.write(pretty, "UTF-8");
    	}
    }

     

3 Replies

  • Sirisha2020 :

     

    Hope below code will help you out in saving response to txt file, it will work in tear down script of test case:

     

    import groovy.json.JsonOutput;
    
    testCase.testStepList.each{
    	type = it.config.type
    	name = it.name
    	response = it.getPropertyValue("Response")
    	if(type == "restrequest"){
    		def pretty = JsonOutput.prettyPrint(response);
    		def responseFile="F://testing//"+name.toString()+"__response.txt";
    		def rsfile = new File(responseFile);
    		rsfile.write(pretty, "UTF-8");
    	}
    }

     

      • Sirisha2020's avatar
        Sirisha2020
        Contributor

        Hi Himanshu,

         

        i am able to write the response to a document. But i am trying to update the request to a separate word document it is not saving the request along with the time stamp to the word document. Please find the code as below :

         

        def rawRequest = JsonOutput.prettyPrint(request);
        def file1 = new File("C://Users//appu//Desktop//proj//groovy1.doc");
        file1.write (rawRequest,"UTF-8");

        I tried various ways to get the request but no luck. Also i want to save request and response along with time stamp.

         

        Thanks.