1

I am using standalone jar for executing karate scenarios (java -jar karate.jar xyz.feature). I am stuck at below two concerns

Concern1: Unable to call java class, it just throws TypeError unable to access or file not found

Scenario: 
* def javaFile = Java.type('test')
* def obj = new javaFile()
* print obj.getName()

Test Class: 
public class test {

    public String getName(){
        return "happyface";
    } 
}

Concern2: As i was unable to call java, used js for creating DB connection. Connection is successful but stuck at converting the returned object.

Scenario:

* def stmt = conn.createStatement()
* def dbResponse = stmt.executeQuery('SELECT * FROM xyztable');
* print dbResponse.label
* json jsonValues = dbResponse
* print jsonValues.label
* print JSON.stringify(dbResponse)

None of the above works, is there any simple way in converting the return object from dbResposne? Expecting data from dbResposne as List<Map<String, Object>> (Example of two rows of data from a database table)

Thanks for the help!!

Sandeep P
  • 109
  • 1
  • 10
  • 1
    you have to figure out the db issue on your own, it has nothing to do with karate. here is an example of using JS for the java file API: https://stackoverflow.com/a/65035825/143475 - also read this: https://github.com/intuit/karate#type-conversion – Peter Thomas Jul 09 '21 at 19:05
  • @PeterThomas As my question was made duplicate, i tried using "java -cp karate.jar. com.intuit.karate.Main -e qa Login.feature" But still i see the error >>> failed features: js failed: >>>> 01: Java.type('test') <<<< org.graalvm.polyglot.PolyglotException: TypeError: Access to host class test is not allowed or does not exist. - .:program(Unnamed:1) Login.feature:10 << – Sandeep P Jul 10 '21 at 14:22
  • follow this process - or if you can't - please assume that what you want is not supported by karate: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jul 10 '21 at 14:23
  • @PeterThomas it is not with the DB issue, karate is unable to read the Java file. – Sandeep P Jul 10 '21 at 14:23
  • and my answer to that is `it works for me` – Peter Thomas Jul 10 '21 at 14:24
  • I am on Windows, latest version karate RC. Used java 11 and 8. Not sure if this is a bug in windows only – Sandeep P Jul 10 '21 at 17:31
  • no idea. all the best – Peter Thomas Jul 10 '21 at 17:50

0 Answers0