Get Data from Excel as Map with DataProvider
Shiba Sahoo
SDET | QA Automation Engineer / QAエンジニア | 9+ Years (Selenium,Playwright,Appium,Cypress,JavaScript,API & Mobile Testing) | Japanese Bilingual | Trainer | Freelance | Spain,UAE(Dubai,Abu Dhabi),Japan,Germany,Remote
Have you ever wondered how to effieciently read data from excel with key-value pair using Map and pass data to Dataprovider with Object[][] as return type!!
Why we need this solution in the first place?
Well, If data-column in Excel file is increased(let's say more than 10 or 20), then our Test method argument size also increases , which is not a good standard practice and it's hard to maintain as well.
Also we're kind of hardcoding variable sequence, we have to keep the method arguments in same order as of data-column present in excel file.
With the solution provided in this post, if data sequence changes in excel file, it doesn't affect the test case at all.
Sample Excel File:
Before reading data as Map:
After Reading data as Map:
Additional Tips:
I've also added executeTest column in this excel file. we can pass value for this columns either as 'yes' or 'no', This will enable us to control which test cases to execute at run time.
This is specially helpful when doing dry-run or when some test cases are In-Progress, so we can just put the value as 'no' to disable those tests data.
ExcelReader Code Below: