gradlekarate

Karate and Gatling with Gradle : Run crashed


Unable to run user defined simulation class as simulation class could be loaded

task gatlingRun(type: JavaExec) {
group = 'Web Tests'
description = 'Run Gatling Tests'
new File("${buildDir}/reports/gatling").mkdirs()
classpath = sourceSets.test.runtimeClasspath
main = "io.gatling.app.Gatling"
args = [
        // change this to suit your simulation entry-point
        '-s', 'performance.userSimulationIpay',
        '-rf', "${buildDir}/reports/gatling"
]
systemProperties System.properties}

This is the task added to gradle.build file and I am using gradle version 6.9.1

enter image description here

This is the karate framework structure. Also I have created the same test with maven build tool and the performance test working as expected, getting this issue when I am using gradle build tool. As the client requirment we have to migrate from maven to gradle but getting this exception when I execute the following command from terminal.

enter image description here

The exception I am getting is :

 D:\Users\bakh\Automation\nlp_latest\AUT-Karate>gradle gatling

> Task :gatlingRun
18:08:56.346 [main] INFO  i.g.c.config.GatlingConfiguration$ - Gatling will try to use 'gatling.conf' as config file.
18:09:02.092 [GatlingSystem-akka.actor.default-dispatcher-6] INFO  akka.event.slf4j.Slf4jLogger - Slf4jLogger started
18:09:11.785 [main] ERROR io.gatling.app.Gatling$ - Run crashed
java.lang.IllegalArgumentException: User defined Simulation class performance.userSimulationIpay could not be loaded
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:80)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:85)
        at scala.Option.orElse(Option.scala:477)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:85)
        at scala.Option.flatMap(Option.scala:283)
        at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:83)
        at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:52)
        at scala.Option.getOrElse(Option.scala:201)
        at io.gatling.app.Selection$Selector.selection(Selection.scala:44)
        at io.gatling.app.Selection$.apply(Selection.scala:36)
        at io.gatling.app.Runner.run0(Runner.scala:61)
        at io.gatling.app.Runner.run(Runner.scala:49)
        at io.gatling.app.Gatling$.start(Gatling.scala:83)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:45)
        at io.gatling.app.Gatling$.main(Gatling.scala:37)
        at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: performance.userSimulationIpay
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:71)
        at scala.util.Try$.apply(Try.scala:210)
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:71)
        ... 15 common frames omitted
Exception in thread "main" java.lang.IllegalArgumentException: User defined Simulation class performance.userSimulationIpay could not be loaded
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:80)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:85)
        at scala.Option.orElse(Option.scala:477)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:85)
        at scala.Option.flatMap(Option.scala:283)
        at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:83)
        at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:52)
        at scala.Option.getOrElse(Option.scala:201)
        at io.gatling.app.Selection$Selector.selection(Selection.scala:44)
        at io.gatling.app.Selection$.apply(Selection.scala:36)
        at io.gatling.app.Runner.run0(Runner.scala:61)
        at io.gatling.app.Runner.run(Runner.scala:49)
        at io.gatling.app.Gatling$.start(Gatling.scala:83)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:45)
        at io.gatling.app.Gatling$.main(Gatling.scala:37)
        at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: performance.userSimulationIpay
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:71)
        at scala.util.Try$.apply(Try.scala:210)
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:71)
        ... 15 more

> Task :gatlingRun FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gatlingRun'.
> Process 'command 'C:\Program Files\Amazon Corretto\jdk1.8.0_282\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 26s

Solution

  • Try moving your simulation to a dedicated sourceSet named "gatling" with a sub-directory of "scala" (since your simulations are written in scala, not java), and following the instructions here: https://docs.gatling.io/reference/integrations/build-tools/gradle-plugin/