Caused by: com.intuit.karate.exception.KarateException: ReferenceError: “XMLHttpRequest” is not defined...












1















I want to load my configurations from server but when I am doing using



XMLHttpRequest I am getting Exception




ava.lang.RuntimeException: evaluation of 'karate-config.js' failed
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:211)
at com.intuit.karate.StepActions.(StepActions.java:50)
at com.intuit.karate.core.FeatureExecutionUnit.submit(FeatureExecutionUnit.java:85)
at com.intuit.karate.cucumber.CucumberRunner.callAsync(CucumberRunner.java:191)
at com.intuit.karate.gatling.KarateAction.execute(KarateAction.scala:62)
at io.gatling.core.action.Action.$bang(Action.scala:35)
at io.gatling.core.action.Action.$bang$(Action.scala:35)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ChainableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ChainableAction.$bang(Action.scala:60)
at io.gatling.core.action.ChainableAction.$bang$(Action.scala:58)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ExitableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ExitableAction.$bang(BlockExit.scala:137)
at io.gatling.core.action.ExitableAction.$bang$(BlockExit.scala:135)
at com.intuit.karate.gatling.KarateAction.$bang(KarateAction.scala:26)
at io.gatling.core.controller.inject.Injector.startUser(Injector.scala:130)
at io.gatling.core.controller.inject.Injector.injectUser(Injector.scala:140)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2$adapted(Injector.scala:120)
at io.gatling.core.controller.inject.UserStream.withStream(Injector.scala:61)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$1(Injector.scala:120)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.MapLike$DefaultValuesIterable.foreach(MapLike.scala:210)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at io.gatling.core.controller.inject.Injector.injectStreams(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.io$gatling$core$controller$inject$Injector$$inject(Injector.scala:106)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:151)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:148)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
at akka.actor.FSM.processEvent(FSM.scala:665)
at akka.actor.FSM.processEvent$(FSM.scala:662)
at io.gatling.core.controller.inject.InjectorFSM.processEvent(InjectorFSM.scala:34)
at akka.actor.FSM.akka$actor$FSM$$processMsg(FSM.scala:659)
at akka.actor.FSM$$anonfun$receive$1.applyOrElse(FSM.scala:653)
at akka.actor.Actor.aroundReceive(Actor.scala:514)
at akka.actor.Actor.aroundReceive$(Actor.scala:512)
at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:23)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527)
at akka.actor.ActorCell.invoke(ActorCell.scala:496)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: com.intuit.karate.exception.KarateException: javascript
function call failed: ReferenceError: "XMLHttpRequest" is not defined
at com.intuit.karate.Script.evalFunctionCall(Script.java:1636)
at com.intuit.karate.Script.call(Script.java:1587)
at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1709)
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:206)






My config File Code :






function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}












share|improve this question

























  • Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

    – Ethan Kaminski
    Nov 26 '18 at 12:13











  • I am using karate with gatling.

    – MrStrange
    Nov 26 '18 at 12:40
















1















I want to load my configurations from server but when I am doing using



XMLHttpRequest I am getting Exception




