Search code examples
cucumber-javatestng-dataprovider

Cucumber Java using dataprovider


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?


Solution

  • 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.