I would like to know Is it possible to get error message (reason of why my testcase failed). For instance, below is my code of I am trying to find an element it will fail my test. Error message will display in NUnit. How to get that error message in my text file.
private DateTime _timestamp1;
private DateTime _timestamp2;
private string _TestNum;
private string _TestDetails;
[Test]
public void Initialize()
{
_timestamp1 = DateTime.Now;
_TestNum = "12345";
_TestDetails = "For test purpose";
TWebDriver driver = new TWebDriver();
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("q"));
}
}
[TearDown]
public void cleanup()
{
string path = (@"..\..\Result\");
_timestamp2 = DateTime.Now;
TimeSpan timediff = (_timestamp2) - (_timestamp1);
string TotalTime = timediff.Minutes + " minutes and " + timediff.Seconds + " seconds";
if ((TestContext.CurrentContext.Result.Status == TestStatus.Passed) || (TestContext.CurrentContext.Result.State == TestState.Success))
{
string status = "Passed";
File.WriteAllText(Path.Combine(path, "Passed" + ".txt"), "Test Case No.: " + _TestNum + string.Format(Environment.NewLine) + "Test Details: " + _TestDetails + string.Format(Environment.NewLine) + "Start Time: " + _timestamp1 + string.Format(Environment.NewLine) + "End Time: " + _timestamp2 + string.Format(Environment.NewLine) + "Total Time: " + TotalTime + string.Format(Environment.NewLine) + "Status: " + status);
}
else
{
string status = "Failed";
File.WriteAllText(Path.Combine(path, "Passed" + ".txt"), "Test Case No.: " + _TestNum + string.Format(Environment.NewLine) + "Test Details: " + _TestDetails + string.Format(Environment.NewLine) + "Start Time: " + _timestamp1 + string.Format(Environment.NewLine) + "End Time: " + _timestamp2 + string.Format(Environment.NewLine) + "Total Time: " + TotalTime + string.Format(Environment.NewLine) + "Status: " + status);
}
}
NUnit Version: 2.6.4