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.
How to verify list items in a table is alphabetical
-
- Posts: 28
- Joined: Wed Aug 12, 2015 6:44 pm
Re: How to verify list items in a table is alphabetical
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
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)).
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
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
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);
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
-
- Posts: 28
- Joined: Wed Aug 12, 2015 6:44 pm
Re: How to verify list items in a table is alphabetical
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");
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");