free seo tool
Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Capture soapUI Logs to File

In this Groovy Script example, lets see how can we capture the soapUI logs and save it into a file. At the bottom of soapUI, you might have noticed  different tabs named soapUI log, http log, jetty log, error log, wsrm log, memory log and script log. Each tab will have the logs based on log category. For example, if you are invoking a Web Service request/ response, you will be able to see the web service request and response with the http headers under http tab. Same way if you have groovy script to on your soapUI test steps and if those groovy scripts are printing any dynamic values while test execution, you might also see that in the tab "script log". Lets see the below groovy script to capture the logs and save it into a text file.

//The below groovy script step is to capture the soapUI log area.
// "soapUI log" can be replaced with http log, jetty log, script log, error log etc based on the need.
def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "soapUI log" );
//Below two lines of groovy script is to get the project directory, we will be saving the soapUI log contents on a file in that directory.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 
def projectPath = groovyUtils.projectPath 
def logFile = new File(projectPath + "\\soapUI-Logs-to-file.txt")
//This is the first line in the soapUI log file.
logFile.write("soapUI Logs In a file.\r\n")
   if( logArea !=null )
   {
      def model = logArea.model
      if( model.size > 0 )            
         for( c in 0..(model.size-1) )         
           logFile.append(model.getElementAt( c ))       
      
   }


Read more »

Write soapUI Request & Response to text File using Groovy

Below Groovy Script is an example of how to write the requests and responses available in a test case to a text file. 

In this sample groovy script, we are getting an object of all the test requests available in the test case. Then by using a "each" loop we capture all the request and response XMLs. By using the file creation groovy script, we create two files to write the SOAP request and response. This script will also name the file using the current date and time. This is achieved by using the Groovy Script to capture the current date and time. 


//Define the object for the collection of requests in the soapUI test case
def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep )


//Groovy Script to loop through each requests in the test case.
soapuiRequests.each{
//Creating file name using current date and time
Date startTime = new Date();
def cur_Time = startTime.getMonth() + "_" + startTime.getDate();
cur_Time = cur_Time + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds()
def fileName = it.name + "_" + cur_Time

def inputFileRequest = new File("C:\\"+ "Request_" + fileName+".txt")
def inputFileResponse = new File("C:\\"+ "Response_" + fileName+".txt")
//Writing soapUI response to the file
inputFileResponse.write(context.testCase.getTestStepByName(it.name).getProperty("response").value)
//Writing soapUI request to the file
inputFileRequest.write(context.testCase.getTestStepByName(it.name).getProperty("request").value)
}

Read more »

How to Create, Write and Append a File using Groovy Script

The below code will explain how to create a file using groovy script in soapUI Groovy script editor.//Define the name of the file.
def fileName = "test1.txt"
// Defining a file handler/pointer to handle the file.
def inputFile = new File("C:\\"+fileName)
// Check if a file with same name exisits in the folder.
if(inputFile.exists())
{
// if a file exisits then it will print the message to the log.
log.info("A file named " + fileName + " already exisits in the same folder")
}
else
{
//else it will create a file and write the text "Hello World !"
inputFile.write("Hello World !")


}


If we don't use inputFile.exists() and check if the file is there or not, it will overwrite the contents of the file and recreate a new one with same name.
If we want to append text to an existing file, replace "inputFile.write("Hello World !")" with "inputFile.append("Hello World !")".

Software Testing Tutorials

Read more »