Karate - How to write to the same CSV file that is being used as an input to the feature file - soap

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")

Related

How to set SOAPMessageContext Variables in Postman

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

Karate - How can we see the exact request and input parameters sent when the request in feature file is called from a file

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 ?".

Why is this Web Service called from Matlab receiving null?

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>

Parsing XML (SOAP Response) through NetSuite Script

In Netsuite Script I am trying to parse the response from EchoSign Webservice. The response from EchoSign is like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<getFormDataResponse xmlns="http://api.echosign">
<getFormDataResult xmlns="http://api.echosign">
<errorCode xmlns="http://dto8.api.echosign">OK</errorCode>
<errorMessage xmlns="http://dto8.api.echosign" xsi:nil="true" />
<formDataCsv xmlns="http://dto8.api.echosign">SOME DATA </formDataCsv>
<success xmlns="http://dto8.api.echosign">true</success>
</getFormDataResult>
</getFormDataResponse>
</soap:Body>
</soap:Envelope>
And my NetSuite code is here
var response = nlapiRequestURL(echoSignUrl, postStr, header);
var xml = nlapiStringToXML(response.getBody());
var resData = nlapiSelectNode(xml, 'soap:Envelope/soap:Body'); // /getFormDataResult/success');
if (resData)
return nlapiSelectValue(resData, 'formDataCsv');
But somehow I always get nothing back from nlapiSelectValue method!!
Nodes without any prefix should be accessed using default prefix nlapi:
for e.g. /soap:Envelope/soap:Body/nlapi:getFormDataResponse
It appears to be an issue with the way the namespacing is handled. Using the XML Tools plugin for Notepad++ and the XML you've provided, the XPATH Current Node Selector can't even find the getFormDataResponse node correctly. It simply fails with "Unknown Exception".
I also tried to manually evaluate the following expressions:
/soap:Envelope/soap:Body (works)
/soap:Envelope/soap:Body/getFormDataResponse (fails)
/soap:Envelope/soap:Body//getFormDataResponse (fails)
/soap:Envelope/soap:Body/*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::getFormDataResponse (fails)
If I modify the XML so the EchoSign namespaces are in the Envelope with a prefix, like so:
<soap:Envelope xmlns:echo="http://api.echosign" xmlns:dto8="http://dto8.api.echosign" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<echo:getFormDataResponse>
<echo:getFormDataResult>
<dto8:errorCode>OK</dto8:errorCode>
<dto8:errorMessage xsi:nil="true" />
<dto8:formDataCsv>SOME DATA</dto8:formDataCsv>
<dto8:success>true</dto8:success>
</echo:getFormDataResult>
</echo:getFormDataResponse>
</soap:Body>
</soap:Envelope>
then the path selector can get all the way down to the formDataCsv node correctly. It returns the path: /soap:Envelope/soap:Body/echo:getFormDataResponse/echo:getFormDataResult/dto8:formDataCsv.
Not sure how helpful that is because you're not in control of the XML that EchoSign sends to you, but I'm not sure how to correctly format the XPATH to deal with the namespaces.

Is it possible to add an attribute to an XML Root using nusoap's call() function?

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.