How to verify list items in a table is alphabetical

Best practices, code snippets for common functionality, examples, and guidelines.
jmchughsmart
Posts: 28
Joined: Wed Aug 12, 2015 6:44 pm

How to verify list items in a table is alphabetical

Post by jmchughsmart » Wed Sep 21, 2016 6:49 pm

Hi
I have a table
/form[@title='Available']/container[@accessiblename='Available']//container[@name='viewport']/table[@name='myTable']

This table contains 50 rows.

How to verify row items in a table is alphabetical.

Thanks in advance.

User avatar
N612
Posts: 135
Joined: Mon Jul 11, 2016 4:01 pm

Re: How to verify list items in a table is alphabetical

Post by N612 » Wed Sep 21, 2016 8:36 pm

Ranorex does not have a way built in to automatically validate a list is alphabetical. You will need to use the .Net framework to assist you with this. This will take some coding knowledge to achieve but is certainly achievable.

Below is how I would do it. There may be a easier way to do this, but hopefully this will point you in the right direction or give you ideas on doing it your own way.

1. Make a repository item that grabs all the rows/cells you want to ensure are alphabetical

Code: Select all

//dom/table/tbody/tr
2. Convert them into a list object (You will need to access the repository item's info object by adding 'Info' to the end of the object (see 2nd line in code below)).

Code: Select all

var repo = AlphabetizeListRepository.Instance;
var rows = repo.dom.rowsInfo;
IList<TrTag> tableRows = rows.CreateAdapters<TrTag>();
foreach (TrTag row in tableRows)
     my2ndList.Add(row);
3. Add each to a 2nd list object (last 2 lines in code above)
4. Sort one of the list alphabetically (multiple ways, such as LINQ)
5. Compare list (multiple ways, such as LINQ)
6. Report on the result of the comparison

jmchughsmart
Posts: 28
Joined: Wed Aug 12, 2015 6:44 pm

Re: How to verify list items in a table is alphabetical

Post by jmchughsmart » Fri Sep 23, 2016 5:40 pm

This worked for me

Report.Log(ReportLevel.Info, "Order Test", "START");
varCount = repo.Available.ContainerAvailable.MyTable.Rows.Count;

for (int i = 0; i < varCount; i++)
{
varCurrentValue = repo.Available.ContainerAvailable.MyTable.Rows.Cells[1].ToString();
if (varPreviousValue == null)
{
varPreviousValue = varCurrentValue;
continue;
}

if(varPreviousValue.CompareTo(varCurrentValue) > 0)
{
Delay.Seconds(1);
Report.Log(ReportLevel.Info, "Order: " + i + 1, varPreviousValue + " is before " + varCurrentValue);
}
varPreviousValue = varCurrentValue;
}
Report.Log(ReportLevel.Info, "Order Test", "END");