How can i get failed http request details in jmeter via mail? - email

I am trying to send the mail through jmeter for failed http request, I want to know the sampler details like name of http request?
I have added if controller to check the assertion of previously running request sand send a mail if it fails.It gives me error message
"Message from Jmeter thread # Test failed: code expected to match /200/"
But I want to know the name of http request which has been failed so i can know specifically which request is failing?

You can use JSR223 PreProcessor to get the previous sampler details using the following code:
def sampler = ctx.getPreviousSampler()
Example usage:
def previousSamplerName = ctx.getPreviousSampler().getName()
log.info("Failed sampler name: " + previousSamplerName)
vars.put("SamplerName", previousSamplerName)
Demo:
If everything goes fine you will be able to access previous sampler name as ${SamplerName} in the SMTP Request sampler
ctx is a shorthand to JMeterContext class instance, see the JavaDoc for available methods and fields
vars is a shorthand to JMeterVariables class instance, it provides read/write access to all JMeter Variables in scope.
Also check out Groovy Is the New Black guide to get familiarized with using Groovy in JMeter tests.

Related

Lua open socket error

I am using lua as module for nginx (openresty) to get files from remote host. My function:
function readfile(url)
local http = require ("socket.http")
if not http then
error("Couldn't open socket.http")
end
http.TIMEOUT = 5
local body, code = http.request(url)
if not body then
error("Couldn't read the remote file: " .. code)
end
return body
end
I have tested this code by using Siege. When I set the users more then 100 (for example), I catch this error:
2018/03/27 09:36:38 [info] 10#10: *91018 shutdown() failed (107: Socket not connected), client: 172.18.0.7, server: localhost
I have more errors when i set more users. What does it mean? Thank you for the help.
Don't use luasocket library with OpenResty. The resulting code would block on http.request().
I suppose that all nginx worker just blocked and it is the reason of these errors.
For you purpose you may use one of the libraries below:
lua-resty-http
lua-resty-http-simple
First is more fexible, allow to use secure transport.
Second has simpler API.
And both use internally nginx Lua cosocket API and are 100% nonblocking out of the box.
The lua-resty-http or lua-resty-http-simple do not work in the init_by_lua in http context.
it is fine to use it in the init context where blocking is not considered harmful.

how to access the SOAP request in the groovy script - SOAP UI

I am writing a groovy script to consume the SOAP web service. First i imported my
WSDL in SOAP and created a project.
Then all the SOAP request are generated automatically.
Now am trying to write a groovy to call the SOAP service using the SOAP request generated.
Now here it is my groovy script
import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.*;
class Example {
static void main(String[] args) {
String serviceInput="";
PostMethod post = new PostMethod("http://server:30280/so_ws/SO?WSDL");
post.setRequestHeader("Accept", "application/soap+xml,application/dime,multipart/related,text/*");
post.setRequestHeader("SOAPAction", "");
// access CreateNote SOAP request here to call PostMethod
}
}
I want to access the same SOAP request generated in SOAP UI - CreateNote.
How can I access it?
My actuall requirement is to access all SOAP request in the groovy script - so that i can write one single script to test all the SOAP services in one go and that too in the sequence as per required
Here is the Groovy Script which gets the request from its previous step of the same test case like you have your test case currently.
Script
def req = context.testCase.getTestStepAt(context.currentStepIndex - 1).httpRequest.requestContent
log.info req

JMeter changing my namespace

