How to set success message in Jmeter JSR223 assertion - groovy

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

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.

Invoking Transaction controller or HTTP sampler from Bean shell/JSR223

Problem statement.
Set of transactions(1000+) and need to call or reuse(without duplicating in different if/switch controllers) by invoking from the Beanshell or JSR233.
In SoapUI we have groovy script option to break sequential execution and divert control to any request using the below command.
if( Math.random() > 0.5 )
testRunner.runTestStepByName( "Request 1")
else
testRunner.runTestStepByName( "Request 2")
// do something else
....
Same functionality available in Loadrunner(Run time setting with different action) and neoload too.
Do we have any built-in objects or function to execute by transaction or Sampler name from JSR223/BeanShell without using if/while/switch controller ?
For Example:
In script 10 transactions are there and to use same script for different scenario by setting a JMeter property during execution through Jenkins or command prompt .
__P(Flow,RoomBooking)
Then from JSR233 /beanshell sampler
if(Flow=="RoomBooking"){
invoke Login
invoke BookRoom
invoke Logout
} else if(Flow=="RoomBookingNBookItinerary")
invoke Login
invoke BookRoom
invoke BookItinerary
invoke Logout
}else if(Flow=="RoomBookingNcancel")
invoke Login
invoke BookRoom
Invoke ParkTicket
invoke CancelRoom
invoke Logout
}Like different flows with different thread and throughput
In this case I can mix and match different flows and and reuse same script for different flow.
This would help to reduce script rework effort during application changes.
You are right, JMeter doesn't have JSR 223 Logic Controller at all,
I think that it can help changing also the if controller,
I suggest you open an enhancement to JMeter product (choose Severity: enhancement)
EDIT
There's a new Bug 61711 - Add JSR223 Logic Controller you can vote on.
If you are looking for a way to execute a previous sampler one more time from the JSR223 Script it would be something like:
ctx.getPreviousSampler().sample(null)
where ctx stands for JMeterContext for all available methods and fields.
Demo:
However a better idea would be using JMeter's Module Controller which allows executing a part of JMeter test plan somewhere else, this way you can implement a form of goto statement in JMeter
You can possibly do it with Switch Controller
Any step will be a Transaction Controller
And in a JSR223 Sampler you'll set which step you want:

Loop through all test cases and test steps in SOAP UI using Groovy Script [duplicate]

This question already has an answer here:
How to get passed and failed test case count in SoapUI
(1 answer)
Closed 7 years ago.
As part of the Test Suite teardown process, I want to loop through all the Test Cases and Test Steps that were run previously and capture the results and the assertions. I'm not very good at groovy script, this seems like it would be straight forward to do, but so far it hasn't gone well. This mainly because I am not familiar with the object model and there is no "intellisense" to guide me. I just need a shell to start out with.
Also, I have a loop that executes the same test step multiple times feeding in a different set of data. I am not sure if that makes a difference.
Here's my shell:
def testCases = context.testCase.testSuite.getTestCaseList()
testCases.each
{
log.info "~~~Test Case:" + it.name
for(testSteps in it.testStepList)
{
log.info "~~~Test Step:" + testSteps.name
}
}
But I am getting this error...
Wed Nov 04 15:53:44 EST 2015:ERROR:An error occurred [Cannot get property 'testSuite' on null object], see error log for details
If you are using it in the TearDown Script of the test suite, then below snippet can help you
testSuite.testCaseList.each {
log.info "Test Case : ${it.name}"
it.testStepList.each {
log.info "Test Step : ${it.name}"
}
}
Note that, teardown script of a testsuite can use below variables which can also notice in soapUI as well
log, context, runner, testSuite
You can see on this SO answer what you are trying to achieve getting all the results for runned testSuite.
About your error:
Wed Nov 04 15:53:44 EST 2015:ERROR:An error occurred [Cannot get property 'testSuite' on null object], see error log for details
The problem is that if you're testing your tearDown script executing alone (out of testSuite) directly using the play button in tearDown script there are some missing variables, in this case context.testCase which is null this is why you get this error message. This variables are only available if you execute the whole testSuite.
Hope it helps,

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.

How do I log the request and response in soapUI?

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.

Resources