How do I log the request and response in soapUI? - groovy

I am calling a REST based service from SoapUI. I have created a load test for the service and the test works. I wrote the following code in my setup script for the load test.
log.info("This is from the setup script")
def request = context.expand('${#Request}')
log.info(request)
def response = context.expand('${#Response}')
log.info(response);
The only item I am getting in my log is the "This is from the setup script".
I also added the following lines of code in my Teardown script.
log.info("Teardown script")
def response = context.expand('${#Response}')
log.info(response);
I am not seeing the "Teardown script" text in the log. At this point I am a bit puzzled as to the behavior.
Load Test:
Test Suite
Test case options.
I have unchecked the Discard OK results test box.
What changes do I need to do to my scripts in order to log the requests and the responses?

When you create a setup and/or teardown script, remember those are run only once per run, not per test! What you intended is not going to work.
In your setup, since no tests have run yet, the context is going to be empty ... as you can see from your log message.
In your teardown, I suspect there is a bug in SoapUI and the log is not getting sent to the log tab. If you intentionally create an error (I used logg.info "Hello world!" - note the intentional double g), I still got a an error in the error log tab.

Related

Issues regarding calling a custom function in a Netsuite CS script on button click

I added a button to my employee form via a UE script to which I bound the 'createDebtor' function, which I made in the CS script which I attached to my UE script.
I am not really familiar with this method yet and run into some errors in my CS script. The following is the start of my CS script:
I added both console and script logging, because the script logging did not work. Note that the alert function works, so the initialization of the code and binding of the function works correctly. I have the following questions regarding my code:
*Why does log.debug not work (I am owner of the script and the script deployment has debug log level and testing status)
*Trying to console.log the 'employee' variable returns a readOnly object with the methods like 'getvalue', but no properties containing data. Is there an easy way to obtain and log all the properties of this object?
*As a followup to the previous question I tried to use the 'getValue' function to obtain data, but this returns 'undefined' for the 'subsidiary' field. (the field ID should be correct, as I got it from the employee form itself). Could someone advice what I am doing wrong here?
Suite Answers 68476, 74121, and 10564 suggest that you try/confirm the following:
In the User Event script, call form.setScript() before form.addButton().
Check the execution log of the User Event script, not the Client Script.
Confirm that the Log Level is set correctly, I assume on the User Event script and the Client Script.

How to set success message in Jmeter JSR223 assertion

I have a question about assertion message I would like to add in Jmeter JSR223assertion.
I know how to put message if an assertion failed
AssertionResult.setFailureMessage(failureMessage);
but if the assertion passed, meaning its all OK is their a way to print a message?
AssertionResult.setFailure(false);
what to add that I could put a message in Jmeter
For the moment you cannot set "assertion success" message, however you can amend parent SampleResult message to something custom using the following code in the JSR223 Assertion:
prev.setResponseMessage('some custom message')
It will result into:
More information: Scripting JMeter Assertions in Groovy - A Tutorial
Assertion result doesn't have option to set successful message, but JSR223 Assertion as other JSR223 elements have specific variable, you need the log variable,
You can print a message to log with error level:
log.error("My error...");
or log information to log:
log.info("My message");
also you have log.debug or log.warn and maybe other function depending on your log implementation (slf4j/log4j...)
There is no way to set a success message.
JMeter being a load test tool mainly, we only report details on failed samplers.
You may request an enhancement explaining why you need this:
http://jmeter.apache.org/issues.html

How to get script assertion results by calling test case?

I have isolated all the request alone in One Test Suite. I need to collect each api call time Taken..
Every Functional Test Case will call Request Test Suite using Run Test Case option.
I have following code in the script assertion of each request.
def endpoint = messageExchange.getEndpoint()
uri = endpoint.replace("baseurl","")
log.info("Current URI: "+uri)
uri = "t_"+uri
def headers = messageExchange.getResponseHeaders()
bytes= headers["Content-Length"].get(0)
log.info("Number of Bytes: "+ bytes)
timeTaken = messageExchange.getTimeTaken().toString()
values = timeTaken + ";"+ bytes
context.testCase.setPropertyValue(uri, values)
I expected that the uri would be created as the key and timeTaken and bytes are values.
When run the request (from Request Test Suite) it creates the property.
But Functional Test Case calls this request from other Test suite it does not create such property.. How to resolve this? I see the work around run the each request and get the property created so that on next run it would be updated.. But the problem is when starting test suite I am deleting all the properties and values. So again it is a mess up.. Can someone let me know how to resolve this issue?
you can add a result to a csv file directly after execution like this:
new File('out.csv').append( "$uri; $timeTaken; $bytes\n" )

