I have two methods General and SearchTab below. When I look at my report file, I see that the values for the General Methods as:
TestName:
TestMachine: Maya
TestUser: Administrator
TestTime: 6/13/2011 12:02
TestStatus: FAIL
TestExpectedResult:
TestActualResult:
TestComments:
TestName, TestExpectedResult, TestActualResult, and TestComments are blank whereas they should have values:
TestName: Test 1: General,
TestExpectedResult: ‘Home’ tab should be present,
TestActualResult: Home tab found
TestComments: Home tab found
Also, the TestStatus should have been PASS instead of FAIL.
It looks like even though I reassigned the values of these variables in the method General, they are still printing the values that were assigned to them inside the constructor.
The problem is the same for the second method SearchTab.
Please help me figure out the problem.
namespace Automation
{
[TestClass]
public class FunctionalTest
{
public ISelenium Sel;
public StringBuilder Err;
public string Report = "C:\Report.XLS";
public string[] arrTestResults = new string[8];
public string TestName;
public string TestMachine;
public string TestUser;
public string TestTime;
public string TestStatus;
public string TestExpectedResult;
public string TestActualResult;
public string TestComments;
// Constructor
public FunctionalTest()
{
TestName = arrTestResults[0];
TestMachine = arrTestResults[1] = System.Environment.MachineName.ToString();
TestUser = arrTestResults[2] = System.Environment.UserName.ToString();
TestTime = arrTestResults[3] = System.DateTime.Now.ToString();
TestStatus = arrTestResults[4] = "FAIL";
TestExpectedResult = arrTestResults[5];
TestActualResult = arrTestResults[6];
TestComments = arrTestResults[7];
}
public void WriteReport(string[] arrResults)
{
int iLastRow, iCnt1;
if (File.Exists(Report))
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
Object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkBook = xlApp.Workbooks.Open(Report, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
iLastRow = range.Rows.Count;
for (iCnt1 = 1; iCnt1 < 9; iCnt1++)
{
xlWorkSheet.Cells[iLastRow + 1, iCnt1] = arrResults[iCnt1 - 1];
}
xlWorkBook.Save();
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
else
{
Console.WriteLine("Report File " + Report + " does not exist");
}
}
[TestMethod]
public void General()
{
TestName = "Test 1: General";
TestExpectedResult = "'Home' tab should be present";
if (Sel.IsElementPresent("TAB_Home")))
{
TestStatus = "PASS";
TestActualResult = "Home tab found";
TestComments = TestActualResult;
}
else
{
TestActualResult = "Home tab not found";
TestComments = TestActualResult;
}
//Write to report
WriteReport(arrTestResults);
}
}
[TestMethod]
public void SearchTab()
{
TestName = "Test 2: Search Tab";
TestExpectedResult = "Search tab should be present";
// Assigning TestStatus to FAIL because TestStatus is PASS right now from the previous test method
TestStatus = "FAIL";
if (Sel.IsElementPresent("TAB_Search"))
{
sActual = "Search Tab found";
arrTestResults[7] = sActual;
TestComments = TestActualResult;
TestStatus = "PASS";
}
else
{
TestActualResult = "Search tab not found";
TestComments = TestActualResult;
}
//Write to report
WriteReport(arrTestResults);
}
}
}
Your intialization creates the initial array values and never changes them. You are changing the field values:
Also, you should not use public fields. Rather, you should use properties.
OR
You either need to write a setter for your properties that change the array, or better yet use the appropriate fields/properties in your report:
Of course, this could be refactored to be much better as well.