How to check ascending and descending order with pagination?
package Admin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
import BaseInit.BaseInit;
import MyMethods.MyLoginMethods;
public class Sorting extends BaseInit {
@Test
public static void sortingtest() throws InterruptedException {
// Login to Admin Panel
MyLoginMethods.AdminLogin(datap.getProperty("email"), datap.getProperty("Pass"));
driver.get(sitedata.getProperty("confiProURL"));
Thread.sleep(2000);
ArrayList<String> ActualList = new ArrayList<String>();
ArrayList<String> sortedList = new ArrayList<String>();
String[] pageItem = epresent("pageItem_className").getText().split(" ");
String TotalPage = pageItem[3].trim();
System.out.println("Items per Page is- " + TotalPage);
int PagePerItem = Integer.parseInt(TotalPage);
String page = epresent("pageSize_className").getText();
String[] split = page.split(" ");
String pageNo = split[4].trim();
System.out.println("Page num is- " + pageNo);
int tPage = Integer.parseInt(pageNo);
int TotalClick = (tPage / PagePerItem);
System.out.println(TotalClick);
int currentPage = 1;
for (int j = 0; j < TotalClick; j++) {
if (currentPage >= 10) {
epresent("NextPage_xpath").click();
Thread.sleep(2000);
}
WebElement headPath = epresent("table_tagName");
List<WebElement> rowPath = headPath.findElements(By.tagName("mat-row"));
for (int i = 0; i < rowPath.size(); i++) {
String rowdata = rowPath.get(i).findElement(By.className("cdk-column-product_name")).getText();
ActualList.add(rowdata);
}
System.out.println(ActualList);
Thread.sleep(2000);
if (j == 0) {
epresent("name_xpath").click();
Thread.sleep(2000);
}
WebElement headPath1 = epresent("table_tagName");
List<WebElement> rowPath1 = headPath1.findElements(By.tagName("mat-row"));
for (int i = 0; i < rowPath.size(); i++) {
String sortData = rowPath1.get(i).findElement(By.className("cdk-column-product_name")).getText();
sortedList.add(sortData);
currentPage++;
}
System.out.println(sortedList);
// Check sorting
Collections.sort(ActualList);
System.out.println("-------------------------------------------------");
Assert.assertTrue(sortedList.equals(ActualList));
ActualList.clear();
sortedList.clear();
}
}
}
Comments
Post a Comment