cancel
Showing results for 
Search instead for 
Did you mean: 

To Write the "status response" from a REST" in a file,status different to "HTTP/1.0 200 OK".

SOLVED
Highlighted
Occasional Contributor

To Write the "status response" from a REST" in a file,status different to "HTTP/1.0 200 OK".

Hi

I have a script that writes me in an Excel Sheet the "status" response  from a REST, for correct cases, but not the status different to "HTTP/1.0 200 OK".

 

I would like to write this errors. What will I do?

 

 

import com.eviware.soapui.support.GroovyUtils.*;
import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.util.*
import groovy.json.JsonSlurper.*

int fil = testRunner.testCase.getPropertyValue("Fila").toInteger();
int cel = testRunner.testCase.getPropertyValue("Col").toInteger();
cel++;

def httpResponseHeaders = context.testCase.testSteps["PuntoVenta"].testRequest.response.responseHeaders


def httpStatus = httpResponseHeaders["#status#"]
log.info httpStatus


def fs=new FileInputStream ("D:\\prueba\\Salida.xlsx")
Workbook wb = WorkbookFactory.create(fs)
def fil1 = wb.getSheet("Hoja1").getLastRowNum()+1

def hora = new Date().format("yyyy-MM-dd'T'HH:mm:ss SSS")
log.info hora
def row = wb.getSheet("Hoja1").createRow(fil1)

row.createCell(0).setCellValue(new Date().toString())
row.createCell(1).setCellValue(httpStatus)
fs.close();

def fo = new FileOutputStream ("D:\\prueba\\Salida.xlsx");
wb.write(fo);
fo.close();


if(fil<5)
{
fil++;
testRunner.testCase.setPropertyValue("Fila",fil.toString());
testRunner.gotoStepByName("Script");
// Se realiza el bucle para que vaya al script fila.
}
else
{
fil=0;
cel=0;
testRunner.testCase.setPropertyValue("Fila",fil.toString());
testRunner.testCase.setPropertyValue("Col",cel.toString());
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: To Write the "status response" from a REST" in a file,status different to "

Hey @alfonsolftc,

Is there a reason you're not using a Datasink step to do this? If you just need the status headers value i think a couple of lines of groovy in either a script assertion (or separate groovy step), which youve written already for the most part, along with a Datasink step will do this?

Also i'm not understanding the purpose of youre assignment of the hora variable. I can see youre specifying the datetime as the hora variable but you dont appear to use it at all in the script after assignment? Am i missing something important here?

Cheers fella,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: To Write the "status response" from a REST" in a file,status different to "

Hey @alfonsolftc,

Is there a reason you're not using a Datasink step to do this? If you just need the status headers value i think a couple of lines of groovy in either a script assertion (or separate groovy step), which youve written already for the most part, along with a Datasink step will do this?

Also i'm not understanding the purpose of youre assignment of the hora variable. I can see youre specifying the datetime as the hora variable but you dont appear to use it at all in the script after assignment? Am i missing something important here?

Cheers fella,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

Highlighted
Community Manager

Re: To Write the "status response" from a REST" in a file,status different to "

Thank you richie. 

Hi @alfonsolftc , were you able to solve the issue? If not, please try providing richie with the info he’s requiring and the Community will try to help you further. 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: To Write the "status response" from a REST" in a file,status different to "

Sorry Richie. Happy New Year 2020, I couldn´t answer before because I was in holiday.

I find interesting the solution you propose, could you send me an example with Data Sink and groovy script.

I suppose taht I could also use the Data Source Loop too

 

 

 

Highlighted
Community Hero

Re: To Write the "status response" from a REST" in a file,status different to "

Hi @alfonsolftc,

I will respond with the solution i think identified but it's going to be the weekend before i can get back to you on this.
Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: To Write the "status response" from a REST" in a file,status different to "

Hey @alfonsolftc 

 

ok - firstly the object hierarchy within your testcase I would expect to be something like the following:

 

REST Step

Properties Step

DataSink Step

 

On your REST request add a script assertion with the following code snippet:

//Takes one of the elements of the response Header
def value = messageExchange.modelItem.testStep.testCase.testSteps["RESTStepName"].testRequest.response.responseHeaders["#status#"]

//Read this value into a parameter - writes the header value into the Properties test step
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
groovyUtils.setPropertyValue("Properties ", "status",value[0])  //Properties is name of Properties step, #status# is the name of the header your need to extract from

The above script - grabs the header value and writes it to the Properties step and the Property wihtin the Properties step is entitled status

 

Configure the DataSink step to source the value from the Properties (I specified to use the DataSink's 'File' type.  I added a Property (Name value =  statusval) to the DataSink and the Property Value value = ${Properties#status} (you can use the GetDAta function to do this)

 

hope this helps,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors