This question is locked. New answers and comments are not allowed.
Hello!
I found the code that allows me to write test result to an Excel file or txt file, and it all works great! No issues at all. But what I would like to do now is write the same results to a specific worksheet within the workbook. I've tried several different methods that I found online, but keep getting errors in Visual Studio. I've searched throughout these forums and haven't found exactly what I'm looking for.
Scenario I'm trying to achieve:
Run multiple tests and have them write to the same workbook, but each test assigned/writing to its own worksheet within that workbook. Does that make sense?
Example:
test1.tstest writes to Sheet1
test2.tstest writes to Sheet2
etc
Below is the code I am using that works successfully in writing to the default worksheet. Any help is appreciated. Thanks!
public override void OnAfterTestCompleted(TestResult result)
{
string passed = Convert.ToString(result.TotalPassedSteps);
string notRunSteps = Convert.ToString(result.TotalNumberOfNotRunSteps);
string overall = Convert.ToString(result.Result);
string resultMessage = Convert.ToString(result.Message);
string[] split = resultMessage.Split(new Char[] { '\n' });
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
string myPath = "C:\\Results.xlsx";
Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(myPath);
int idx = 1;
foreach (string s in split)
{
excelApp.Cells[idx, 1] = s;
idx++;
}
excelApp.Cells[idx + 1, 1] = ("Number of Passed Steps: " + passed);
excelApp.Cells[idx + 2, 1] = ("Number of Not Run Steps: " + notRunSteps);
excelApp.Cells[idx + 3, 1] = ("Total Test Result: " + overall);
excelApp.Visible = true;
excelApp.ActiveWorkbook.Save();
workbook.Close(false, Type.Missing, Type.Missing);
excelApp.Workbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
excelApp.Quit();
GC.Collect();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
}
Reference site:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/external-log-file.aspx
I found the code that allows me to write test result to an Excel file or txt file, and it all works great! No issues at all. But what I would like to do now is write the same results to a specific worksheet within the workbook. I've tried several different methods that I found online, but keep getting errors in Visual Studio. I've searched throughout these forums and haven't found exactly what I'm looking for.
Scenario I'm trying to achieve:
Run multiple tests and have them write to the same workbook, but each test assigned/writing to its own worksheet within that workbook. Does that make sense?
Example:
test1.tstest writes to Sheet1
test2.tstest writes to Sheet2
etc
Below is the code I am using that works successfully in writing to the default worksheet. Any help is appreciated. Thanks!
public override void OnAfterTestCompleted(TestResult result)
{
string passed = Convert.ToString(result.TotalPassedSteps);
string notRunSteps = Convert.ToString(result.TotalNumberOfNotRunSteps);
string overall = Convert.ToString(result.Result);
string resultMessage = Convert.ToString(result.Message);
string[] split = resultMessage.Split(new Char[] { '\n' });
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
string myPath = "C:\\Results.xlsx";
Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(myPath);
int idx = 1;
foreach (string s in split)
{
excelApp.Cells[idx, 1] = s;
idx++;
}
excelApp.Cells[idx + 1, 1] = ("Number of Passed Steps: " + passed);
excelApp.Cells[idx + 2, 1] = ("Number of Not Run Steps: " + notRunSteps);
excelApp.Cells[idx + 3, 1] = ("Total Test Result: " + overall);
excelApp.Visible = true;
excelApp.ActiveWorkbook.Save();
workbook.Close(false, Type.Missing, Type.Missing);
excelApp.Workbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
excelApp.Quit();
GC.Collect();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
}
Reference site:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/external-log-file.aspx