ava.lang.RuntimeException: evaluation of 'karate-config.js' failed
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:211)
at com.intuit.karate.StepActions.(StepActions.java:50)
at com.intuit.karate.core.FeatureExecutionUnit.submit(FeatureExecutionUnit.java:85)
at com.intuit.karate.cucumber.CucumberRunner.callAsync(CucumberRunner.java:191)
at com.intuit.karate.gatling.KarateAction.execute(KarateAction.scala:62)
at io.gatling.core.action.Action.$bang(Action.scala:35)
at io.gatling.core.action.Action.$bang$(Action.scala:35)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ChainableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ChainableAction.$bang(Action.scala:60)
at io.gatling.core.action.ChainableAction.$bang$(Action.scala:58)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ExitableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ExitableAction.$bang(BlockExit.scala:137)
at io.gatling.core.action.ExitableAction.$bang$(BlockExit.scala:135)
at com.intuit.karate.gatling.KarateAction.$bang(KarateAction.scala:26)
at io.gatling.core.controller.inject.Injector.startUser(Injector.scala:130)
at io.gatling.core.controller.inject.Injector.injectUser(Injector.scala:140)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2$adapted(Injector.scala:120)
at io.gatling.core.controller.inject.UserStream.withStream(Injector.scala:61)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$1(Injector.scala:120)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.MapLike$DefaultValuesIterable.foreach(MapLike.scala:210)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at io.gatling.core.controller.inject.Injector.injectStreams(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.io$gatling$core$controller$inject$Injector$$inject(Injector.scala:106)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:151)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:148)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
at akka.actor.FSM.processEvent(FSM.scala:665)
at akka.actor.FSM.processEvent$(FSM.scala:662)
at io.gatling.core.controller.inject.InjectorFSM.processEvent(InjectorFSM.scala:34)
at akka.actor.FSM.akka$actor$FSM$$processMsg(FSM.scala:659)
at akka.actor.FSM$$anonfun$receive$1.applyOrElse(FSM.scala:653)
at akka.actor.Actor.aroundReceive(Actor.scala:514)
at akka.actor.Actor.aroundReceive$(Actor.scala:512)
at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:23)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527)
at akka.actor.ActorCell.invoke(ActorCell.scala:496)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: com.intuit.karate.exception.KarateException: javascript
function call failed: ReferenceError: "XMLHttpRequest" is not defined
at com.intuit.karate.Script.evalFunctionCall(Script.java:1636)
at com.intuit.karate.Script.call(Script.java:1587)
at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1709)
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:206)






My config File Code :






function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}












share|improve this question

























  • Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

    – Ethan Kaminski
    Nov 26 '18 at 12:13











  • I am using karate with gatling.

    – MrStrange
    Nov 26 '18 at 12:40














1












1








1








I want to load my configurations from server but when I am doing using



XMLHttpRequest I am getting Exception




ava.lang.RuntimeException: evaluation of 'karate-config.js' failed
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:211)
at com.intuit.karate.StepActions.(StepActions.java:50)
at com.intuit.karate.core.FeatureExecutionUnit.submit(FeatureExecutionUnit.java:85)
at com.intuit.karate.cucumber.CucumberRunner.callAsync(CucumberRunner.java:191)
at com.intuit.karate.gatling.KarateAction.execute(KarateAction.scala:62)
at io.gatling.core.action.Action.$bang(Action.scala:35)
at io.gatling.core.action.Action.$bang$(Action.scala:35)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ChainableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ChainableAction.$bang(Action.scala:60)
at io.gatling.core.action.ChainableAction.$bang$(Action.scala:58)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ExitableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ExitableAction.$bang(BlockExit.scala:137)
at io.gatling.core.action.ExitableAction.$bang$(BlockExit.scala:135)
at com.intuit.karate.gatling.KarateAction.$bang(KarateAction.scala:26)
at io.gatling.core.controller.inject.Injector.startUser(Injector.scala:130)
at io.gatling.core.controller.inject.Injector.injectUser(Injector.scala:140)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2$adapted(Injector.scala:120)
at io.gatling.core.controller.inject.UserStream.withStream(Injector.scala:61)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$1(Injector.scala:120)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.MapLike$DefaultValuesIterable.foreach(MapLike.scala:210)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at io.gatling.core.controller.inject.Injector.injectStreams(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.io$gatling$core$controller$inject$Injector$$inject(Injector.scala:106)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:151)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:148)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
at akka.actor.FSM.processEvent(FSM.scala:665)
at akka.actor.FSM.processEvent$(FSM.scala:662)
at io.gatling.core.controller.inject.InjectorFSM.processEvent(InjectorFSM.scala:34)
at akka.actor.FSM.akka$actor$FSM$$processMsg(FSM.scala:659)
at akka.actor.FSM$$anonfun$receive$1.applyOrElse(FSM.scala:653)
at akka.actor.Actor.aroundReceive(Actor.scala:514)
at akka.actor.Actor.aroundReceive$(Actor.scala:512)
at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:23)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527)
at akka.actor.ActorCell.invoke(ActorCell.scala:496)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: com.intuit.karate.exception.KarateException: javascript
function call failed: ReferenceError: "XMLHttpRequest" is not defined
at com.intuit.karate.Script.evalFunctionCall(Script.java:1636)
at com.intuit.karate.Script.call(Script.java:1587)
at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1709)
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:206)






