How to use relative or absolute file path in Karate.write function - karate

I am trying to write my contents into an external file. How to define your file path in the Karate.write(value, file) ?? (I am aware that it is not recommended from the framework perspective but I have to do some JMS activity with my customised Java functions. That is why I am trying to do this)

Anyone coming across this answer in the future, please read this first: https://stackoverflow.com/a/54593057/143475
Even if you need to do JMS, I don't understand why you need to write a file. Read the above link again if you need to please. Also Karate has support for async and we even have a JMS example here: https://github.com/intuit/karate/tree/master/karate-netty#consumer-provider-example
Finally: my strong advice to you: write a Java or JS utility yourself. Look at this example for hints: upload.feature especially this part:
* def FileChecker = Java.type('com.intuit.karate.demo.util.FileChecker')
# example of parsing a string into json by karate
* json fileInfo = FileChecker.getMetadata(id)
Here we are reading a file, but you get the idea.

Related

How to reuse Javascript functions(written in Feature file) in Karate from other .feature files

So for re usability, how can I reuse some particular amount of code from one feature file to other feature file.
I don't want to keep functions outside in js files.
As of now, this is not possible with karate.
IMHO, this is not even valid enhancement request. If you really want to reuse the code, it would be better idea to keep outside of feature file in js function and calling them from different feature files as and when needed.
Peter Thomas, author of Karate, mentioned here that reuse of feature is possible and one cannot reuse the particular scenario from feature file.
I don't want to keep functions outside in js files.
You don't have to. Please read the documentation. There are multiple ways for code-reuse:
the call keyword for re-usable features
Background / hooks
calling Java

How can I read a local file in Elm?

I'm exploring the idea of replacing an XML->XSLT->HTML workflow with Elm, just to see if I can do it. I found an Elm XML parser, and now I just need to figure out how to read a local file into Elm. I can't seem to find anything anywhere that explains how to do that. How would I go about doing that?
You can't directly read a file in Elm. Depending on your needs, you have a few options:
If your program only needs access to a static file, you can read in the file with Javascript and provide it to Elm as a flag (see here). This is the simplest way if it meets your needs.
If you need to react to changes in the file somehow, you could again read the file in with Javascript but communicate using ports (see here).
A possibly-simpler variation would be to stand up a web server that serves the file, and then interact with it in elm using HTTP requests (see here).

Reading data from .properties file in Karate DSL

We are trying to co exist with another java project which uses Webdriver etc. As part of this we would like to re use the same .properties file that is being used by other project for our configuration etc. Could some one guide us on reading from .properties file in Karate DSL.
There is nothing built in to Karate - but the solution for you is clear, write a simple Java utility to read a properties file - or since it is so simple, you should be able to do this even in JS, in the karate-config.js itself.
And also refer this: https://github.com/intuit/karate#calling-java
I haven't tested the below code, but you get the idea:
* def stream = read('classpath:myfile.properties')
* def props = new java.util.Properties()
* eval props.load(stream)

Get extention point contribution as text

Is there a way to get the raw XML text which another plugin has contributed to an extension point?
The normal way to access data that is contributed to an extension point is to use IConfigurationElement objects:
IConfigurationElement[] configElems = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LANGUAGES_EXTENTION_POINT_ID);
But I already have JAXB parser for the kind of data that is contributed to this extension point. I'd like to use that one instead of Eclipse's classes.
EDIT 1: An alternative would be to use some kind of Eclipse-configuratoin-to-JAXB bridge library. But I don't find any.
EDIT 2: It's probably possible to find the plugin.xml of the contributing plug-in and read that manually... Probably not a good idea.
EDIT 3: I think I will do this: Instead of contributing the data directly clients get to give a file name. I then read that file using my old parser.
No, I don't see anything that would give you the XML.
getConfigurationElementsFor gives you information extracted from many different plugin.xml files so it is not clear what XML could be returned anyway.
org.eclipse.core.internal.registry.ExtensionRegistry is the extension registry implementation, but a lot of the information that uses comes from org.eclipse.core.internal.registry.RegistryObjectManager.

Apache giraph process graph with a custom algorithm

I have a custom algorithm for processing a graph which accepts a txt file as input. Because it is a large scale graph I want to implement it in the apache giraph framework. I' ve done a lot of research but I am still not sure if I am in the right path.
I am reading a .csv file which contain the graph data and using a parser I am converting it to the txt file and uploading to the HDFS file system of hadoop.
I have read the SimpleShortestPathsVertex example from the apache quick start guide and I can see that processes the data from a file in HDFS using the jar-with-dependencies jar file.
My problem is that I haven't yet understood how can I add my algorithm in the apache giraph framework and start the process of the graph. Can I add my algorithm to apache framework using eclipse and modify it from there or there is any other way?
Thank you!
Have a look here:
https://cwiki.apache.org/confluence/display/GIRAPH/Shortest+Paths+Example
Where you able to run this example?
If yes.
Familiarize yourself with the different Writable formats of hadoop! Else it is hard to use these to your algorithm.
All computation concerning the graph is done in the compute() function.
(If you're more advanced have a look into the workerContext preSuperstep and Aggregators!)
You can change the example, but as soon as you use other data types you have to change your VertexReader and VertexWriter.
If you have a specific Algorithm in mind, make up your mind what you need for the computation and specify the layout of your input file. Then adapt your VertexReader and -Writer. And then finaly start the implement your compute() function!
Of course you can use eclipse! Simply Reference the Giraph jar (For me it is "giraph-0.1-jar-with-dependencies.jar") And start coding.
All you need is a instance of these files specific to your algorithm:
YourGiraphJob (the file starting the Hadoop/Giraph job)
YourVertex (Specifies your compute() function executed on each Vertex)
YourInputFormat (Specifying the Writable formats of YourReader)
YourOutputFormat (Specifying the Writable formats of YourWriter)
YourReader (Specifies how your inputFile is transformed e.g. that for each line a Vertex can be initialized using given information)
YourWriter (Specifies how your outputFile is generated from the vertices)
(optionaly a WorkerContext if you want to use Aggregators.)
Simply checkout: http://giraph.apache.org/source-repository.html
using eclipse and you should have the code including an example application you can toy around with!