Hi, I am creating a test where I need to verify some specific text is present so I am using the checkpoint wizard to verify the text. However in the middle of the text will be a date that will show ...
If you know the message will always start the same with, "This is a test on " - you could just capture the first 18 characters using [aqString.SubString] and supply today's date using your own function to validate. Here's how to return today's date and add that date to the end of your aqString.SubString for validation (sorry for bad formatting - inline code feature isn't working):
function getCurrentDate() { var currentDate = aqDateTime.Today(); var today = aqConvert.DateTimeToFormatStr(currentDate, "%m/%d/%Y"); //MM/DD/YYYY return today; }
function mainMessageHandler() { // set variables var page = Sys.Browser("*").Page("*"); var date = getCurrentDate(); var aString = "This is a test on 01/01/2023"; //get text from obj var aSubString = aqString.SubString(aString, 0, 18); //This_is_a_test_on_ var Res = aqString.Find(aqString.ToLower(aString), aqString.ToLower(aSubString));
// find subString and add today's date Log.Message("LOG: full string --> " + aString); Log.Message("LOG: substring --> " + aSubString);
if (!equal(Res, -1)) { Log.Message("| Great Success | - substring '" + aSubString + "' was found"); Log.Checkpoint(aSubString + date); } else { Log.Warning("WARNING: " + aSubString + " no found in: " + aString); } }
Sorry the example given probably wasn't the best one as the date will fall within the middle of a set of text so getting the first x number of characters wouldn't be applicable. Is there a similar way if the date falls in the middle of a block of text?