My config File Code :






function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}












share|improve this question
















I want to load my configurations from server but when I am doing using



XMLHttpRequest I am getting Exception




ava.lang.RuntimeException: evaluation of 'karate-config.js' failed
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:211)
at com.intuit.karate.StepActions.(StepActions.java:50)
at com.intuit.karate.core.FeatureExecutionUnit.submit(FeatureExecutionUnit.java:85)
at com.intuit.karate.cucumber.CucumberRunner.callAsync(CucumberRunner.java:191)
at com.intuit.karate.gatling.KarateAction.execute(KarateAction.scala:62)
at io.gatling.core.action.Action.$bang(Action.scala:35)
at io.gatling.core.action.Action.$bang$(Action.scala:35)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ChainableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ChainableAction.$bang(Action.scala:60)
at io.gatling.core.action.ChainableAction.$bang$(Action.scala:58)
at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ExitableAction$$super$$bang(KarateAction.scala:26)
at io.gatling.core.action.ExitableAction.$bang(BlockExit.scala:137)
at io.gatling.core.action.ExitableAction.$bang$(BlockExit.scala:135)
at com.intuit.karate.gatling.KarateAction.$bang(KarateAction.scala:26)
at io.gatling.core.controller.inject.Injector.startUser(Injector.scala:130)
at io.gatling.core.controller.inject.Injector.injectUser(Injector.scala:140)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$2$adapted(Injector.scala:120)
at io.gatling.core.controller.inject.UserStream.withStream(Injector.scala:61)
at io.gatling.core.controller.inject.Injector.$anonfun$injectStreams$1(Injector.scala:120)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.MapLike$DefaultValuesIterable.foreach(MapLike.scala:210)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at io.gatling.core.controller.inject.Injector.injectStreams(Injector.scala:120)
at io.gatling.core.controller.inject.Injector.io$gatling$core$controller$inject$Injector$$inject(Injector.scala:106)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:151)
at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:148)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
at akka.actor.FSM.processEvent(FSM.scala:665)
at akka.actor.FSM.processEvent$(FSM.scala:662)
at io.gatling.core.controller.inject.InjectorFSM.processEvent(InjectorFSM.scala:34)
at akka.actor.FSM.akka$actor$FSM$$processMsg(FSM.scala:659)
at akka.actor.FSM$$anonfun$receive$1.applyOrElse(FSM.scala:653)
at akka.actor.Actor.aroundReceive(Actor.scala:514)
at akka.actor.Actor.aroundReceive$(Actor.scala:512)
at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:23)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527)
at akka.actor.ActorCell.invoke(ActorCell.scala:496)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: com.intuit.karate.exception.KarateException: javascript
function call failed: ReferenceError: "XMLHttpRequest" is not defined
at com.intuit.karate.Script.evalFunctionCall(Script.java:1636)
at com.intuit.karate.Script.call(Script.java:1587)
at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1709)
at com.intuit.karate.ScenarioContext.(ScenarioContext.java:206)






My config File Code :






function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}








function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}





function () {
var System = Java.type('java.lang.System');
var env = System.getProperty("profile");
if (!env) {
karate.log('env is not defined.')
env = 'dev';
}
var request = new XMLHttpRequest();
request.open("GET", "http://www.testsite.com",false);
request.send();
var result = request.responseText;
console.log(result);
return result
}






javascript java karate






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 12:49









Ethan Kaminski

423310




423310










asked Nov 26 '18 at 12:08









MrStrangeMrStrange

102




