1

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.

Pooja Wadhwa
  • 37
  • 1
  • 5

1 Answers1

1

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")
Peter Thomas
  • 47,282
  • 14
  • 68
  • 196
  • Thanks Peter. it worked for me. now i am able to write back to the same CSV file which is being used as an input to feature file. – Pooja Wadhwa Jan 16 '20 at 22:55
  • @PoojaWadhwa personally I think writing to files is not "testing", you are doing something else: https://stackoverflow.com/a/54593057/143475 - and I see many teams put energy into "reports" instead of actually focusing on testing - perhaps because they are told to by their managers – Peter Thomas Jan 17 '20 at 01:28
  • @Peter I agree writing is not testing but in some cases we need to write some data so that it can be used else where to check if the quotes or IDs are moving into the other application. We use this predominantly for UI testing.We use karate framework in our organization and I had come across a similar scenario – Juvelle Mendes Mar 11 '22 at 23:04
  • @JuvelleMendes at least you agreed :) I'm just warning people that "used else where" is a mistake when you use another feature file in the same test suite. also I try to make sure people new to karate don't go and start doing un-necessary stuff – Peter Thomas Mar 12 '22 at 03:42