Transfer attachment to another testStep - groovy

I have a REST test request that returns a MIME multipart/related message. One of the parts has type 'application/zip'.
In soapUi UI, I can see the zip file in the attachments tab.
1- I would like to have this file attached to the request of another REST testStep without manual intervention.
Is this possible with Groovy script ?
I guess it would start with :
def response = testRunner.testCase.getTestStepByName( "firstStep" ).testRequest.getResponse()
def firstStepAttachment = response1.attachments[0]
2- to make it a bit harder, the transfered file is a .zip and I'd like a specific file in it (I know its name and path), is there any way to do that during the file transfer?
Kudos

Related

Blazemeter: How to read error JTL file of Blazemeter?

I want to read the error.jtl file which we get from Blazemeter Logs (File name- Artifacts).
I am currently using Excel to read the file. Is there any other way, I can view this JTL file, in the same manner, we see the JMeter results jtl file(to HTML Report)?
error.jtl is a JMeter-specific file which is generated by Taurus framework, it contains request and response data for the samplers which have failed during the test execution.
I don't know what do you mean by "read", the file is normal XML file so you can use any text or XML viewer/editor to inspect it.
Also as per How to Capture Response Data from a JMeter JTL File (NTC) article:
Unzip artifacts.zip and open the trace.jtl / error.jtl in JMeter's View Results Tree Listener. The samplers are listed. When selected, the response data can be examined.
so you can open it in View Results Tree or any other Listener of your choice.
You cannot generate HTML Reporting Dashboard from the .jtl file in XML format, however you can use i.e. Filter Results Tool to extract only failing sample results from the kpi.jtl file and generate the dashboard out of it.

Flask: Get gzip filename sent from Postman

I am sending a gzip file from Postman to a Flask endpoint. I can take that binary file with request.data and read it, save it, upload it, etc.
My problem is that I can't take its name. How can I do that?
My gzip file is called "test_file.json.gz" and my file is called "test_file.json".
How can I take any of those names?
Edit:
I'm taking the stream data with io.BytesIO(), but this library doesn't contain a name attribute or something, although I can see the file name into the string if I just:
>>>print(request.data)
>>>b'\x1f\x8b\x08\x08\xca\xb1\xd3]\x00\x03test_file.json\x00\xab\xe6RPP\xcaN\xad4T\xb2RP*K\xcc)M5T\xe2\xaa\x05\x00\xc2\x8b\xb6;\x16\x00\x00\x00'
Further to the comment, I think the code which handles your upload is relevant here.
See this answer regarding request.data:
request.data Contains the incoming request data as string in case it came with a mimetype Flask does not handle.
The recommended way to handle file uploads in flask is to use:
file = request.files['file']
file is then of type: werkzeug.datastructures.FileStorage.
file.stream is the stream, which can be read with file.stream.read() or simply file.read()
file.filename is the filename as specified on the client.
file.save(path) a method which saves the file to disk. path should be a string like '/some/location/file.ext'
source

How to stream (upload) large amount of data with Requests in Python?

The module requests provides a high level HTTP API. Using requests I'd like to send data via HTTP using a POST request. The documentation is very short about this, stating that a "file like object" should be provided without stating clearly what exactly requests would expect from that object. I've some binary data, but unfortunately this is generated data and I have not a file like object. How could I possibly implement a "file like object" myself that would conform to the expectations of requests? The documentation is quite poor in that regard and I wasn't able to clarify this by looking into the source code of requests myself. Has anyone done this before using the requests API?
File-like object is a standard Python term for an object that behaves like a file. This means that if you have a file, you have a file-like object and simply need to pass the file path to Requests. If you have a more complex situation you will need to give us a full description of the form of your data so we can help you more explicitly.
EDIT: To address your comment, here is the code to send a binary file to a host using Requests.
url = 'http://SomeSite/post'
files = {'files': ('mydata', open('mydata', mode='rb'), 'application/octet-stream')}
r = requests.post(url, files=files)
Opening the file with the Python open command creates the file-like object.
EDIT2: Whenever to open a file on disk you create a file-like object in the process of opening the objects. However, Python supports other object types that act like files. Some examples include the standard stdin, stdout and stderr. In addition, pipes can be access using os.pipe and via subprocess.Pipe. These objects behave like files, i.e. they can be accessed with a subset of the file API and their API's behave in the same way as the object that accesses a real file.
This is why they are called file-like because they use the same API's and act in the same way. You open, close, can read or write a pipe in the same way as you do a file.

How do you make SoapUI assert against log output?

I have a process that doesn't respond with output, it creates a log line in a file. I want soapui to generate a request, then look in a log file for the expected output.
If I understand your goal, you can use a Script assertion in your testStep to check for the content in your log file after the request is executed.
So then you can use something like the follow simple Groovy code as Script assertion:
// get your log content
def logFile = new File('pathTo/file.log')
// and assert if the log file
// contains the expected string
assert logFile.getText('UTF-8').contains('expectedText')
NOTE: If you want to check that your server writes a log instead of creates a response then you've to execute your SOAPUI tests from the server machine itself or alternatively have a shared access to this log file from the machine where you will run the tests.
Hope it helps,

How do I get the size of a response attachment in SoapUI?

I'm performing a series of file uploads and downloads through a WSDL defined interface in SoapUI (not Pro). The built-in assertions to verify these attachments are insufficient. I've found some Groovy code that allows me to get the size of the upload attachment.
import com.eviware.soapui.impl.wsdl.support.RequestFileAttachment
def uploadsize = testRunner.testCase.getTestStepByName("Upload File (200KB)").testRequest.getAttachmentAt(0).getSize()
I'm looking for comparable code to get the size of the download attachment. The HTTP headers specify that the content type is "multipart/related" and UTF-8. The attachment itself is "Content-Type: application/octet-stream \n Content-Transfer-Encoding: binary"
I've tried the following snippet of code but it doesn't give me the size of the attachment, just the size of the response.
def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.contentAsString.size()
Since the documentation for the SoapUI Groovy classes is labyrinthine at best, I used introspection to find out what kind of class I was working with:
log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.class.name
log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.class.name
which yields:
com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest
com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse
Now one doesn't need to guess which class to look up.
The resulting code for attachment size is:
def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.getAttachments()[0].getSize()

Resources