102













  • Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

    – Ethan Kaminski
    Nov 26 '18 at 12:13











  • I am using karate with gatling.

    – MrStrange
    Nov 26 '18 at 12:40



















  • Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

    – Ethan Kaminski
    Nov 26 '18 at 12:13











  • I am using karate with gatling.

    – MrStrange
    Nov 26 '18 at 12:40

















Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

– Ethan Kaminski
Nov 26 '18 at 12:13





Are you programming in Java or in JavaScript? Those are two completely unrelated (and incompatible!) languages, but it looks like you've got both of them in this one file.

– Ethan Kaminski
Nov 26 '18 at 12:13













I am using karate with gatling.

– MrStrange
Nov 26 '18 at 12:40





I am using karate with gatling.

– MrStrange
Nov 26 '18 at 12:40












2 Answers
2






active

oldest

votes


















1














var request = new XMLHttpRequest();


Sorry, that's not going to work. Karate supports just ES2015 and plain JS.



Also:



request.open("GET", "http://www.testsite.com",false);


That's totally un-necessary, since Karate's speciality is making HTTP requests ! Please read the docs more carefully. For example you can do this in a *.feature file:



Feature:

Scenario:
Given url 'http://www.testsite.com'
When method get
Then status 200
And def result = response
And print result


And are you sure you have to do this in karate-config.js ? Sounds like you are completely new to Karate - but if so, you can do: var result = karate.call('my.feature');.






