Skip to main content

Quality Assurance

Integrating Excel with Rest Assured

A Male Programmer Shows A Female Colleague A Coding Technique. The Codes Are Visible On The Laptop Screen

Let’s start with this blog as we attempt to understand the art of Integrating Excel with Rest Assured. Get ready for a smooth transition between reading data from Excel files and into our Rest Assured Test. Rest Assured, the Java powerhouse for API testing, joins forces with Apache POI, the maestro of Excel file wizardry, in this thrilling exploration. Let’s have a look at where Java genius meets spreadsheet wizardry.

Need of Integrating Excel with Rest Assured

Excel integration allows us to store the test data in an Excel Sheet. We can easily modify and add test data without modifying the test scripts. This is useful for testing scenarios without changing the existing code. Integrating Excel with Rest Assured improves efficiency and maintainability.

Let’s see how we can integrate Excel with Rest Assured with the following steps.

1: Create a new maven project.

2: Add the following dependencies to the project:

  • Apache POI.
  • Apache POI OOXML.
  • Rest Assured.
  • TestNg
  • Junit
  • Jaxb-API.
  • Log4j-api.
  • Log4j-core.

3: Create a new project. In this example, we have created a ‘Rest’ project. Within this project, a package named ‘resource’ has been made, and inside this package, a class called ‘Data.java’ has been created to read data from an Excel file

Step 3




FileInputStream
will create the object fis and open input stream to read the contents of the Excel file. Follow with the designated file path where the sheet is present.

XSSFWorkbook is a class present in the Apache POI library that represents an Excel workbook, and it will create an object workbook by reading an Excel file from the input stream fis.

4: Create a folder inside the ‘Rest’ project containing a subfolder named ‘Sheet’.’An Excel file is located inside that subfolder, named “Book1.xlsx”.

Step 4

5: Below is the snippet of the complete code for the reference.

5.a

Step 3

The complete code is at the “Integrating Excel with Rest Assured” location.

6: Below is the screenshot given for the output after the code reads the Excel.

Final

Conclusion

We have successfully integrated data from the Excel file using Rest Assured. This approach provides flexibility and reusability in our API testing. With these additional capabilities in Excel, we can easily manage test scenarios without effectively modifying our existing code.

Happy learning!

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.

Shakti Singh

Shakti Singh works at Perficient as Technical Consultant based in Nagpur. He has over two years of experience. He loves to explore technology and enjoys traveling.

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram