Cucumber Java using dataprovider - cucumber-java

I have gone through all possible solutions online to implement data provider facility using cucumber, but all are either incomplete or not working. Can anyone please suggest a working solution to read data from an external source such as an excel or CSV? How is it used in the step defs and feature file?

Exact code might be difficult to share at the moment. But following approach should work for you. Cucumber has Interface called as Transformer which you need to implement. THe transformer implementation should be accepted as step definitions arguments. E.g.,
#Given("your text <regex>")
public void someMethod(TransformerImpl transformerImpl) {
//your code goes here
}
The TranformerImpl is the implementation of Transformer interface. In that interface you will implement the logic of taking the csv file path or name and read its content and pass its data to the step definition as argument.
Let me know if this helps.

Related

Custom type conversion in Karate

As Karate supports type conversion, I was wondering if it is possible to write a custom type conversion in such a way that I could write something similar to this in my .feature file
customType customTypeResponse = response
which should have the same semantic as
yaml yamlResponse = response
but for customType instead of yaml.
I think I found the code enabling the custom type conversion. But I am not sure about the extensibility.
Thus the shortest way might be to use the Java interop enabling something like this
def customTypeResponse = CustomType.convert(response)
Please let me know of any possibiliy of type conversion.
Yes, I strongly suggest just using Java interop and not complicating it further for now. Maybe in the future we'll have a better way to do contribute custom syntax (hint: look for the Plugin interface and how karate-robot uses it).

Creating libraries that can be imported and used in Groovy

Currently, I am working on a project to transpile from my company's in house scripting language, which is Object Orientated and takes quite a few features from other languages, into Groovy, which has many similar features.
To keep code as close to original as possible, I am trying to leave certain function names and parameters the same. To cater for this, I would like to write a set of libraries that can be imported.
For example, say I have an inbuilt method in the original scripting language,
I would like to be able to write the definition for this method in a groovy file, that can then be imported when needed, and the method may be called.
Tools.groovy
// filename: Tools.groovy
public String foo(String bar) {
return bar;
}
and in another file
Main.groovy
// filename: Main.groovy
import Tools;
String bat = foo("bar")
I know you can can compile class files into jars and put them into the class path, but a lot of the methods I will need to implement will either require meta programming or won't be associated with an object.
Sorry if it's either a bad question or not clear enough. I'm not sure whether its even possible.
Cheers
I believe you should be able to create libraries and reuse them when needed.
All you need to do is create class and add the static methods if you do not have to create instances, non static methods otherwise. Then it looks like you already aware how to proceed later.
For instance, you can create utilities classes for String, List, etc based on your description.
By the way, even if you do not create libraries, it is even possible to write one lines in groovy achieve what you may needed most of the cases.

Java Card program using GPJ

So I was tasked to create a java client to communicate with java card.
Right now I can authenticate, write and read data using javax.smartcardio but having a bit of trouble trying to upload cap file and install it.
So after googling around, I found that I can use gpj as a library and use it in my java application to upload and install the cap file.
The problem is I can't find any documentation for gpj and I can't understand the code without one.
Here's one that I have trouble to understand public void installAndMakeSelecatable(AID paramAID1, AID paramAID2, AID paramAID3, byte paramByte, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
Even when I look on the other part of the code, I can't find out the last parameter since all that use these method will pass null.
So if anyone know where can I find the documentation, I would be really glad. Or better yet, another library that can upload cap file and have some documentation with it.
so far, I've found gpj,jpcsc,jcManager and opal.
Nevermind, it seems that I'm not a clever guy.
For future reference, you can find out what to pass to what method by looking through the main method of the Global Platform Services class. For parameter that you are not sure what to pass, just use null.

Mono.Cecil Modifying the RVA of a method

I would like to modify the RVA of a method using Mono.Cecil. I noticed a similar question asked back in 2007 but is this doable in 0.95?
For eg: methodA.RVA = 0x1234;
I understand Mono.Cecil compute and write RVA during compilation but
are there anyways to go about modifying the RVA?
It can be done using CFF explorer though.
Thank You.
No this is not possible: that's simply not the goal of Mono.Cecil.
Cecil let you read, modify and write the managed code and metadata, but when it comes to the PE file organization, that's considered an implementation detail.

Importing csv files using groovy

I have developed a groovy application. Now it has been required
that for feeding the DB a CSV interface must be provided.
That is, I have to load a csv file, parse it and
insert records into the DB in a transactional way.
The question is if there exists for groovy something
like ostermiller utils (a configurable csv parser).
Thanks in advance,
Luis
Kelly Robinson just wrote a nice blog post about the different possibilities that are available to work with CSV files in Groovy.
Groovy and Java are interoperable. Take a look at the documentation for mixed Java and Groovy applications. Any Java class can easily be used in Groovy with no change (plus you have the groovy syntax). If you are interested in the ostermiller utils to do your CSV parsing, you can use it directly from Groovy.
If the ostermiller library does what you want you can call it directly from Groovy. Just put the necessary jars in your groovy\lib directory and you should be ready to go.

Resources