I'm trying to use JMeter to invoke a RPC/SOAP Web service and when I invoke the service my namespaces are mangled from the actual values to NS1.
<?xml version="1.0" encoding="UTF-8"?>
<wpc:invoke xmlns:wpc="http://wpc.ibm.com">
<wpc:envelope communicationVersion="5.3">
<wpc:WPCResponseType>asynchronous</wpc:WPCResponseType>
<wpc:wpcHeader>
<wpc:companyName>mycompany</wpc:companyName>
<wpc:wpsUserID>me</wpc:wpsUserID>
<wpc:wpcUserID>wpcUsername</wpc:wpcUserID>
<wpc:password />
<wpc:messageIdentifier>9E2FA100-BE54-11E5-8A91-BF48E24665E0</wpc:messageIdentifier>
<wpc:timestamp>2016-01-18</wpc:timestamp>
<wpc:supplierId><![CDATA[0Z188]]></wpc:supplierId>
<wpc:localeForDisplay>en_US</wpc:localeForDisplay>
<wpc:localeRestriction>en_US</wpc:localeRestriction>
</wpc:wpcHeader>
<wpc:wpcBody>
<wpc:wpcCommand mode="ASYNC" type="UPLOAD">
<wpc:wpcCatalogName>Item Transaction Catalog</wpc:wpcCatalogName>
<wpc:wpcFileDocStorePath>test_data/upload/0003_items.csv</wpc:wpcFileDocStorePath>
<wpc:wpcUpdateOnly>false</wpc:wpcUpdateOnly>
</wpc:wpcCommand>
</wpc:wpcBody>
</wpc:envelope>
</wpc:invoke>
Changes to:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:invoke xmlns:ns1="http://wpc.ibm.com">
<ns1:envelope communicationVersion="5.3">
<ns1:WPCResponseType>asynchronous</ns1:WPCResponseType>
<ns1:wpcHeader>
<ns1:companyName>mycompany</ns1:companyName>
<ns1:wpsUserID>me</ns1:wpsUserID>
<ns1:wpcUserID>wpcUsername</ns1:wpcUserID>
<ns1:password/>
<ns1:messageIdentifier>9E2FA100-BE54-11E5-8A91-BF48E24665E0</ns1:messageIdentifier>
<ns1:timestamp>2016-01-18</ns1:timestamp>
<ns1:supplierId><![CDATA[0Z188]]></ns1:supplierId>
<ns1:localeForDisplay>en_US</ns1:localeForDisplay>
<ns1:localeRestriction>en_US</ns1:localeRestriction>
</ns1:wpcHeader>
<ns1:wpcBody>
<ns1:wpcCommand mode="ASYNC" type="UPLOAD">
<ns1:wpcCatalogName>Item Transaction Catalog</ns1:wpcCatalogName>
<ns1:wpcFileDocStorePath>test_data/upload/0003_items.csv</ns1:wpcFileDocStorePath>
<ns1:wpcUpdateOnly>false</ns1:wpcUpdateOnly>
</ns1:wpcCommand>
</ns1:wpcBody>
</ns1:envelope>
</ns1:invoke>
There must be a setting in JMeter to keep the message from being transformed from my original meaningful namespace to this arbitrary namespace called NS1? When the message is received at the target endpoint it cannot parse the request because of this semantic error.
Any/all replies are appreciated!
MG
JMeter should not change anything in the request body, maybe it is an issues with your web service? Double check the request which is being sent by JMeter using a sniffer tool like Wireshark
In any case try switching to HTTP Request sampler, this is recommended way of sending web service requests (just don't forget to add HTTP Header Manager to send Content-Type and SOAPAction headers).
References:
JMeter User's Manual: Building a SOAP WebService Test Plan
Testing SOAP/REST Web Services Using JMeter

SoapUI endpoint error randomly

I don't understand something about SoapUI and his mockservice's behaviour.
I'm using the client of SoapUI (testcase) and a Java EE application with JAX-RPC.
My problem is :
when I'm trying to call any webservice, from my Java Client, or the testcase of SoapUI, the mockservice return a well message at first call, and the error below at the second call, with the same call or not.
But if I'm waiting, It works ...
So, I have enabled the option in SOAPui : "close HTTP connection after each SOAP request" and it works all the time...
So my question is :
"Is it a normal behaviour of the mockservice, and how to implement this with my java client ?"
Thank you all.
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Missing operation for soapAction [] and body element [null] with SOAP Version [SOAP 1.1]</faultstring>
</soapenv:Fault>
OK,
I found a solution on the forum of SoapUI : http://www.soapui.org/forum/viewtopic.php?t=5648
It is when you have the settings flag "HTTP Settings/Logs wire content of all mock requests" set to true.
=> Uncheck the flag and it works fine!
Thanks a lot !
I had the same problem, using SoapUI 5.1.2 Pro.
After receiving first asynchronous response to the MockService, the MockService
stopped and could not receive any more responses for the request I sent.
The error message was:
Thu Jul 02 12:59:44 CEST 2015:ERROR:An error occurred [Missing operation for soapAction [XXXX] and body element [null] with SOAP Version [SOAP 1.1]], see error log for details
In SoapUI Settings:
File->Preferences->Http Settings: "Enable Mock HTTP log", uncheck box:
"Logs wire content of all mock requests".
Now I receive several asynchronous responses in a row, and give response back on them.
The same problem may happen when two mock services run with the same endpoint address (including port and path) on SoapUI.

Testing Soap 1.2 service in RobotFramework using suds library

I am trying to test soap 1.2 services using RobotFramework. So far, we have only tested soap 1.1 services using suds library for RobotFramework, and suds is not compatible with soap 1.2.
Backwards compatibility is an option for the new services, but it would be better to have a more long-term solution. I am not an experienced programmer, though I can edit code if told what to edit and where.
What happens in the test we have for soap 1.2 services using suds is: suds is unable to interpret the response it gets from the webservice and gives this error: SAXParseException: :159:229: mismatched tag
The soap message is fine, there is no problem using it in SoapUI.
I have found some snippets online that suggest I could get suds library to work with soap 1.2 for my RobotFramework tests. But I have little programming experience and no idea how to incorporate those snippets in suds.
Someone commented on this snippet that this fixed his issue with RobotFramework and suds.
Is there someone out there willing to explain how I could make this work? I can't seem to figure it out on my own. Any suggestions would be greatly appreciated.
from suds.client import Client
from suds.bindings import binding
import logging
USERNAME = 'username'
PASSWORD = 'password'
# Just for debugging purposes.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Telnic's SOAP server expects a SOAP 1.2 envelope, not a SOAP 1.1 envelope
# and will complain if this hack isn't done.
binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('client.wsdl',
username=USERNAME,
password=PASSWORD,
headers={'Content-Type': 'application/soap+xml'})
# This will now work just fine.
client.service.someRandomMethod()
snippet from: https://gist.github.com/kgaughan/858851
In short Suds does not support SOAP 1.2 bindings. Development has ceased quite some time ago. For this reason the SudsLibrary does not support it either.
Some of the differences I observed using an example service SOAP 1.1/1.2 are:
HTTP header Content-Type:
1.2 = "application/soap+xml"
1.1 = "text/xml".
HTTP header
1.2 = Action
1.1 = SOAPAction
Envelope Namespace
1.2 = "http://www.w3.org/2003/05/soap-envelope"
1.1 = "http://schemas.xmlsoap.org/soap/envelope/"
For each of these a seperate solution was implemented in the example below. The content type could be overwritten. The Action can be added but the SOAPAction can not be removed. The namespace can also be overwritten using the extension library. This should work for you if your service ignores the SOAPaction header attribute.
Test Case.robot
*** Settings ***
Library SudsLibrary
Library SudsLibraryExtension
Library Collections
*** Test Cases ***
TC
${BASE_URL} Set Variable http://www.holidaywebservice.com
${SERVICE} Create Dictionary
... name=HolidayService_v2
... wsdl=HolidayService2.asmx?WSDL
${PORT} Set variable HolidayService2Soap12
${METHOD} Set variable GetCountriesAvailable
Set Binding SOAP-ENV http://www.w3.org/2003/05/soap-envelope
Create Soap Client ${BASE_URL}/${SERVICE.name}/${SERVICE.wsdl}
Set Port ${PORT}
Set Headers Content-Type application/soap+xml
Set Headers Soapaction ${EMPTY}
Set Headers Action "${BASE_URL}/${SERVICE.name}/${METHOD}"
${result} Call Soap Method ${METHOD}
SudsLibraryExtension.py
import suds.bindings
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
class SudsLibraryExtension(object):
"""
Extension on the SudsLibrary
"""
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self, LibraryName='SudsLibrary'):
"""SudsLibraryExtension can be imported with an optional argument.
- ``LibraryName``:
Default value for `LibraryName` is SudsLibrary if not given.
The name can by any Library Name that implements or extends the
SudsLibraryExtension.
"""
try:
self.SudsLibrary = BuiltIn().get_library_instance(LibraryName)
# This is useful for when you run Robot in Validation mode or load
# the library in an IDE that automatically retrieves the documen-
# tation from the library.
except RobotNotRunningError:
pass
def set_binding(self, binding, url):
"""Set Binding can be used to add a binding to the message.
Example Set Binding SOAP-ENV http://www.w3.org/2003/05/soap-envelope
"""
suds.bindings.binding.envns = (binding, url)