public static void ValidNumeric(string inputField, string fieldName) { int myInteger; bool IsNumeric = int.TryParse(inputField, out myInteger); if (IsNumeric == true) { //ignore } else { Console.WriteLine(" The " + fieldName + " should be numeric "); CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, " The " + fieldName + " should be numeric "); CommonFeatures.Teardown(); } }
// UI validation methods are coming below // character length validation public static void CheckLength(int minLength, int maxLength, string inputText, string fieldName) { try { Assert.LessOrEqual(inputText.Length, maxLength); Assert.GreaterOrEqual(inputText.Length, minLength); //CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Skip, passMessage); } catch (Exception ex) { //CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, failMessage); Console.WriteLine("exception message:" + ex.Message + "Inner exception:" + ex.InnerException); Console.WriteLine("The field must be between " + minLength + " - " + maxLength + " alphanumeric characters."); CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, fieldName + " must be between " + minLength + " - " + maxLength + " alphanumeric characters."); CommonFeatures.Teardown(); } }
public static void ValidYear(int minYear, string inputYear, string fieldName) { int currentYear = DateTime.Now.Year; int _inputYear = Int32.Parse(inputYear); try { Assert.GreaterOrEqual(_inputYear, minYear); Assert.LessOrEqual(_inputYear, currentYear); //CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Skip, passMessage); } catch (Exception ex) { //CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, failMessage); Console.WriteLine("The exception message : " + ex + "Inner Exception : " + ex.InnerException); Console.WriteLine("The Year built should be within " + minYear + " and " + currentYear); CommonFeatures.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "The Year in " + fieldName + " field should be within " + minYear + " and " + currentYear); CommonFeatures.Teardown(); } }