tutorial property probar online espaƱol ejemplo como groovy soapui jsessionid

groovy - property - soapui send xml request



Pasar JSESSIONID desde una respuesta SOAP a una solicitud HTTP en SOAP UI (1)

Suponiendo que el caso de prueba tiene dos pasos de prueba con los siguientes nombres:

  • paso 1 (del paso de prueba de Solicitud SOAP)
  • paso 2 (del paso de prueba de Solicitud HTTP)

step1 respuesta step1 contiene Set-Cookie en el encabezado de respuesta. Y el step2 debe enviar Cookie arriba como parte de los encabezados de solicitud.

La siguiente Script Assertion para el step1 establece Cookie en el paso 2. Por favor, siga los comentarios en línea.

Aserción de script:

/** * This script assertion reads the http response, * collect the cookies for the next http request * Provide the next step name where you want to set the Cookie to the request **/ //Change the name of the test step2 below as per your test def nextStepName = ''step2'' //Assert if the step1 response has headers assert messageExchange.responseHeaders, "Response does not have headers" //Get the next request using test step name def nextRequest = context.testCase.testSteps[nextStepName].httpRequest //Get the existing headers def headers = nextRequest.requestHeaders //Get Cookie from step1 response and create headers if (messageExchange.responseHeaders.containsKey(''Set-Cookie'')) { log.info "Found Cookie in the response headers" def cookiez = messageExchange.responseHeaders[''Set-Cookie''].value def list = [] cookiez.each { cookies -> list.add(cookies.toString()) } headers[''Cookie''] = list } else { log.warn "Not Found Cookie in the response headers" } //Set the headers for step2 nextRequest.requestHeaders = headers

Actualización 1

Aquí está la Script Assertion mejorada que le permite extenderse muy fácilmente:

  • a cualquier número de encabezados de respuesta de paso actual
  • a cualquier cantidad de pasos de prueba según sea necesario

/** * This is the Script Assertion * which sets headers to the requested targeted steps * by extracting header from current step response **/ //Assert if response has headers assert messageExchange.responseHeaders, "Response does not have any headers" //Specify all the headers to retrieve from current test step response as keys, target step request headers as values //key - current response header name //value - target request header name //Add more key, values into map if you need to extract and set more headers def headerMap = [''Set-Cookie'' : ''Cookie''] //Specify the test step name for which headers to be set. Change step name as needed. //Add call to setHttpHeaders with different test step names as needed to apply for more steps setHttpHeaders(''step2'', headerMap) /** * method sets headers to targeted step * step is the step name for which headers to be set * header map consists key, header name in the current step and value, header name to appear in the * targeted step * **/ def setHttpHeaders(def step, def headerMap) { def nextRequest = context.testCase.testSteps[step]?.httpRequest def existingHeaders = nextRequest?.requestHeaders headerMap.each { existingHeaders[it.value] = getHttpHeaderValue(it.key) } nextRequest?.requestHeaders = existingHeaders } /** * method to retrieve the value of the specified header **/ def getHttpHeaderValue(def headerToLookup) { if (messageExchange.responseHeaders.containsKey(headerToLookup)) { log.info "Found ${headerToLookup} in the response headers" return messageExchange.responseHeaders[headerToLookup] } else { log.warn "${headerToLookup} is not found in the response headers" } null }

Tengo un caso de prueba que realiza un inicio de sesión a través de una solicitud SOAP y la respuesta incluye este encabezado:

Set-Cookie | JSESSIONID=85fc792a71f8eb1e2f0e9c63339e; Path=/somepath; HttpOnly

Después de eso tengo una solicitud HTTP a una URL a la que solo se puede acceder si el inicio de sesión fue exitoso. Aunque configuré ''Mantener sesión HTTP'' como verdadero en Opciones de TestCase, la cookie JSESSIONID no se transfiere a mi solicitud HTTP. La solicitud HTTP se realiza sin un JSESSIONID, por lo tanto, la respuesta no es la URL solicitada sino la página de inicio de sesión. Supongo que es porque el proceso de inicio de sesión es una solicitud SOAP no HTTP.

Traté de manejar el problema con un guión maravilloso: pude capturar el JSESSIONID de la respuesta SOAP y configurarlo como

Cookie | JSESSIONID=85fc792a71f8eb1e2f0e9c63339e

a mi solicitud HTTP, pero la respuesta es nuevamente la página de inicio de sesión, no la página solicitada. ¿Alguna idea de cómo resolver este problema? La versión de SOAP UI es 5.2.1