How to use karate.get in Java with Karate Framework? - karate

in javascript I use karate.get('key') but how to use this feature in Java please?

It is not supported.
What teams typically do is pass the data they need to the Java side via function arguments.

Related

What is the equivalent of karate.get() in Java?

I have created a Java object in karate scripts using Java interop and have used it as required.
Now, I want to retrieve that same instance in another Java class. Is there a way to do that?
In karate, we have an equivalent method like karate.get('objectName'). Is there any equivalent API available in Karate lib?
Please assume that the answer is no. I'd like to mention that the whole point of creating Karate was to avoid using Java for API test automation. I say this because I suspect based on your questions that you have made the same mistake I've seen a few other teams make - which is attempting to make Karate work like the Seleniums and Rest Assureds of the world. That always ends badly. And what's worse is that these teams blame Karate for that and go around telling everyone. I'd rather have that not happen - so if this is a "blocker" please consider using some other tool.
If you are already calling Java, you have plenty of ways to pass objects around right? Just use that and don't over-complicate your tests. Or you can use the "singleton" pattern, nothing to do with Karate, you can look it up.

Mule ESB : Which has better performance -- scripts (java script,groovy,ognl etc ) or java code through Java component or transformer

I had this question in mind for long time and am jotting it down now.
Which will be a best practice or has an edge over others while transforming or processing data in Mule ESB. I am curious to differentiate between the following components.
Java Script
Groovy Script
Other allowed scripts
VS
Java Component or Java Transformer
Usually any ESB should provide various options for the transformations and Mule also provides a lot of ways and methodologies for transformation.
I am curios to know which is better for some of the common situations.
For example check the scenarios for below.
Calling a java component to chunk out a list from an object and make that list as the payload VS using OGNL in set payload component.
OGNL is being deprecated in Mule.
Regarding Javascript vs Groovy vs MEL (MVEL) I would say it depends.
MEL scripts are the faster to start (find here some performance benchmarks), followed by Javascript (Mule still does not use Java 8's Nashorn) and followed by Groovy.
However, for very big tasks where initialization doens't matter that much groovy might still perform faster.
Anyhow, for almost the 100% of the cases, Java components, on equivalent tasks will perform faster than any other binding. This is due that Mule is written in Java and is doing straight API calls without using bindings or adaptations.

Grails functional test dependency injection

I am quite new to Grails, but I am using this plugin for functional testing:
http://www.grails.org/Grails%20Functional%20Testing
I am wondering how to inject a service such as the messageSource or or the applicationContext so I can have access to different resources. A simple example would be that I want to write a functional test to check if the text on the website is equal to the message string in the messages.properties file. Right now I cant seem to find an out of the box way of doing that. Can you advice on something? Also is that the best functional testing framework for grails since its quite limited?
You may want to try Geb instead it is a good framework that has nice support and good docs. But the one items to remember is that functional tests are running against the full stack so some tests you may find work better as integration or unit tests.
You can use the remote control plugin in grails to modify your grails application on the fly. It uses the groovy remote control mechanism and serializes results for functional tests

Access KV store and Environment Variables in G-WAN using MONO

I got mono 3.0.6 working with G-WAN and now I am trying to use G-WAN persistent pointers and KV Store using mono but don't know how to do it.
G-WAN does expose some functions on gwan_api.cs but the KV function and get_env is not there.
Is it possible to access this in mono?
Is it possible to access G-WAN's KV store in C# scripts?
No, and here is why.
We initially tried the wrappers we wrote but, like for JNI, the mandatory conversion overhead is defeating the purpose of light and fast calls.
Like Java, C# offers a plethora of solutions for almost everything G-WAN does natively and this is what should be used if you use either language.
Note that part of your application can be written in C/C++/D/Objective-C/Objective-C++ and call all the native G-WAN API directly while the rest of your application may use C# or Java.
That's the advantage for an Application Server to support different programming languages.

How do I access/read the Phonegap API?

I know there is this: http://docs.phonegap.com/en/2.1.0/index.html but it doesn't really help.
I am trying to learn about the appView variable (I think it's a variable). I would've said it was a class but it starts with a lower case letter :/
The reason I am trying to learn that is because I am trying to understand the appView.addJavascriptInterface(Object, String) method.
My main goal is to send a variable from a java file to a javascript file. Tutorials online seem to be using the method stated above. Because the method takes in an object, the tutorials seem to be creating another class. I want to simplify my code as much as possible so I was seeing if there are any other options.
You will want to write a Plugin. We've already gone through the pain of the JS to Java and back to JS communication. If you purely use addJavaScriptInterface you will run into some edge cases where it doesn't work and we already guard against.
In appView.addJavascriptInterface(Object, String) method Object refers to Java object from which you want to transfer data from Java to java script.
You can't achieve functionality without creating new class.
Apart from Plugin usage above mentioned way only we can achieve communication between java and javascript in phonegap apps.