Skip to main content

Software Development

Cucumber Data Table Generator from Json

Person Testing Different Business Processes

What is JSON?

JavaScript Object Notation, more commonly known by the acronym JSON, is an open data interchange format that is both human and machine-readable. Despite the name JavaScript Object Notation, JSON is independent of any programming language and is a common API output in a wide variety of applications.
Json Format.0b284ee998d9b3b000deae381153646b0a09f8fb


What is cucumber data table?

A data table (or data matrix) is a special type of table that allows us to compare a set of numerical values simultaneously easily. It’s great for displaying data that you would like people to understand at a glance.
They are used for displaying numbers and statistics. Still, they can also be used as a simple way of providing information about a range of choices and doing multiple tests for a particular scenario, as we will use today.Screenshot 2023 01 10 001606

Concept:

The purpose of this component is to take JSON as input and return it as a data table.

Parameters:

  • jsonString* – to provide the JSON as input to extract as output.
  • prefixPadding* – The padding space for the key column(left) in table data
  • replacableStrings – To mention strings in a comma-separated list that needs to be replaced as an empty string. Example:ObjectId(,NumberLong(,JUUID(,),$
  • suffixPadding* – The padding space for the value column(right) in table data
    (*)Mandatory

Run the application:

  • Find the jar here https://github.com/Ashwin-9227/cucumber-data-generator-runnable-file
  • Download the jar by name cucumberdatatablegenerator-0.0.1-SNAPSHOT.jar
  • Place it in any folder that is accessible.
  • Open a command prompt and go to the appropriate destination.
    • If the location of the jar is in the folder is D:\xxx\yyy
    • Open command prompt, input: D:(press enter)
    • You will be in D:\ input: cd D:\xxx\yyy
    • Now you will be in D:\xxx\yyy
  • Execute the jar by using the following command. Input: java -jar cucumberdatatablegenerator-0.0.1-SNAPSHOT.jar
  • If you see similar to Started CucumberDataTableGeneratorApplication in 4.945 seconds (JVM running for 5.717). Then your application has started successfully.

URL to open the application

 


An example of how it works:

  1. Open the URL which is provided above.
  2. Navigate to the path as provided here.
    Example Controller
  3. In the jsonString body paste in the needed JSON formatted data that you need to convert into a cucumber data table.
    Example Json
  4. Add the padding parameters to format the data table output
    Example Parameters
  5. Click on execute.
  6. Voila! now you have successfully converted JSON data in cucumber’s data table using this simple generator tool
    Example Response

 

This tool is the initial version where you might come across some errors while running. Try adding the unrecognized JSON parameter in replacableStrings and check it works. If it doesn’t feel free to reach me for suggestions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ashwin Krishnamurthy

Ashwin Krishnamurthy is a Technical Consultant and has been with Perficient since January 2019. I am a back-end developer having close to 8 years of experience in Java expertise. I like to talk about technologies that keep adding up, and I am eager to know more than I know now. I also would love to share my knowledge of technology with others.

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram