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
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”.
5: Below is the snippet of the complete code for the reference.
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.
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!