Text Validation - use of wildcard or truncation?

Ranorex Studio, Spy, Recorder, and Driver.
jhance
Posts: 6
Joined: Fri Feb 27, 2009 11:48 pm

Text Validation - use of wildcard or truncation?

Post by jhance » Fri May 29, 2009 7:19 pm

Hi All -

I have an application which creates orders based on customer demand for a given quantity on a given date. I want to be able to perform a few different validations, using a test dataset. I can successfully control all elements of the dataset, except the date I run the test, which obviously changes with each day.

Currently, I am validating on a text string, within the confirmation dialog that comes up when the user tries to place the order. That dialog says:

-------------------------------
Would you like to accept the recommended order for part 'C'?

Quantity: 298
Priority: Critical
Reorder Date: 5/21/2009
---------------------------------

I selected to validate against a caption, which came up with:

text[@caption~'^Would\ you\ like\ to\ accept\ ']

However, it still looks for the entire contents of the dialog, including the date. What I would like is to validate against a string, followed by some kind of wildcard, such as:

text[@caption~'^Would\ you\ like\ to\ accept... Date:* ']

Where anything before the "*" would have to pass validation, but whatever happens after the "*" is excluded from the validation.

Is this possible, and what are the exact steps to set this up.
Thank you SO much, in advance!

User avatar
Ciege
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Fri May 29, 2009 8:32 pm

I can suggest one method. It would be to read the entire caption into a string and then remove the time/date stamp with a regular expression. Once the time/date is removed you can compare your results with anything you need.

What language are you writing in? If C# I can give you an example of a regular expression the removes time and/or date stamps from a string.

jhance
Posts: 6
Joined: Fri Feb 27, 2009 11:48 pm

Thanks for the reply

Post by jhance » Fri May 29, 2009 11:31 pm

We're using Vb, but I expect your advice still holds. If you have the syntax, that would be great. Otherwise, I'll bounce it off one of our developers.

Thanks again!
Jon

User avatar
Ciege
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Fri May 29, 2009 11:38 pm

I have a few different patterns that I verify against since time and date formats can vary widely. Regardless, here is a snippet of what I use.
You should be able to extrapolate the rest based on this snippet. If not let me know and I will post more.

Good luck!

Code: Select all

string strDatePattern1 = "\\d{1,2}(\\-|\\/|\\.)\\d{1,2}\\1\\d{2,4}";
string strDatePattern2 = "(Monday|Tuesday|Wednesday|Thursday|Friday),\\s(Jan|Feb|Mar|Apr|May|Jun|July|Aug|Sep|Oct|Nov|Dec)\\s\\d{1,2}, \\d{2,4}";
string strDatePattern3 = "\\d{1,2}\\-(Jan|Feb|Mar|Apr|May|Jun|July|Aug|Sep|Oct|Nov|Dec)\\-\\d{2,4}";
string strDatePattern4 = "(0[0-9]|1[0-2])([0-2][0-9]|30|31)([0-1][0-9])";
string strTimePattern1 = "\\d{1,2}:\\d{1,2}:\\d{1,2}(AM|PM)";
string strTimePattern2 = "([0-1][0-9]|2[0-3]):([0-5][0-9])";

if (Regex.IsMatch(file2line, strDatePattern1) | Regex.IsMatch(file2line, strDatePattern2) |
    Regex.IsMatch(file2line, strDatePattern3) | Regex.IsMatch(file2line, strDatePattern4) |
    Regex.IsMatch(file2line, strTimePattern1) | Regex.IsMatch(file2line, strTimePattern2))
{
  if (Regex.IsMatch(file2line, strTimePattern1))
  {
    file1line = Regex.Replace(file1line, strTimePattern1, "[IGNORED TIME]");
    file2line = Regex.Replace(file2line, strTimePattern1, "[IGNORED TIME]");
  }
  else if (Regex.IsMatch(file2line, strTimePattern2))
  {
    file1line = Regex.Replace(file1line, strTimePattern2, "[IGNORED TIME]");
    file2line = Regex.Replace(file2line, strTimePattern2, "[IGNORED TIME]");
  }
}

jhance
Posts: 6
Joined: Fri Feb 27, 2009 11:48 pm

Thank you!!

Post by jhance » Mon Jun 01, 2009 8:52 pm

Ciege, thanks so much for the info and snippets. I'll see if I can incorporate them into my scripts, and see where that takes me. Thanks again for the help!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Tue Jun 02, 2009 3:24 pm

Ciege's patterns are very accurate for checking date/time strings. However, if you just need a wildcard in regular expression, you can use ".", which matches any character (except newline), followed by a quantifier. E.g. ".*" matches zero or more characters, ".{5}" matches exactly 5 characters.
In your case you could search for a Text element using the following regular expression:

Code: Select all

text[@caption~'^Would\ you\ like\ to\ accept... Date:.*']
Regards,
Alex
Ranorex Support Team