Код выполняется успешно, но данные добавляются в Excel только на последней итерации
Мне нужна помощь людей, я застрял в точке.
Это мой код для метода после
@AfterMethod
public void writeResult(ITestResult result) throws IOException, Exception
{
Workbook workbk = Workbook.getWorkbook(new File("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls"));
WritableWorkbook bookk = Workbook.createWorkbook(new File("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest_Written.xls"),workbk);
int methodCellColumn =findCellLocationColumn("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls", methodName);
int methodCellRow =findCellLocationRow("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls", methodName);
if(result.getStatus() == ITestResult.SUCCESS)
{
System.out.println("Method-"+methodName+"- has Passed");
writeDataInCell(methodCellColumn+3, methodCellRow,"Pass",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow);
}
else if(result.getStatus() == ITestResult.FAILURE)
{
System.out.println("Method-"+methodName+"- has Failed");
writeDataInCell(methodCellColumn+3, methodCellRow,"Fail",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow+"\n");
}
else if(result.getStatus() == ITestResult.SKIP)
{
System.out.println("Method-"+methodName+"- has Skipped");
writeDataInCell(methodCellColumn+3, methodCellRow,"Skip",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow);
}
bookk.write();
bookk.close();
workbk.close();
}
Методы, используемые для получения номера столбца и номера ячейки, возвращают правильные результаты. его методы
public int findCellLocationColumn(String xlPath,String runningMethod) throws Exception, IOException
{
Workbook workbk = Workbook.getWorkbook(new File(xlPath));
Sheet sht = workbk.getSheet(0);
Cell requiredCell = sht.findCell(runningMethod);
int cellColumnNumber = requiredCell.getColumn();
workbk.close();
return cellColumnNumber;
}
&
public int findCellLocationRow(String xlPath,String runningMethod) throws Exception, IOException
{
Workbook workbk = Workbook.getWorkbook(new File(xlPath));
Sheet sht = workbk.getSheet(0);
Cell requiredCell = sht.findCell(runningMethod);
int cellRowNumber = requiredCell.getRow();
workbk.close();
return cellRowNumber;
}
Метод writeDataInCell является
public void writeDataInCell(int col,int row,String result,WritableWorkbook book1) throws RowsExceededException, WriteException, BiffException, IOException
{
WritableSheet firstSheet = book1.getSheet(0);
Label label= new Label(col, row, result);
firstSheet.addCell(label);
System.out.println("writeDataInCell method executed for row-> "+row);
}
Я не знаю, что происходит не так, но данные не записываются в выходной файл Excel, как ожидалось. Выходной Excel выглядит следующим образом:
В то время как ожидаемый выходной файл должен выглядеть следующим образом:
Требуемый вывод консоли выглядит следующим образом:
Started InternetExplorerDriver server (64-bit)
2.44.0.0
Listening on port 32921
Static method completed
[TestNG] Running:
C:\Users\sha.RCOTIS\AppData\Local\Temp\testng-eclipse--424717979\testng- customsuite.xml
Execution mode is Y
Login method completed
Method-Login- has Passed
writeDataInCell method executed for row-> 1
Method Column number is-> 7
Method row number is-> 1
Execution mode is N
Method-quickProject- has Skipped
writeDataInCell method executed for row-> 2
Method Column number is-> 7
Method row number is-> 2
Execution mode is Y
Close Browser method completed
Method-closeBrowser- has Passed
writeDataInCell method executed for row-> 3
Method Column number is-> 7
Method row number is-> 3
Execution mode is N
Method-closeBrowser1- has Skipped
writeDataInCell method executed for row-> 4
Method Column number is-> 7
Method row number is-> 4
PASSED: Test("1", "Project Creation", "1.00", "Login", "Robert.Lezwijn@otis.com1", "Y")
PASSED: Test("2", "Complete Execution", "Final 1", "closeBrowser", "NA", "Y")
SKIPPED: Test("", "", "1.01", "quickProject", "NA", "N")
org.testng.SkipException: Execution mode is N
at eLogistics_Execution.Execute_Test.Test(Execute_Test.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
SKIPPED: Test("2", "Complete Execution", "Final 1", "closeBrowser1", "NA", "N")
org.testng.SkipException: Execution mode is N
at eLogistics_Execution.Execute_Test.Test(Execute_Test.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 4, Failures: 0, Skips: 2
===============================================
===============================================
Default suite
Total tests run: 4, Failures: 0, Skips: 2
===============================================
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@450b9338: 47 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4f013415: 0 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@666e2862: 47 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@4ff561a7: 0 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@11def881: 0 ms
Помогите мне найти решение, ребята.,.!!!
1 ответ
Поскольку каждый раз, когда вы получаете лист от объекта book1, все сделанные изменения пропускаются, кроме последнего изменения. ссылка:
WritableSheet firstSheet = book1.getSheet(0);
Что вы можете сделать, это изменить тип возвращаемого значения writeDataInCell() на WritableWorkBook и изменить логику области вызова следующим образом:
public WritableWorkbook writeDataInCell(int col,int row,String result,WritableWorkbook book1) throws RowsExceededException, WriteException, BiffException, IOException
{
WritableSheet firstSheet = book1.getSheet(0);
Label label= new Label(col, row, result);
firstSheet.addCell(label);
System.out.println("writeDataInCell method executed for row-> "+row);
return book1;
}
А также
if(result.getStatus() == ITestResult.SUCCESS)
{
System.out.println("Method-"+methodName+"- has Passed");
this.bookk = writeDataInCell(methodCellColumn+3, methodCellRow,"Pass",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow);
}
else if(result.getStatus() == ITestResult.FAILURE)
{
System.out.println("Method-"+methodName+"- has Failed");
this.bookk = writeDataInCell(methodCellColumn+3, methodCellRow,"Fail",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow+"\n");
}
else if(result.getStatus() == ITestResult.SKIP)
{
System.out.println("Method-"+methodName+"- has Skipped");
this.bookk = writeDataInCell(methodCellColumn+3, methodCellRow,"Skip",bookk);
System.out.println("Method Column number is-> "+(methodCellColumn+3));
System.out.println("Method row number is-> "+methodCellRow);
}