I have a task to collect all the links of site, go to and check on each page, there is no error. The problem is that if there is an error on any page, the test is terminated. I want to have checked all the pages and at the end of the test to get the result of all the pages.
public static void OpenAllLinksAndCheckOnErrors()
{
var collectionReportsLinks = CollectionReportsLinks();
foreach (string linkToReportPage in collectionReportsLinks)
{
Driver.Instance.Navigate().GoToUrl(linkToReportPage);
Assert.That(string.IsNullOrWhiteSpace(FindErrorsInReportPages()), "Error on page {0}", FindErrorsInReportPages()));
}
}
public static List<string> CollectionReportsLinks()
{
List<string> links = new List<string>();
var collectionReportsItems = Driver.Instance.FindElements(By.TagName("a")).ToList();
for (int i = 0; i <= collectionReportsItems.Count - 1; i++)
{
var menuItemHref = collectionReportsItems[i].GetAttribute("href".ToString());
links.Add(menuItemHref);
}
return links;
}
public static string FindErrorsInReportPages()
{
string errorText = string.Empty;
var reportItem = Driver.Instance.FindElements(Selectors.AnyPage.GetReportPageError()).FirstOrDefault();
if (reportItem == null)
return errorText;
if (reportItem.Displayed)
errorText = reportItem.Text;
return errorText;
}