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