share|improve this answer































    0














    I also have the same issue.
    Because I want to send notice when Scenario execute failed, like this:



    Feature:

    Background:
    * url baseApi
    * configure afterScenario =
    """
    function() {
    if (karate.info.errorMessage != null) {
    callback();
    }
    }
    """
    * configure retry = { count: 3, interval: 3000 }

    Scenario: get it (ERROR)
    * def input =
    """
    {
    'form': {
    'id': '123509638998',
    'td': '5xm6ksy6ty2jqam',
    'nd': '0'
    },
    'query': {
    }
    }
    """
    * path '/rest/n/list'
    * params input.query
    * form fields input.form
    * retry until responseStatus == 200
    * method post
    * match response contains { result: 1 }


    And karate-config.js like this:



    function() {
    karate.configure('connectTimeout', 5000);
    karate.configure('readTimeout', 5000);
    var url = 'http://127.0.0.1:8088';
    if (karate.properties['apiServer'] != '') {
    url = karate.properties['apiServer'];
    }

    var config = {
    apiBaseUrl: url,
    callback: function() {
    var url = 'https://x.y.z.com/api/send?access_token=257def70cab07fda4e93efeae04c497d';

    var data = JSON.stringify({
    'id': '123',
    'msgtype': 'text',
    'text':{
    'content': 'Test message...'
    }
    });

    fetch(url, {
    headers: { "Content-Type": "application/json; charset=utf-8" },
    method: 'POST',
    body: data
    })
    }
    };

    return config;
    }





    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480810%2fcaused-by-com-intuit-karate-exception-karateexception-referenceerror-xmlhttp%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      var request = new XMLHttpRequest();


      Sorry, that's not going to work. Karate supports just ES2015 and plain JS.



      Also:



      request.open("GET", "http://www.testsite.com",false);


      That's totally un-necessary, since Karate's speciality is making HTTP requests ! Please read the docs more carefully. For example you can do this in a *.feature file:



      Feature:

      Scenario:
      Given url 'http://www.testsite.com'
      When method get
      Then status 200
      And def result = response
      And print result


      And are you sure you have to do this in karate-config.js ? Sounds like you are completely new to Karate - but if so, you can do: var result = karate.call('my.feature');.






      share|improve this answer




























        1














        var request = new XMLHttpRequest();


        Sorry, that's not going to work. Karate supports just ES2015 and plain JS.



        Also:



        request.open("GET", "http://www.testsite.com",false);


        That's totally un-necessary, since Karate's speciality is making HTTP requests ! Please read the docs more carefully. For example you can do this in a *.feature file:



        Feature:

        Scenario:
        Given url 'http://www.testsite.com'
        When method get
        Then status 200
        And def result = response
        And print result


        And are you sure you have to do this in karate-config.js ? Sounds like you are completely new to Karate - but if so, you can do: var result = karate.call('my.feature');.






        share|improve this answer


























          1












          1








          1







          var request = new XMLHttpRequest();


          Sorry, that's not going to work. Karate supports just ES2015 and plain JS.



          Also:



          request.open("GET", "http://www.testsite.com",false);


          That's totally un-necessary, since Karate's speciality is making HTTP requests ! Please read the docs more carefully. For example you can do this in a *.feature file:



          Feature:

          Scenario:
          Given url 'http://www.testsite.com'
          When method get
          Then status 200
          And def result = response
          And print result


          And are you sure you have to do this in karate-config.js ? Sounds like you are completely new to Karate - but if so, you can do: var result = karate.call('my.feature');.






          share|improve this answer













          var request = new XMLHttpRequest();


          Sorry, that's not going to work. Karate supports just ES2015 and plain JS.



          Also:



          request.open("GET", "http://www.testsite.com",false);


          That's totally un-necessary, since Karate's speciality is making HTTP requests ! Please read the docs more carefully. For example you can do this in a *.feature file:



          Feature:

          Scenario:
          Given url 'http://www.testsite.com'
          When method get
          Then status 200
          And def result = response
          And print result


          And are you sure you have to do this in karate-config.js ? Sounds like you are completely new to Karate - but if so, you can do: var result = karate.call('my.feature');.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 12:18









          Peter ThomasPeter Thomas

          16k32051




          16k32051

























              0














              I also have the same issue.
              Because I want to send notice when Scenario execute failed, like this:



              Feature:

              Background:
              * url baseApi
              * configure afterScenario =
              """
              function() {
              if (karate.info.errorMessage != null) {
              callback();
              }
              }
              """
              * configure retry = { count: 3, interval: 3000 }

              Scenario: get it (ERROR)
              * def input =
              """
              {
              'form': {
              'id': '123509638998',
              'td': '5xm6ksy6ty2jqam',
              'nd': '0'
              },
              'query': {
              }
              }
              """
              * path '/rest/n/list'
              * params input.query
              * form fields input.form
              * retry until responseStatus == 200
              * method post
              * match response contains { result: 1 }


              And karate-config.js like this:



              function() {
              karate.configure('connectTimeout', 5000);
              karate.configure('readTimeout', 5000);
              var url = 'http://127.0.0.1:8088';
              if (karate.properties['apiServer'] != '') {
              url = karate.properties['apiServer'];
              }

              var config = {
              apiBaseUrl: url,
              callback: function() {
              var url = 'https://x.y.z.com/api/send?access_token=257def70cab07fda4e93efeae04c497d';

              var data = JSON.stringify({
              'id': '123',
              'msgtype': 'text',
              'text':{
              'content': 'Test message...'
              }
              });

              fetch(url, {
              headers: { "Content-Type": "application/json; charset=utf-8" },
              method: 'POST',
              body: data
              })
              }
              };

              return config;
              }





              share|improve this answer




























                0














                I also have the same issue.
                Because I want to send notice when Scenario execute failed, like this:



                Feature:

                Background:
                * url baseApi
                * configure afterScenario =
                """
                function() {
                if (karate.info.errorMessage != null) {
                callback();
                }
                }
                """
                * configure retry = { count: 3, interval: 3000 }

                Scenario: get it (ERROR)
                * def input =
                """
                {
                'form': {
                'id': '123509638998',
                'td': '5xm6ksy6ty2jqam',
                'nd': '0'
                },
                'query': {
                }
                }
                """
                * path '/rest/n/list'
                * params input.query
                * form fields input.form
                * retry until responseStatus == 200
                * method post
                * match response contains { result: 1 }


                And karate-config.js like this:



                function() {
                karate.configure('connectTimeout', 5000);
                karate.configure('readTimeout', 5000);
                var url = 'http://127.0.0.1:8088';
                if (karate.properties['apiServer'] != '') {
                url = karate.properties['apiServer'];
                }

                var config = {
                apiBaseUrl: url,
                callback: function() {
                var url = 'https://x.y.z.com/api/send?access_token=257def70cab07fda4e93efeae04c497d';

                var data = JSON.stringify({
                'id': '123',
                'msgtype': 'text',
                'text':{
                'content': 'Test message...'
                }
                });

                fetch(url, {
                headers: { "Content-Type": "application/json; charset=utf-8" },
                method: 'POST',
                body: data
                })
                }
                };

                return config;
                }





                share|improve this answer


























                  0












                  0








                  0







                  I also have the same issue.
                  Because I want to send notice when Scenario execute failed, like this:



                  Feature:

                  Background:
                  * url baseApi
                  * configure afterScenario =
                  """
                  function() {
                  if (karate.info.errorMessage != null) {
                  callback();
                  }
                  }
                  """
                  * configure retry = { count: 3, interval: 3000 }

                  Scenario: get it (ERROR)
                  * def input =
                  """
                  {
                  'form': {
                  'id': '123509638998',
                  'td': '5xm6ksy6ty2jqam',
                  'nd': '0'
                  },
                  'query': {
                  }
                  }
                  """
                  * path '/rest/n/list'
                  * params input.query
                  * form fields input.form
                  * retry until responseStatus == 200
                  * method post
                  * match response contains { result: 1 }


                  And karate-config.js like this:



                  function() {
                  karate.configure('connectTimeout', 5000);
                  karate.configure('readTimeout', 5000);
                  var url = 'http://127.0.0.1:8088';
                  if (karate.properties['apiServer'] != '') {
                  url = karate.properties['apiServer'];
                  }

                  var config = {
                  apiBaseUrl: url,
                  callback: function() {
                  var url = 'https://x.y.z.com/api/send?access_token=257def70cab07fda4e93efeae04c497d';

                  var data = JSON.stringify({
                  'id': '123',
                  'msgtype': 'text',
                  'text':{
                  'content': 'Test message...'
                  }
                  });

                  fetch(url, {
                  headers: { "Content-Type": "application/json; charset=utf-8" },
                  method: 'POST',
                  body: data
                  })
                  }
                  };

                  return config;
                  }





                  share|improve this answer













                  I also have the same issue.
                  Because I want to send notice when Scenario execute failed, like this:



                  Feature:

                  Background:
                  * url baseApi
                  * configure afterScenario =
                  """
                  function() {
                  if (karate.info.errorMessage != null) {
                  callback();
                  }
                  }
                  """
                  * configure retry = { count: 3, interval: 3000 }

                  Scenario: get it (ERROR)
                  * def input =
                  """
                  {
                  'form': {
                  'id': '123509638998',
                  'td': '5xm6ksy6ty2jqam',
                  'nd': '0'
                  },
                  'query': {
                  }
                  }
                  """
                  * path '/rest/n/list'
                  * params input.query
                  * form fields input.form
                  * retry until responseStatus == 200
                  * method post
                  * match response contains { result: 1 }


                  And karate-config.js like this:



                  function() {
                  karate.configure('connectTimeout', 5000);
                  karate.configure('readTimeout', 5000);
                  var url = 'http://127.0.0.1:8088';
                  if (karate.properties['apiServer'] != '') {
                  url = karate.properties['apiServer'];
                  }

                  var config = {
                  apiBaseUrl: url,
                  callback: function() {
                  var url = 'https://x.y.z.com/api/send?access_token=257def70cab07fda4e93efeae04c497d';

                  var data = JSON.stringify({
                  'id': '123',
                  'msgtype': 'text',
                  'text':{
                  'content': 'Test message...'
                  }
                  });

                  fetch(url, {
                  headers: { "Content-Type": "application/json; charset=utf-8" },
                  method: 'POST',
                  body: data
                  })
                  }
                  };

                  return config;
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 25 at 9:45









                  thinkerouthinkerou

                  7962822




                  7962822






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480810%2fcaused-by-com-intuit-karate-exception-karateexception-referenceerror-xmlhttp%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen