Code Monkey home page Code Monkey logo

Comments (6)

kirksl avatar kirksl commented on July 16, 2024

Hi @Shivin89. Apologies for the delay i've been very busy.

We initially tried to use "after scenario" but had many issues when running tests in parallel. The results posted to RP were reported incorrectly. I spent a lot of time on this to see what others were doing and understand RP code. Ultimately the safest option and what I saw others doing was to take advantage of Java "synchronize" and to report results using "after feature" where we could still access all of the scenario level detail, but it would get reported all at once per feature.

I would suggest keeping what is in place as you have full capability to spin through the scenarios in the "after feature" hook. If you really need to use "after scenario" feel free to try, but be very careful, test parallel execution, verify results are always correct. The other issue we saw sporadically when using "after scenario" is that execution runs would not complete as well and we had to force finish test runs in the RP UI.

from karate-maven-gradle.

Shivin89 avatar Shivin89 commented on July 16, 2024

Hi @kirksl

Thanks for the explanation, appreciate it !! I had one question not related to this issue but in general, Is the Calling Java class working in your framework? like example below

def JavaDemo = Java.type('com.cdk.runner.RPReporter').SL_DC

  • json result = JavaDemo.getSlDc("HelloWorld")
    • print JavaDemo

https://stackoverflow.com/questions/70283234/set-the-variable-value-defined-in-the-java-class-via-feature-file

Thanks
Shivin

from karate-maven-gradle.

kirksl avatar kirksl commented on July 16, 2024

@Shivin89 are you having trouble with a specific Java class or calling all Java classes? I am able to call Java classes within karate-maven-gradle.

from karate-maven-gradle.

Shivin89 avatar Shivin89 commented on July 16, 2024

Hi @kirksl I was trying to call Report Porter Class using
def JavaDemo = Java.type('com.cdk.runner.RPReporter')

I have defined the below variables in the Report Portal class and
public static String SL_JOB_ID;
public static String SL_DC = "US";

I have this method (Setter and Getter)
public void setSlJobId(String slJobId) {

    SL_JOB_ID = slJobId;

}

public static String getSlDc() {
    return SL_DC;
}

I am trying to set the value of SL_JOB_ID to session-id in my feature file

(
Given driver baseUrl
* def sessionId = driver.sessionId
* print sessionId
def JavaDemo = Java.type('com.cdk.runner.RPReporter')
* def test = JavaDemo.setSlJobId("Testing")

But when I run the test it says
01: JavaDemo.setSlJobId("Testing")
<<<<
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (setSlJobId) on com.cdk.runner.RPReporter failed due to: Unknown identifier: setSlJobId

  • .:program(Unnamed:1)

I have also tried to get the value of SL_DC too but it also failed with the same error

I have also tried def JavaDemo = Java.type('com.cdk.runner.RPReporter').SL_DC and test passes but the value of JavaDemo is Null when I print it

I am able to call a library called Faker and use methods inside that library
in karate-config.js
config.faker = Java.type('com.github.javafaker.Faker');

  • def fakerObj = new faker()
    • def fName = fakerObj.name().firstName()

And this works fine , I have tried creating obj of the class too but then it failed saying message not supported .

This is a static method so we don't need to create object .

from karate-maven-gradle.

kirksl avatar kirksl commented on July 16, 2024

@Shivin89 this thread is going out of scope of the issue reported.

But below is an example of how I use local/project classes if that helps. I'd suggest talking to Karate developers if you can't solve this. Also try other versions of Karate maybe it's a bug?

karate-config.js

var dbService = Java.type('common.DBService');
config.db = new dbService();
return config;

// now db class and methods are available everywhere

from karate-maven-gradle.

kirksl avatar kirksl commented on July 16, 2024

Closing due to inactivity

from karate-maven-gradle.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.