I am trying to use Postman to test an old outdated SOAP Service. The service is expecting some identities to be placed in a Handler Chain to obtain from the request. In the request it obtains the values in the following manner (with some exclusions):
import javax.annotation.Resource;
#Resource
private WebServiceContext webServiceContext;
public MyResponse methodEvent(...) {
...
String var1 = (String) context.getMessageContext().get("VAR1");
...
}
My question is when trying to use Postman how can I set this value in the request. It is not part of the normal headers or other standard entries.
It is possible before SOAP API call.
You can using the response of output to assign result variable
It can use other call output
From three different inputs
#1 Pre-request Script
#2 Global variable
#3 From other request output - I think you looking for this solution.
Demo - I will show ADD operation in Calculator SOAP
SOAP service URL
http://www.dneonline.com/calculator.asmx
Using variables input_a, input_b for adding
#1 Pre-request Script
value defined at Pre-request Script
postman.setEnvironmentVariable("input_a", 3);
postman.setEnvironmentVariable("input_b", 4);
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>{{input_a}}</intA>
<intB>{{input_b}}</intB>
</Add>
</soap:Body>
</soap:Envelope>
Result
#2 Global variable
Result
#3 From other request output - XML parsing and assign variable
You can using this output variable for other SOAP call's input
var xmlTree = xml2Json(responseBody);
var text = xmlTree["soap:Envelope"]["soap:Body"]["AddResponse"]["AddResult"];
console.log(text)
postman.setEnvironmentVariable("output_result", Number(text));
console.log(postman.getEnvironmentVariable("output_result"));
Print the parsing variable
Related
Karate - How to write to the same CSV file that is being used as an input to the feature file
I have created a java function which accepts key and value pair as arguments and then writes those values to the CSV file. But I am unable to understand how to call that method in the feature file.
I am writing the javascript function as shown below wherein "Utilities" is the package and "getdataexcel" is the java class.
Background:
* def doWork = function(arg1,arg2) {
var JavaDemo = Java.type(Utilities.getdataexcel);
JavaDemo.writesingleData(arg1,arg2);
}
Below is the feature file being used:
I am not quite sure how to write back the status/Result to the same CSV file.
There is definitely something wrong with the code that i have written in the Background and Feature file section.
Scenario: soapAdd 1.1 <Scenario with passing input Parameters in Request>
Given request
"""
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>4</intA>
<intB>3</intB>
</Add>
</soap:Body>
</soap:Envelope>
"""
When soap action 'http://tempuri.org/Add'
Then status 200
And def resp = /Envelope/Body/AddResponse/AddResult
And match /Envelope/Body/AddResponse/AddResult == 7
* eval if (resp == 7) karate.call doWork("Result","Pass")
* print 'the value of resp is' + resp
I need to write the Results back to the same input file and i have integrated Karate with QTEST(Test management Tool) and the test cases will the executed(Passed/Failed) in QTEST based on the test results of the API.
Please read this part of the documentation (actually read all of it, it is worth it :) https://github.com/intuit/karate#js-function-argument-rules-for-call
So you can't use call if you have 2 arguments. So just do this:
* if (resp == 7) doWork("Result","Pass")
Karate - How can we see the exact request and input parameters sent when the request is called from a file and input parameters are coming through CSV file
In the HTML report - at the given request step,whole of the request with input parameters is displayed if the request has been put in the feature file.
HTML Report:
**Test 49 : Given request**
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>2</intA>
<intB>6</intB>
</Add>
</soap:Body>
</soap:Envelope>
whereas, if the request had been put into an XML file and then called by using the XML in the feature file then it does not display the whole of the request in the HTML report.
For Example- Feature File:
Given request read('classpath:RequestFiles/AddRequest.xml')
HTML Report just displays the test step as:
"Test 86 : When soap action 'http://tempuri.org/Add'"
Is anyone aware of the way to display the whole of request with input parameters if the request(in the feature file) is called from a XML file?
There is a simple way to put anything in what you refer to as the Doc String section of the report. Just print it.
* print someVarYouReadFromAFile
Also note that HTTP requests and responses will appear in the report by default, and most teams are fine with it. If you don't see this, there may be some other problem.
Finally a word of advice. I see many teams focus too much on time on making the reports "pretty". I would focus more on the question "am I able to test more scenarios and detect failures ?".
I have created a very basic Web Service "operation" with an operation called "hello". It works perfectly from SoapUI, but when I use Matlab 2014a to call it, the input parameters are never obtained. So hello() always returns "Hello null!" and other operations, such as addition(), always returns 0. I have followed Matlab help and I am unable to see what is going on.
What I have done is:
>> createClassFromWsdl('http://ip/WebServiceTest/operation?wsdl')
ans = operation
>> obj = operation
endpoint: 'http://ip/WebServiceTest/operation'
wsdl: 'http://ip/WebServiceTest/operation?wsdl'
>> methods(obj)
addition display hello operation
>> hello(obj, 'John')
ans =
Hello null!
This demonstrates that the Web Service is called correctly and it returns an answer, but the input parameter is not obtained.
The generated code hello.m seems fine to me:
function xReturn = hello(obj,name)
%hello(obj,name)
%
% Input:
% name = (string)
%
% Output:
% return = (string)
% Build up the argument lists.
values = { ...
name, ...
};
names = { ...
'name', ...
};
types = { ...
'{http://www.w3.org/2001/XMLSchema}string', ...
};
% Create the message, make the call, and convert the response into a variable.
soapMessage = createSoapMessage( ...
'http://webservices/', ...
'hello', ...
values,names,types,'document');
response = callSoapService( ...
obj.endpoint, ...
'', ...
soapMessage);
xReturn = parseSoapResponse(response);
I have captured network traffic to see the SOAP message and Matlab sends indeed the parameter, and the message looks fine:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<hello xmlns="http://webservices/">
<name xsi:type="xs:string">John</name>
</hello>
</soap:Body>
</soap:Envelope>
The same message from SoapUI, which returns a correct Hello John! value would look like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices/">
<soapenv:Header/>
<soapenv:Body>
<web:hello>
<!--Optional:-->
<name>John</name>
</web:hello>
</soapenv:Body>
</soapenv:Envelope>
What is it happening?
EDIT
I have also found this in the logs:
Received WS-I BP non-conformant Unquoted SoapAction HTTP header
After a lot of testing, I believe this is due to an error on old Matlab Web Service implementation, especially related to the lack of explicit namespace here <hello xmlns="http://webservices/">
From version 2014b there is a new way to call Web Services based on JDK and Apache CXF, and using the Web Services are called correctly. According to the documentation, the steps are:
Install and/or locate the Java JDK and Apache CXF programs.
Set the
paths to the JDK and CXF programs using the
matlab.wsdl.setWSDLToolPath function. Values for the paths are saved
across sessions in your user preferences, so you only need to
specify them once.
Change the MATLAB current folder to the location
where you want to use the files generated from the WSDL document.
You must have write-permission for this folder.
Run
matlab.wsdl.createWSDLClient, supplying the WSDL document location,
which can be a URL or a path to a file. The function converts the
server's APIs to a MATLAB class, and creates a class folder in the
current folder. The class folder contains methods for using the
server's APIs. The function always creates a constructor method that
has the same name as the class. You only need to run the
matlab.wsdl.createWSDLClient function once. You can access the class
anytime after that.
Create an object of the class whenever you want
to use the operations of the service.
View information about the
class to see what methods (operations) are available for you to use.
Use the methods of the object to run applications on and exchange
data with the server. MATLAB automatically converts XML data types
to MATLAB types, and vice versa.
Note: Depending on the version of Matlab used you might be required to provide a minimum or specific version of JDK
An example can be:
jdk = 'C:\Program Files\Java\jdk1.7.0_79'
cxf = 'C:\Program Files\apache\apache-cxf-2.7.18'
matlab.wsdl.setWSDLToolPath('JDK',jdk,'CXF',cxf)
matlab.wsdl.createWSDLClient('http://ip/WebServiceTest/operation?wsdl')
javaaddpath('.\+wsdl\operation.jar')
obj = operation
methods(obj)
hello(obj, 'John')
The newer version produces the following SOAP message:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:hello xmlns:ns2="http://webservices/">
<name>John</name>
</ns2:hello>
</S:Body>
</S:Envelope>
I'm using Currency Converter webservice to practice groovy script in SoapUI Pro.
In that, I have created a property that should get response / output of the Currency Converter service through groovy script.
For that, I tried the following script which gets all the raw response data :(
I need to get the exact result i.e. converted value and assign to the property.
Can anyone provide me the correct groovy script?
Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>INR</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
Response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>60.54</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
Thanks
Karunagara Pandi
First you need access to the Response.
def conversionRateResult = context.expand( '${step_name#Response#//*:ConversionRateResult}' )
Then to assign it to a property depends on multiple things: 1) where are you doing it from, and 2) where do you want the property assigned.
To crawl the hierarchy from a script step, you would do something like:
testRunner.testCase.setPropertyValue("property_name", conversionRateResult)
Consider browsing through the documentation and API.
I am creating a class that will be utilizing the Fedex Web Services. I am attempting to communicate through the nusoap php class's nosoapclient() function, passing it a wsdl file. It seems Fedex requires a namespace attribute in the document root of a request.
I can use nusoap's call() function and pass it an XML string as the PARAMETER agrument which WILL WORK properly. I would rather pass an array through as the PARAMETER argument, and this is where I am running into an issue.
Is it possible to pass an array through nusoap's call() function and also include a namespace attribute in the root?
FEDEX RateRequest PHP exerpt
The following is to give an idea of what I am trying to do and not actual code
$client = new nusoapclient('RateRequest_v9.wsdl',true);
//Thought this would work but to no avail.
//$request_array is a multi-associative array with keys as required XML tag names and values as the tags inner value, did not include as it is irrelevant to this problem
//$root_attr = array('xmlns'=>'http://fedex.com/ws/rate/v9');
//$parameters = array('RateRequest'=>new soapval('RateRequest',false,$request_array,false,false,$root_attr));
$parameters = array('RateRequest'=>$request_array);
//Have tried with and without the third argument - which is the for the namespace
$response = $client->call('getRates',$parameters,'http://fedex.com/ws/rate/v9');
FEDEX RateRequest XML excerpt
The following is not the full XML (look at the RateRequest tag toward the end to see the difference)
INCORRECT FORMAT
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns="http://fedex.com/ws/rate/v9"><SOAP-ENV:Body><RateRequest>...</RateRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
CORRECT FORMAT
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns="http://fedex.com/ws/rate/v9"><SOAP-ENV:Body><RateRequest xmlns="http://fedex.com/ws/rate/v9">...</RateRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
My apologies in advance if I have missed this conversation elsewhere but I have been scouring the net and trying everything I could think of to make it work, if its not possible any suggestions? Thank you in advance for your assistance.