Comments (2)
package com.Automation.Utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class Excelutil2 {
public Workbook book;
public Sheet sheet;
public Excelutil2(String filePath, String sheetName) {
try {
FileInputStream file = new FileInputStream(new File(filePath));
book = WorkbookFactory.create(file);
sheet = book.getSheet(sheetName);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
}
public Object[][] getTestData() {
int rowCount = getRowCount();
int columnCount = getCellCount();
Object[][] data = new Object[rowCount][columnCount];
for (int i = 0; i < rowCount; i++) {
Row row = sheet.getRow(i + 1);
for (int j = 0; j < columnCount; j++) {
Cell cell = row.getCell(j);
cell.setCellType(Cell.CELL_TYPE_STRING);
data[i][j] = cell.getStringCellValue().trim();
}
}
return data;
}
public HashMap<String, String> getTestDataInMap(int rowNum) {
HashMap<String, String> testDataMap = new HashMap<>();
Row headerRow = sheet.getRow(0);
Row dataRow = sheet.getRow(rowNum);
if (dataRow != null) { // Add null check for data row
for (int i = 0; i < headerRow.getLastCellNum(); i++) {
Cell headerCell = headerRow.getCell(i);
Cell dataCell = dataRow.getCell(i);
if (headerCell != null && dataCell != null) { // Add null checks for header and data cells
headerCell.setCellType(Cell.CELL_TYPE_STRING);
dataCell.setCellType(Cell.CELL_TYPE_STRING);
String key = headerCell.getStringCellValue().trim();
String value = dataCell.getStringCellValue().trim();
testDataMap.put(key, value);
}
}
}
return testDataMap;
}
public int getRowCount() {
return sheet.getLastRowNum();
}
public int getCellCount() {
Row headerRow = sheet.getRow(0);
return headerRow.getLastCellNum();
}
}
/////////////////////////
String ExcelPath = "./TestData/CheckListExecutionData.xlsx";
String[] sheets = { "ChecklistExecutionData", "Sheet1", "Sheet2" };
@dataProvider(name = "ChecklistExecutionData")
public Object[][] testDataSupplier() throws Exception {
List<Object[]> testDataList = new ArrayList<>();
for (String sheet : sheets) {
Excelutil2 excel = new Excelutil2(ExcelPath, sheet);
for (int i = 1; i <= excel.getRowCount(); i++) {
HashMap<String, String> testData = excel.getTestDataInMap(i);
testDataList.add(new Object[] { sheet, testData });
}
}
return testDataList.toArray(new Object[0][]);
}
with this dataprovider how to use different sheets for different @test methods this is which u have created i have modified few things how to use single dataprovider for multiple testNG methods in class
from webautomation_allurewdm.
Could you please assist me with this problems? Thank you
from webautomation_allurewdm.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webautomation_allurewdm.