SoapUI Groovy Script’s JSON Responses Is Empty When Using Testrunner

Using Windows 7 with Soap 5.2.0 freeware.
I also asked about this in the Smart Bear community and was only given recommended posts to read. The posts didn’t relate to this problem.
I have a REST project that has one test suite with one test case containing two test steps. The first step is a groovy step with a groovy script that calls the second test step. The second test step is a REST GET request that sends a string to our API server and receives a response back in JSON format. The second test step has a script assertion that does "log.info Test Is Run", so I can see when the second test is run.
When the groovy script calls the second test step it reads the second test step’s JSON response in the groovy script like this:
def response = context.expand('${PingTest#Response}').toString() // read results
I can also use this for getting JSON response:
def response = testRunner.testCase.getTestStepByName(testStepForPing).getPropertyValue("response")
The project runs as expected when run through the Soap UI but when I run the project with test runner, the response from the groovy script call to get the JSON response is empty, using either of the methods shown above. When run from testrunner, I know the second test step is being called because I see the log.info result in the script log.
This is part of the DOS log that shows the second test step is running and it seems there are no errors for the second test step run.
SoapUI 5.2.0 TestCase Runner
12:09:01,612 INFO [WsdlProject] Loaded project from [file:/C:/LichPublic/_Soap/_EdPeterWorks/DemoPing.xml]
12:09:01,617 INFO [SoapUITestCaseRunner] Running SoapUI tests in project [demo-procurement-api]
12:09:01,619 INFO [SoapUITestCaseRunner] Running Project [demo-procurement-api], runType = SEQUENTIAL
12:09:01,628 INFO [SoapUITestCaseRunner] Running SoapUI testcase [PingTestCase]
12:09:01,633 INFO [SoapUITestCaseRunner] running step [GroovyScriptForPingtest]
12:09:01,932 INFO [WsdlProject] Loaded project from [file:/C:/LichPublic/_Soap/_EdPeterWorks/DemoPing.xml]
12:09:02,110 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request
12:09:02,111 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: GET /SomeLocation/ABC/ping?echoText=PingOne HTTP/1.1
12:09:02,977 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200
12:09:02,982 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely
12:09:03,061 INFO [log] **Test Is Run**
This is the testrunner call I use in DOS command line:
“C:\Program Files\SmartBear\SoapUI-5.2.0\bin\testrunner.bat" DemoPing.xml
When the groovy script is run through test runner I get the project using ProjectFactoryRegistry and WsdlProjectFactory. Any advice on why I can’t read JSON response when using testrunner would be appreciated.
I can provide more info/code if needed.
Thanks.
Please try the below script:
import groovy.json.JsonSlurper
//provide the correct rest test step name
def stepName='testStepForPing'
def step = context.testCase.getTestStepByName(stepName)
def response = new String(step.testRequest.messageExchange.response.responseContent)
log.info response
def json = new JsonSlurper().parseText(response)
Thank you Rao! Your suggestion worked when I used it as shown below. The DOS window showed the response text:
// setup stepName as variable for name of test step to run.
def stepName = "PingTest"
// use stepName to get the test step for calling the test step (testCase is a
string variable of the test case name).
def step = context.testCase.getTestStepByName(stepName)
// call the test step.
step.run(testRunner, context)
// show the results.
def response = new String(step.testRequest.messageExchange.response.responseContent)
log.info response // this response shows correctly in the DOS window
The json slurper also works. At your convenience, if you have any suggested links or books describing the technique(s) you used here please let me know of them.
Thanks.

SOAP UI Reporting

I am using open Source version of SOAPUI.
My requirement is to export SOAP Response XML into a file (e.f txt). I could not find any such option in open source for this purpose. Please suggest if there is any way to do it or Groovy scripting is the solution. If yes then how.
If you want to save a simple SOAP Test step response, you can add a groovy script with this code to do so:
// get your response
def soapResponse = context.expand('${YourSOAPRequest#Response}')
// create the file
def file = new File("C:/Temp/testSO/response.xml")
file.mkdirs()
// save the response
file.write(soapResponse)
Note that YourSOAPRequest is the name of your SOAP Test step.
Additionally if you want to save all the test step responses of the Test suite or the Test case this answer could help you: Unable to save TestSuite Response Result in SOAP UI
You could run your tests from the command line, with the -a or -A switch.
Thanks to #albciff for guiding me through the answer. I also figured out a way for situtaion when rather than a static SOAP request name we have a variable:
def soapResponse= testRunner.testCase.getTestStepByName(testStepName).getProperty("Response").getValue()
Now this response can be used to save

Resources