Sorting of Data

Hi guyz,

Is it possible to check the sorting of data using katalon studio?? if yes, please help me…

I have a set of data in list view in **Mobile, **and after selecting a sorting option I want to check whether the data is getting sorted according to the selected option or not.

Please help me, if someone knows the answer…

Thanks!

Hello,

if you can share your source code of elements you want to compare, it’d be great. But let me show you a general approach for such a case.

// first of all, run your code for sorting UI data; at this time data must be sortedList<String> sortedData = Arrays.asList('Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo')WebDriver driver = DriverFactory.getWebDriver()List<WebElement> webElemData = driver.findElements(By.xpath("//div[@id='myData']/p"))List<String> textData = new ArrayList<>()for(WebElement we in webElemData) {	textData.add(we.getText())}if(sortedData.size() != textData.size()) {	KeywordUtil.markFailedAndStop("Expected number of elements do not match actual one.")}for(int i = 0; i < sortedData.size(); i++) {	if(sortedData.get(i) != textData.get(i)) {		KeywordUtil.markFailed("Expected element does not match actual element.")	} else {		KeywordUtil.logInfo("Success on index" + i)	}}

Now few words about a code. First of all, you should define an ordered list with expected results (sortedData). Now, time to get data from UI. This example is valid for WebDriver, for mobile it may be slightly different, I am not familiar with it. But generally, you should find all elements, which should match your expected data and put it into another list (textData).

When you have two lists, which should be the same, it is compare time. First of all, if they have different sizes, you can immediately say that something is wrong (first condition). If sizes are the same, loop through both lists and compare i-th element - if they are not the same, throw an error.

I hope it is more clear now.