我需要帮助的人,我已经陷入困境。
这是我的方法
的代码@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
帮我找到解决方案的人。 。 。!!!
答案 0 :(得分: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);
}