karate
karate copied to clipboard
Add option to write gatling tests in Java
refer: https://gatling.io/docs/gatling/reference/current/whats_new/3.7/
avoiding the need for Scala would be a great improvement
@ptrthomas This would be an excellent improvement.
I would be really happy to see the java/gatling integration in karate. My naive tries to create the needed "bridge" parts failed because of my (not existing) Scala knowledge. Is there someone with Scala knowledge how can show me the way?
Hello,
I can take a look at this one, if it's ok...
Scala's concise syntax will not be easy to replace, but maybe we could try to define some kind of dsl instead?
For example:
protocol = karateProtocol(
"/cats/{id}" -> Nil,
"/cats" -> pauseFor("get" -> 15, "post" -> 25)
)
would be replaced by:
protocol = karateProtocol(patterns()
.uri("/cats/{id}").nil()
.uri("/cats").pauseFor("get", 15)
.pauseFor("post", 25)
);
@f-delahaye yes that sounds good, go ahead
I can't get karate-gatling to compile on develop (jdk17)...
[INFO] compiling 2 Scala sources and 1 Java source to D:\dev\karate\karate-gatling\target\test-classes ... [ERROR] D:\dev\karate\karate-gatling\src\test\scala\mock\MockUtils.java:3:24: error: package com.intuit.karate does not exist [ERROR] D:\dev\karate\karate-gatling\src\test\scala\mock\MockUtils.java:4:29: error: package com.intuit.karate.core does not exist [ERROR] D:\dev\karate\karate-gatling\src\test\scala\mock\MockUtils.java:24:69: error: cannot find symbol [ERROR] D:\dev\karate\karate-gatling\src\test\scala\mock\MockUtils.java:20:8: error: cannot find symbol [ERROR] D:\dev\karate\karate-gatling\src\test\scala\mock\MockUtils.java:20:28: error: cannot find symbol
Can't figure out what the problem is, karate-core compiles and is imported as a dependency...
Someone else have the same issue?
Never mind. There was a 'é' in my local repository's path. I moved it to a different folder and it's compiling again.
for those interested in trying this, 1.5.0.RC2 has been released
posted on social media
LinkedIn: https://www.linkedin.com/feed/update/urn:li:activity:7137691423725780992 Twitter: https://twitter.com/getkarate/status/1731926887595913593
1.5.0.RC3 is available, also the "karate-todo" example has been updated to use this approach: https://github.com/karatelabs/karate-todo/blob/d7d47ecd824904f51faaa826ef163ba92f32607a/src/test/java/app/perf/TodoSimulation.java
hi @ptrthomas, I am trying to rewrite the scala simulation file into java one and it looks like it doesn't pick urls and pathes that I defined in karate-config.js.
I am getting ReferenceError: "serverUrl" is not defined.
Path to config is set via plugin configuration like:
<configFolder>src/test/java/${gatlingConfig}</configFolder>
Would appreciate the help, thanks
Also did I understand from the code correctly, that setting call names is not supported yet for Java DSL?
* header karate-name = 'Initiate Login flow'
karateProtocol(
uri("Initiate Login flow").pauseFor("get", TIMEOUT_1000),
will let @f-delahaye answer. I was able to get the karate-todo
example to work as I commented above
Hi, I will take a look asap.
As a workaround for "serverUrl" is not defined
I am reading karate-config.js into variable "*def config = ..." instide .feature file and then referencing it, so not a huge deal, but being able to remap call names from "POST /bla/bla" into meaningfull names with header karate-name
very desirable feature to have it back -_-
@borzykin Maybe what you're looking for is nameResolver
?
It is still available but you may need to change your code to:
KarateProtocolBuilder protocolBuilder = karateProtocol(uri("/bla/bla").pauseFor("get", 1000));
protocolBuilder.nameResolver = (req, ctx) -> req.getHeader("karate-name");
KarateProtocol protocol = protocolBuilder.protocol();
If you're using it in a different way, could you please share an example?
Anyway, I will raise a PR for a more fluent api, something like:
KarateProtocol protocol =
karateProtocol(uri("/bla/bla")
.pauseFor("get", 1000)
.nameResolver = (req, ctx) -> req.getHeader("karate-name"))
protocol();
As a workaround for
"serverUrl" is not defined
I am reading karate-config.js into variable "*def config = ..." instide .feature file and then referencing it, so not a huge deal, but being able to remap call names from "POST /bla/bla" into meaningfull names withheader karate-name
very desirable feature to have it back -_-
Good to hear you found a workaround!
However, do you have any reason to believe this "serverUrl" is not defined
is caused by the gatling java dsl?
As far as I know, karate-config.js is loaded by the Karate core engine.
Unless it's something to do with what you said in your initial post
Path to config is set via plugin configuration like: <configFolder>src/test/java/${gatlingConfig}</configFolder>
but then could you please give a bit more details?
Many thanks
@f-delahaye changing the code to your example fixed the issues with the name resolver, thanks a lot as for URL issue I will play with it a bit more to find more details
@borzykin PR for new fluent api: https://github.com/karatelabs/karate/pull/2525
@f-delahaye @ptrthomas I am not sure that problem is due to gatliung DSL via Java, just trying to point out problem for people who seems to care enough to try to understand :) As fo URL problem, I cloned example project, and in the simple.feature file when I comment out this line:
* def urlBase = karate.properties['url.base'] || karate.get('urlBase', 'http://localhost:8080')
and just hardcode let urlBase = "http://localhost:8080";
in karate-config.perf.js
= I am start getting same error that URL is not defined, even though it is difened in config.
If I add this line to the simple.feature:
* call read("classpath:../karate-config-perf.js")
It start to work fine again. I am not competent enough to say it is correct behaviour or not, just pointing out that used to work on 1.4.1 version without this hacks
I am start getting same error that URL is not defined, even though it is difened in config.
That makes sense. As far as I know, karate-config-perf.js is not read by default unless the vm arg -Dkarate.env=perf
is specified.
Anyway, back to your initial problem, which probably has nothing to do with the karate-todo example or karate-config-perf.js ;) Please create another issue with a reproduceable example as explained here and someone will take a look. And please don't forget the last step (provide the exact command to run and reproduce the problem locally) which might be helpful in your case.
Hello @ptrthomas , is there an java example for this feature ? I tried many ways but still not work. I want to use java to write gatling test.
@fingerdancer https://github.com/karatelabs/karate-todo/blob/d7d47ecd824904f51faaa826ef163ba92f32607a/src/test/java/app/perf/TodoSimulation.java
1.5.0 released