Forum Discussion

alfonsolftc's avatar
alfonsolftc
Occasional Contributor
5 years ago

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());
}

 

 

  • 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
  • richie's avatar
    richie
    Community Hero
    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
    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      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. 

    • alfonsolftc's avatar
      alfonsolftc
      Occasional Contributor

      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

       

       

       

      • richie's avatar
        richie
        Community Hero
        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