Search code examples
bddkarate

Karate SET functionality is not setting the value


In the given on the code I wanted to update the empid in the json which I get the value from database. The empid value is read from the database and it is properly printing in the console but when I try to set the same value I get the exception as null.

Source Code"

Feature File

Feature:Request

Scenario: Create Service

    * def getResults = db.readRows(Java.type("abc.xyz").getDBValue())
    * def empid = getResults.empid
    * def service= { "empid": 25072801, "userName": "testuser", "reasonCode": "test cancel" }

    * print service.empId
    * set service.empId = empId

Instead of reading from database, I have also given the value like below but still fails

* set service.empId = 1234

Exception:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running riseMap.TestParallel
23:31:01.767 [main] INFO  com.intuit.karate.RunnerOptions - found system property 'karate.options': --tags @updateactiveroutesequence
Warning: Nashorn engine is planned to be removed from a future JDK release
23:31:02.651 [main] INFO  com.intuit.karate.Runner - waiting for parallel features to complete ...
23:31:02.760 [ForkJoinPool-1-worker-3] INFO  com.intuit.karate - karate.env system property was: dops
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via
the SPI and manual loading of the driver class is generally unnecessary.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.minidev.asm.DynamicClassLoader (file:/C:/Users/chinnsu/.m2/repository/net/minidev/accessors-smart/1.2/accessors-smart-1.2.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of net.minidev.asm.DynamicClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
23:31:04.613 [ForkJoinPool-1-worker-3] INFO  com.intuit.karate - [print] 0

scenarios:  1 | passed:  0 | failed:  1 | time: 1.7240
---------------------------------------------------------
Karate version: 0.9.5
======================================================
elapsed:   2.81 | threads:    5 | thread time: 1.72
features:     1 | ignored:   62 | efficiency: 0.12
scenarios:    1 | passed:     0 | failed: 1
======================================================
failed features:
project.service: service.feature:22 - null

Jun 11, 2020 11:31:04 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\chinnsu\RSG\Workspace\API\target\surefire-reports\project.service.json' contains 1 features

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.975 sec <<< FAILURE!
testParallel(project.TestParallel)  Time elapsed: 3.92 sec  <<< FAILURE!
java.lang.AssertionError: failed features:
project.service: service.feature:22 - null

        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.assertTrue(Assert.java:41)
        at project.TestParallel.testParallel(TestParallel.java:22)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Even I tried to read this json from a separate file and then I set value but that also does not working


Solution

  • Try without the set:

    * service.empId = empId
    

    Else this works for me. Follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue