Variable number of validations

Best practices, code snippets for common functionality, examples, and guidelines.
cpalex
Posts: 5
Joined: Sat Feb 17, 2018 12:37 am

Variable number of validations

Post by cpalex » Thu Mar 08, 2018 6:00 pm

I have a test, where I want to perform 100 different searches. This is easily achieved by data binding. But each search can have between 1 and about 50 results. I am trying to figure out how to run the validation only as many times as there are expected results.

For example, my data table could look like this:
PartGrid.PNG
PartGrid.PNG (5.64 KiB) Viewed 240 times

So for the first row, there would only be one expected result. I can expect the same result every time.

But row 2 will have 2 expected results

To complicate it a little further, I am using the varExpectedResult1 in the repository to find the element that contains the expected result.

Is there a way to repeat the validation step only as many times as the data table isn't blank?

Or could I link the expected results in a different table, and create a table for each row in the first table?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Variable number of validations

Post by odklizec » Fri Mar 09, 2018 9:46 am

Hi,

At first, I think using varExpectedResult1 for element identification purposes is a bad idea. You should never use a data connector value, designed for validation purposes, as "identification" attribute. This is, in my opinion, a wrong idea. You must find another way to uniquely identify the element in question (e.g. using relationship operators).

As for variable number of expected results, I think the way you designed it would be too complicated. Because recording/code module variable cannot be binded to multiple data connectors (at the same time), your idea would not work without some kind of dynamic (code-based) data binding, which I'm not sure is even possible? Anyway, it would be too complicated. Another possibility may be using SQL data connector, which I believe is much more dynamic, but I'm not using SQL data connectors, so maybe someone else can help here (krstcs)?

I personally would solve this kind of problem by merging multiple validation values into one data connector, using some kind of pseudo-array. Then instead of directly validating a data connector binded with variable, I would read the data connector value, split it into individual array values and then validate the actual value against individual array values.

Here is a pseudocode:

Code: Select all

//varExpectedResultArray - a module variable binded to data connector called varExpectedResultArray, containing array of values separated by semicolon
//varActualResult - variable containing actual value obtained from element (by GetValue)

string[] varExpectedResultArrayValues = varExpectedResultArray.Split(';');
        foreach (string varExpectedResultArrayValue in varExpectedResultArrayValues)
        {
            if (varActualResult == varExpectedResultArrayValue)
                {
                    Report.Success("validation success");
                    break; // exit loop
                }
        }
hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

cpalex
Posts: 5
Joined: Sat Feb 17, 2018 12:37 am

Re: Variable number of validations

Post by cpalex » Fri Mar 09, 2018 6:00 pm

Taking your advice, it was pretty easy to switch the repository item to a constant, as each identifiable item started with 1), 2) etc.

Getting the data into an array for a comparison may be a little more complicated, and I may have to involve one of my programmers, but let's start with a little better example. I don't want to post my entire snapshot online, so I will start with a screenshot, I can post more details on an item if requested.
ictree.png
ictree.png (39.5 KiB) Viewed 221 times
And here is a screenshot of the actual Application window I'm testing:
ictab.png
ictab.png (37.52 KiB) Viewed 221 times
The element that I am really trying to test is the Interchange column numbers. How many times they appear in the list, and the different descriptions, are less important to me than whether or not the Interchange number is actually presented (or not presented) as an option.

Is there a way to search the entire TreeItem 'TRA" and all of its children for the existence of a particular number?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Variable number of validations

Post by odklizec » Mon Mar 12, 2018 9:59 am

Hi,

Unfortunately, without seeing, at very least, Ranorex snapshot of the tree, it's hard to suggest something reliable. Generally speaking, if the values of Interchange column are traceable with Ranorex Spy, then it should be possible to get the list of all Interchange values and eventually compare them with expected (reference) values. I would personally obtain the list of Interchange values and then search the expected (reference) values in the list via loop.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration