我在一個工作簿中有多個工作表,它也讀取每一行。如何使用java從一個工作簿中讀取多個工作表中的工作表?
但是,每次它開始讀取第一行的表格,並因爲它開始設置/寫入案例的狀態時,它再次開始設置結果從第一行意味着它重疊每個案件的結果同一排。
另外,對於閱讀和書寫工作表,我使用Jxl api。
下面是邏輯的代碼任何人都可以請讓我知道如何解決它:
private void handleScenario(String scenarioName) throws Exception {
ExcelHandler testScenarios = new ExcelHandler(TEST_SUITE_PATH);
testScenarios.setSheetName(scenarioName);
testScenarios.columnData();
int rowWorkBook1 = testScenarios.rowCount();
System.out.println("Total Rows1: "+ rowWorkBook1);
for (int j = 1; j < rowWorkBook1; j++) {
String sno = testScenarios.readCell(testScenarios.getCell("Sno"), j); // SendKey
String testCaseDescription = testScenarios.readCell(testScenarios.getCell("TestCaseDescription"), j);
String framWork = testScenarios.readCell(testScenarios.getCell("FrameworkName"), j);
String operation = testScenarios.readCell(testScenarios.getCell("Operation"), j); // SendKey
String value = testScenarios.readCell(testScenarios.getCell("Value"), j);
handleObjects(operation, value, framWork);
boolean bTestCaseStepStatus = handleObjects(operation,value, framWork);
generateReport(bTestCaseStepStatus, scenarioName, sno,testCaseDescription, j);
}
}
private boolean generateReport(boolean bTestCaseStepStatus,
String testSuiteName, String SNO, String testCaseDescription, int j)
throws RowsExceededException, WriteException, IOException {
WritableData writableData = new WritableData(TEST_RESULT, testSuiteName, j, 2);
// If sheet name is already exist then .... write data at row = row +1
// else write directly .. means row = 1
if (bTestCaseStepStatus) {
//System.out.println("--------------"+bTestCaseStepStatus+"------------");
System.out.println("SNo=" +SNO+ ",Test description=" + testCaseDescription + "Row ID: " + j);
writableData.shSheet("Result", 2, j, "Pass");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
} else {
// System.out.println("--------------"+bTestCaseStepStatus+"------------");
System.out.println("SNo=" +SNO+ ",Test description=" + testCaseDescription + "Row ID: "+ j);
writableData.shSheet("Result", 2, j, "Fail");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
return bTestCaseStepStatus;
// Finally .... close Report file ...
}
private boolean handleObjects(String operation, String value,
String framWork) throws Exception {
// Return true/False
ExcelHandler objectRepository = new ExcelHandler(OBJECT_REPOSITORY_PATH, "OR");
objectRepository.columnData();
int rowCount = objectRepository.rowCount();
//System.out.println("Total Rows in hadleObject=" + rowCount);
boolean testStepStatus = false;
for (int k = 1; k < rowCount; k++) {
String frameWorkName = objectRepository.readCell(
objectRepository.getCell("FrameworkName"), k);
String ObjectName = objectRepository.readCell(
objectRepository.getCell("ObjectName"), k);
String Locator = objectRepository.readCell(
objectRepository.getCell("Locator"), k); // SendKey
//System.out.println("FrameWorkNameV=" + frameWorkName
// + ",ObjectName=" + ObjectName + ",Locator=" + Locator);
if (framWork.equalsIgnoreCase(frameWorkName)) {
testStepStatus = operateWebDriver(operation, Locator, value,
ObjectName);
}
}
return testStepStatus;
}
你的方法handleObjects()被調用兩次 - 是故意的嗎? 另外,它看起來像你所做的只是讀取這部分代碼中的值,你可以發佈你的handleObjects()和generateReport()方法嗎? –
@UlliSchmid我已經發布了handleObjects()和generateReport()方法,請檢查。 – SelenyanC2
謝謝你。再次 - handleObjects(操作,值,framWork);被稱爲2次 - 故意?也許嘗試評論第16行? –