Gradle project not reading from the karate-config.js
Closed this issue · 1 comments
I notice the gradle project created from scratch using IDE such as intellij doesn't seem to find the karate-config.js. This only happens to the gradle project. I have checked with the issue #2468 but it's very different from mine
Error
TestRunner > testParallel() FAILED
org.opentest4j.AssertionFailedError: js failed:
>>>>
01: baseUrl
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "baseUrl" is not defined
- <js>.:program(Unnamed:1)
How to reproduce
Create a project from intellij (if possible)
The build.gradle used is as the following:
plugins {
id 'java'
id 'idea'
}
group = 'com.djomeda.testing'
version = '1.0-SNAPSHOT'
ext {
karateVersion = '1.4.1'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
implementation "com.intuit.karate:karate-core:${karateVersion}"
testImplementation "com.intuit.karate:karate-junit5:${karateVersion}"
testImplementation 'net.masterthought:cucumber-reporting:5.8.1'
// testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
}
sourceSets {
test {
resources {
srcDir file('src/test/java')
exclude '**/*.java'
}
}
}
clean.doFirst {
delete("target/")
}
test {
useJUnitPlatform()
systemProperty "karate.options", System.properties.getProperty("karate.options")
systemProperty "karate.env", System.properties.getProperty("karate.env")
outputs.upToDateWhen { false }
}
task karateDebug(type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
// main = 'com.intuit.karate.cli.Main'
}
The Main class TestRunner.java is as the following, basically the same things as the mavn karate sample project
public class TestRunner {
@Test
void testParallel() {
Results results = Runner.path("classpath:com/tutorials/testing/karatetest")
//.outputCucumberJson(true)
.parallel(5);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
}
The root karate-config.js is also copied from the maven sample project
function fn() {
var env = karate.env; // get system property 'karate.env'
karate.log('karate.env system property was:', env);
if (!env) {
env = 'dev';
}
var config = {
env: env,
myVarName: 'someValue',
baseUrl: 'https://jsonplaceholder.typicode.com'
}
if (env == 'dev') {
// customize
// e.g. config.foo = 'bar';
} else if (env == 'e2e') {
// customize
}
return config;
}
if I run gradle :test --tests "com.tutorials.testing.karatetest.TestRunner" --info
expected
======================================================
elapsed: 2.69 | threads: 5 | thread time: 2.73
features: 1 | skipped: 0 | efficiency: 0.20
scenarios: 2 | passed: 2 | failed: 0
======================================================
actual
TestRunner > testParallel() FAILED
org.opentest4j.AssertionFailedError: js failed:
>>>>
01: baseUrl
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "baseUrl" is not defined
- <js>.:program(Unnamed:1)
classpath:com/tutorials/testing/karatetest/authentication/login.feature:5
js failed:
>>>>
01: baseUrl
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "baseUrl" is not defined
- <js>.:program(Unnamed:1)
classpath:com/tutorials/testing/karatetest/authentication/login.feature:5 ==> expected: <0> but was: <2>
at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:563)
at app//com.tutorials.testing.karatetest.TestRunner.testParallel(TestRunner.java:15)
I have attached the actual project. Grateful anyone can point out what is wrong ow what I am missing
karate-test.zip
@kdjomeda the karate-config.js
is in the wrong place
when it is moved to src/test/java
everything works fine. please refer to the docs, it is all explained there: https://github.com/karatelabs/karate#classpath