public bool DeleteOrganisation(string OrgName, string TerminationDateState = "MoreThanRenewalPeriod") { try { if (!commonFeatures.Search(OrgName)) { CreateOrganisation(OrgName); commonFeatures.Search(OrgName); } string Org_Status = commonFeatures.CheckStatus(OrgName); if (Org_Status.Equals("Active")) { int RenewalPeriod = Convert.ToInt32(CheckRenewalPeriod(OrgName)); int toSub = 0; switch (TerminationDateState) { case "LessThanRenewalPeriod": toSub = (RenewalPeriod - 1) * (-1); break; case "EqualToRenewalPeriod": toSub = (RenewalPeriod) * (-1); break; case "MoreThanRenewalPeriod": toSub = (RenewalPeriod + 1) * (-1); break; } DateTime dateTime = DateTime.UtcNow.Date; DateTime newDateTime = dateTime.AddDays(toSub).Date; string ddmmyyyy = newDateTime.ToString("dd/MM/yyyy"); commonFeatures.Search(OrgName); IWebElement lnk_Edit = driver.FindElement(By.XPath("//td[contains(text(),'" + OrgName + "')]/../td/a[text()='Edit']")); ClickOn(lnk_Edit); commonFeatures.SelectDate(clndr_TerminationDate, ddmmyyyy); Wait(5); ClickOn(btn_Save); DeleteOrganisation(OrgName); } else if (Org_Status.Equals("Expired")) { IWebElement lnk_Delete = driver.FindElement(By.XPath("//td[contains(text(),'" + OrgName + "')]/../td/a[text()='Delete']")); ClickOn(lnk_Delete); WaitForObject(btn_Delete); if (btn_Delete.Displayed) { ExtentReportUtil.report.Log(Status.Info, "Delete Organisation Modal pop-up is dispayed."); ClickOn(btn_Delete); Wait(1); TakeScreenshot(); Wait(1); if (driver.PageSource.Contains("deleted successfully") && TerminationDateState.Equals("MoreThanRenewalPeriod")) { ExtentReportUtil.report.Log(Status.Pass, "Organisation '" + OrgName + "' deleted successfully."); result = true; } else if (driver.PageSource.Contains("cannot be deleted") && driver.PageSource.Contains("under a renewal period.") && TerminationDateState.Equals("LessThanRenewalPeriod")) { ExtentReportUtil.report.Log(Status.Pass, "Organisation '" + OrgName + "' cannot be deleted as it's under a renewal period."); result = true; } else if (driver.PageSource.Contains("cannot be deleted") && driver.PageSource.Contains("there is an active media") && TerminationDateState.Equals("EqualToRenewalPeriod")) { ExtentReportUtil.report.Log(Status.Pass, "Organisation '" + OrgName + "' cannot be deleted as there is an active media."); result = true; } else if (driver.PageSource.Contains("cannot be deleted") && driver.PageSource.Contains("under a renewal period.") && TerminationDateState.Equals("MoreThanRenewalPeriod")) { int RenewalPeriod = Convert.ToInt32(CheckRenewalPeriod(OrgName)); int toSub = (RenewalPeriod + 1) * (-1); DateTime dateTime = DateTime.UtcNow.Date; DateTime newDateTime = dateTime.AddDays(toSub).Date; string ddmmyyyy = newDateTime.ToString("dd/MM/yyyy"); commonFeatures.Search(OrgName); IWebElement lnk_Edit = driver.FindElement(By.XPath("//td[contains(text(),'" + OrgName + "')]/../td/a[text()='Edit']")); ClickOn(lnk_Edit); commonFeatures.SelectDate(clndr_TerminationDate, ddmmyyyy); Wait(5); ClickOn(btn_Save); DeleteOrganisation(OrgName); } } } } catch (Exception ex) { ExtentReportUtil.report.Log(Status.Error, "Exception Occured: " + ex.ToString()); } return(result); }